Skip to content

Commit ae5c4f8

Browse files
author
idk
committed
fix how the padding is computed
1 parent 946a6f6 commit ae5c4f8

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

transcoders.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -261,18 +261,14 @@ func garlic32StB(s string) ([]byte, error) {
261261
return nil, fmt.Errorf("failed to parse garlic addr: %s not a i2p base32 address. len: %d", s, len(s))
262262
}
263263
}
264-
265-
for len(s) < 56 {
264+
//compute the length to pad the address to, usually 56 or 64
265+
x := int((len(s)/8)+1) * 8
266+
for len(s) < x {
266267
s += "="
267268
}
268-
269-
garlicHostBytes, err := garlicBase32Encoding.DecodeString(s)
269+
garlicHostBytes, err := garlicBase32Encoding.DecodeString(s[0:56])
270270
if err != nil {
271-
return nil, fmt.Errorf("failed to decode base32 garlic addr: %s, err: %v len: %v",
272-
s,
273-
err,
274-
len(s),
275-
)
271+
return nil, fmt.Errorf("failed to decode base32 garlic addr: %s, err: %v len: %v", s, err, len(s))
276272
}
277273
return garlicHostBytes, nil
278274
}

0 commit comments

Comments
 (0)