Browse Source

add tor.IsValidHostname

master
Dan Ballard 1 month ago
parent
commit
beb2665c49
1 changed files with 14 additions and 0 deletions
  1. +14
    -0
      tor/torUtils.go

+ 14
- 0
tor/torUtils.go View File

@@ -35,3 +35,17 @@ func GetTorV3Hostname(pub ed25519.PublicKey) string {
serviceID := base32.StdEncoding.EncodeToString(combined)
return strings.ToLower(serviceID)
}

// IsValidHostname returns true if the given address is a valid onion v3 address
func IsValidHostname(address string) bool {
if len(address) == V3HostnameLength {
data, err := base32.StdEncoding.DecodeString(strings.ToUpper(address))
if err == nil {
pubkey := data[0:ed25519.PublicKeySize]
if GetTorV3Hostname(ed25519.PublicKey(pubkey)) == address {
return true
}
}
}
return false
}

Loading…
Cancel
Save