key.go 489 Bytes
Newer Older
1 2 3
package flatfs

import (
tavit ohanian's avatar
tavit ohanian committed
4
	"gitlab.dms3.io/dms3/public/go-datastore"
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
)

// keyIsValid returns true if the key is valid for flatfs.
// Allows keys that match [0-9A-Z+-_=].
func keyIsValid(key datastore.Key) bool {
	ks := key.String()
	if len(ks) < 2 || ks[0] != '/' {
		return false
	}
	for _, b := range ks[1:] {
		if '0' <= b && b <= '9' {
			continue
		}
		if 'A' <= b && b <= 'Z' {
			continue
		}
		switch b {
		case '+', '-', '_', '=':
			continue
		}
		return false
	}
	return true
}