Skip to content

Commit ebd6de6

Browse files
author
idk
committed
fix the padding
1 parent 4283992 commit ebd6de6

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

transcoders.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,18 @@ func garlic32StB(s string) ([]byte, error) {
262262
}
263263
}
264264
//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 {
267-
s += "="
265+
padout := func(s string) string {
266+
if len(s)%8 == 0 {
267+
return s
268+
}
269+
x := int((len(s)/8)+1) * 8
270+
for len(s) < x {
271+
s += "="
272+
}
273+
return s
268274
}
269-
garlicHostBytes, err := garlicBase32Encoding.DecodeString(s[0:56])
275+
276+
garlicHostBytes, err := garlicBase32Encoding.DecodeString(padout(s))
270277
if err != nil {
271278
return nil, fmt.Errorf("failed to decode base32 garlic addr: %s, err: %v len: %v", s, err, len(s))
272279
}

0 commit comments

Comments
 (0)