Skip to content

Commit 477514c

Browse files
author
idk
committed
Add comments to garlic64 addresses and use the validator
1 parent ebd6de6 commit 477514c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

transcoders.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ var TranscoderGarlic64 = NewTranscoderFromFunctions(garlic64StB, garlic64BtS, ga
218218
var garlicBase64Encoding = base64.NewEncoding("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-~")
219219

220220
func garlic64StB(s string) ([]byte, error) {
221-
// i2p base64 address
221+
// i2p base64 address will be between 516 and 616 characters long, depending on
222+
// certificate type
222223
if len(s) < 516 || len(s) > 616 {
223224
return nil, fmt.Errorf("failed to parse garlic addr: %s not an i2p base64 address. len: %d\n", s, len(s))
224225
}
@@ -231,14 +232,15 @@ func garlic64StB(s string) ([]byte, error) {
231232
}
232233

233234
func garlic64BtS(b []byte) (string, error) {
234-
if len(b) < 386 {
235-
return "", fmt.Errorf("failed to validate garlic addr: %s not an i2p base64 address. len: %d\n", b, len(b))
235+
if err := garlic64Validate(b); err != nil {
236+
return "", err
236237
}
237238
addr := garlicBase64Encoding.EncodeToString(b)
238239
return addr, nil
239240
}
240241

241242
func garlic64Validate(b []byte) error {
243+
// A garlic64 address will always be greater than 386 bytes long when encoded.
242244
if len(b) < 386 {
243245
return fmt.Errorf("failed to validate garlic addr: %s not an i2p base64 address. len: %d\n", b, len(b))
244246
}

0 commit comments

Comments
 (0)