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