2021-10-08 12:39:31 +00:00
|
|
|
// SPDX-FileCopyrightText: 2021 The NGI Pointer Secure-Scuttlebutt Team of 2020/2021
|
|
|
|
//
|
2021-03-12 13:11:22 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
package aliases
|
|
|
|
|
2021-03-16 07:39:59 +00:00
|
|
|
// IsValid decides whether an alias is okay for use or not.
|
2022-11-07 09:18:13 +00:00
|
|
|
// The room spec defines it as _labels valid under RFC 1035_ ( https://ssbc.github.io/rooms2/#alias-string )
|
2021-03-12 13:11:22 +00:00
|
|
|
// but that can be mostly any string since DNS is a 8bit binary protocol,
|
|
|
|
// as long as it's shorter then 63 charachters.
|
|
|
|
//
|
2021-04-22 14:32:33 +00:00
|
|
|
// Right now it's pretty basic set of characters (a-z, 0-9).
|
2021-03-12 13:11:22 +00:00
|
|
|
// In theory we could be more liberal but there is a bunch of stuff to figure out,
|
|
|
|
// like homograph attacks (https://en.wikipedia.org/wiki/IDN_homograph_attack),
|
|
|
|
// if we would decide to allow full utf8 unicode.
|
|
|
|
func IsValid(alias string) bool {
|
|
|
|
if len(alias) > 63 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
var valid = true
|
|
|
|
for _, char := range alias {
|
|
|
|
if char >= '0' && char <= '9' { // is an ASCII number
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if char >= 'a' && char <= 'z' { // is an ASCII char between a and z
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
valid = false
|
|
|
|
break
|
|
|
|
}
|
|
|
|
return valid
|
|
|
|
}
|