mirror of
https://github.com/juanfont/headscale.git
synced 2025-11-02 22:17:44 +09:00
Ensure we always have the key prefix when needed
This commit is contained in:
24
utils.go
24
utils.go
@@ -60,6 +60,30 @@ func DiscoPublicKeyStripPrefix(discoKey key.DiscoPublic) string {
|
||||
return strings.TrimPrefix(discoKey.String(), discoPublicHexPrefix)
|
||||
}
|
||||
|
||||
func MachinePublicKeyEnsurePrefix(machineKey string) string {
|
||||
if !strings.HasPrefix(machineKey, machinePublicHexPrefix) {
|
||||
return machinePublicHexPrefix + machineKey
|
||||
}
|
||||
|
||||
return machineKey
|
||||
}
|
||||
|
||||
func NodePublicKeyEnsurePrefix(nodeKey string) string {
|
||||
if !strings.HasPrefix(nodeKey, nodePublicHexPrefix) {
|
||||
return nodePublicHexPrefix + nodeKey
|
||||
}
|
||||
|
||||
return nodeKey
|
||||
}
|
||||
|
||||
func DiscoPublicKeyEnsurePrefix(discoKey string) string {
|
||||
if !strings.HasPrefix(discoKey, discoPublicHexPrefix) {
|
||||
return discoPublicHexPrefix + discoKey
|
||||
}
|
||||
|
||||
return discoKey
|
||||
}
|
||||
|
||||
// Error is used to compare errors as per https://dave.cheney.net/2016/04/07/constant-errors
|
||||
type Error string
|
||||
|
||||
|
||||
Reference in New Issue
Block a user