mirror of
https://github.com/go-i2p/i2pkeys.git
synced 2025-06-16 12:05:33 -04:00
fix validateAddressFormat
This commit is contained in:
@ -3,6 +3,7 @@ package i2pkeys
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -61,6 +62,10 @@ func sanitizeAddress(addr string) string {
|
||||
|
||||
func validateAddressFormat(addr string) error {
|
||||
host, _, err := net.SplitHostPort(addr)
|
||||
if err != nil {
|
||||
// If SplitHostPort fails, it means addr is not in host:port format
|
||||
host = addr
|
||||
}
|
||||
if host != "" {
|
||||
addr = host
|
||||
}
|
||||
@ -68,11 +73,9 @@ func validateAddressFormat(addr string) error {
|
||||
return fmt.Errorf("invalid address length: got %d, want between %d and %d",
|
||||
len(addr), MinAddressLength, MaxAddressLength)
|
||||
}
|
||||
|
||||
if strings.HasSuffix(addr, B32Suffix) {
|
||||
return fmt.Errorf("cannot convert %s to full destination", B32Suffix)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user