@@ -252,30 +252,16 @@ var TranscoderGarlic32 = NewTranscoderFromFunctions(garlic32StB, garlic32BtS, ga
252
252
var garlicBase32Encoding = base32 .NewEncoding ("abcdefghijklmnopqrstuvwxyz234567" )
253
253
254
254
func garlic32StB (s string ) ([]byte , error ) {
255
- //s = strings.Replace(s, ".b32.i2p", "", -1)
256
- // garlic address without the ".b32.i2p" substring
257
-
258
255
// an i2p base32 address with a length of greater than 55 characters is
259
- // using an Encrypted Leaseset v2.
260
- if len (s ) < 55 {
261
- if len (s ) != 52 {
262
- // all other base32 addresses will always be exactly 52 characters
263
- return nil , fmt .Errorf ("failed to parse garlic addr: %s not a i2p base32 address. len: %d" , s , len (s ))
264
- }
265
- }
266
- //compute the length to pad the address to, usually 56 or 64
267
- padout := func (s string ) string {
268
- if len (s )% 8 == 0 {
269
- return s
270
- }
271
- x := int ((len (s )/ 8 )+ 1 ) * 8
272
- for len (s ) < x {
273
- s += "="
274
- }
275
- return s
276
- }
277
-
278
- garlicHostBytes , err := garlicBase32Encoding .DecodeString (padout (s ))
256
+ // using an Encrypted Leaseset v2. all other base32 addresses will always be
257
+ // exactly 52 characters
258
+ if len (s ) < 55 && len (s ) != 52 {
259
+ return nil , fmt .Errorf ("failed to parse garlic addr: %s not a i2p base32 address. len: %d" , s , len (s ))
260
+ }
261
+ for len (s )% 8 != 0 {
262
+ s += "="
263
+ }
264
+ garlicHostBytes , err := garlicBase32Encoding .DecodeString (s )
279
265
if err != nil {
280
266
return nil , fmt .Errorf ("failed to decode base32 garlic addr: %s, err: %v len: %v" , s , err , len (s ))
281
267
}
@@ -291,12 +277,9 @@ func garlic32BtS(b []byte) (string, error) {
291
277
292
278
func garlic32Validate (b []byte ) error {
293
279
// an i2p base64 for an Encrypted Leaseset v2 will be at least 35 bytes
294
- // long
295
- if len (b ) < 35 {
296
- // other than that, they will be exactly 32 bytes
297
- if len (b ) != 32 {
298
- return fmt .Errorf ("failed to validate garlic addr: %s not an i2p base32 address. len: %d\n " , b , len (b ))
299
- }
280
+ // long other than that, they will be exactly 32 bytes
281
+ if len (b ) < 35 && len (b ) != 32 {
282
+ return fmt .Errorf ("failed to validate garlic addr: %s not an i2p base32 address. len: %d\n " , b , len (b ))
300
283
}
301
284
return nil
302
285
}
0 commit comments