Compare commits
3 Commits
25ef151100
...
faf6b8e93e
Author | SHA1 | Date | |
---|---|---|---|
![]() |
faf6b8e93e | ||
![]() |
d844519847 | ||
![]() |
d166f5c31e |
11
I2PAddr.go
11
I2PAddr.go
@@ -3,6 +3,7 @@ package i2pkeys
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -60,15 +61,21 @@ 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
|
||||
}
|
||||
if len(addr) > MaxAddressLength || len(addr) < MinAddressLength {
|
||||
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