Polish code

This commit is contained in:
AlexSSD7 2023-08-29 14:24:18 +01:00
commit 0870f8113a
10 changed files with 246 additions and 238 deletions

View file

@ -21,7 +21,7 @@ func ClearUnprintableChars(s string, allowNewlines bool) string {
}, s)
}
var devNameRegexp = regexp.MustCompile("^[0-9a-z_-]+$")
var devNameRegexp = regexp.MustCompile(`^[0-9a-z_-]+$`)
func ValidateDevName(s string) bool {
// Allow mapped devices.
@ -30,6 +30,12 @@ func ValidateDevName(s string) bool {
return devNameRegexp.MatchString(s)
}
var unixUsernameRegexp = regexp.MustCompile(`^[a-z_]([a-z0-9_-]{0,31}|[a-z0-9_-]{0,30}\$)$`)
func ValidateUnixUsername(s string) bool {
return unixUsernameRegexp.MatchString(s)
}
func Uint16ToBytesBE(v uint16) []byte {
b := make([]byte, 2)
binary.BigEndian.PutUint16(b, v)