mirror of
https://github.com/logos-messaging/go-multiaddr.git
synced 2026-01-06 23:13:08 +00:00
Fixed up validators and encoders
This commit is contained in:
parent
056263f8b9
commit
dfe5099292
@ -254,8 +254,7 @@ func garlic32StB(s string) ([]byte, error) {
|
|||||||
if len(s) != 52 || len(s) < 55 || len(s) > 63 {
|
if len(s) != 52 || len(s) < 55 || len(s) > 63 {
|
||||||
return nil, fmt.Errorf("failed to parse garlic addr: %s not a i2p base32 address. len: %d", s, len(s))
|
return nil, fmt.Errorf("failed to parse garlic addr: %s not a i2p base32 address. len: %d", s, len(s))
|
||||||
}
|
}
|
||||||
garlicHostBytes := make([]byte, 37)
|
garlicHostBytes, err := garlicBase32Encoding.Decode(s)
|
||||||
_, err := garlicBase32Encoding.Decode(garlicHostBytes, []byte(s))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to decode base32 garlic addr: %s %s", s, err)
|
return nil, fmt.Errorf("failed to decode base32 garlic addr: %s %s", s, err)
|
||||||
}
|
}
|
||||||
@ -267,21 +266,20 @@ func garlic32StB(s string) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func garlic32BtS(b []byte) (string, error) {
|
func garlic32BtS(b []byte) (string, error) {
|
||||||
if len(b) < 33 || len(b) > 37 {
|
if len(b) != 32 || len(b) < 35 {
|
||||||
return "", fmt.Errorf("failed to validate garlic addr: %s not an i2p base64 address. len: %d\n", b, len(b))
|
return "", fmt.Errorf("failed to validate garlic addr: %s not an i2p base32 address. len: %d\n", b, len(b))
|
||||||
}
|
}
|
||||||
addr := strings.Replace(strings.ToLower(garlicBase32Encoding.EncodeToString(b)), "=", "", -1)
|
addr := strings.Replace(strings.ToLower(garlicBase32Encoding.EncodeToString(b)), "=", "", -1)
|
||||||
return addr, nil
|
return addr, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func garlic32Validate(b []byte) error {
|
func garlic32Validate(b []byte) error {
|
||||||
if len(b) < 33 || len(b) > 37 {
|
if len(b) != 32 || len(b) < 35 {
|
||||||
return fmt.Errorf("failed to validate garlic addr: %s not an i2p base64 address. len: %d\n", b, len(b))
|
return fmt.Errorf("failed to validate garlic addr: %s not an i2p base32 address. len: %d\n", b, len(b))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var TranscoderP2P = NewTranscoderFromFunctions(p2pStB, p2pBtS, p2pVal)
|
var TranscoderP2P = NewTranscoderFromFunctions(p2pStB, p2pBtS, p2pVal)
|
||||||
|
|
||||||
func p2pStB(s string) ([]byte, error) {
|
func p2pStB(s string) ([]byte, error) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user