Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
mf
go-multiaddr
Commits
84811f91
Commit
84811f91
authored
Apr 05, 2019
by
idk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
don't use a function to guarantee correct padding
parent
477514c8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
29 deletions
+12
-29
transcoders.go
transcoders.go
+12
-29
No files found.
transcoders.go
View file @
84811f91
...
...
@@ -252,30 +252,16 @@ var TranscoderGarlic32 = NewTranscoderFromFunctions(garlic32StB, garlic32BtS, ga
var
garlicBase32Encoding
=
base32
.
NewEncoding
(
"abcdefghijklmnopqrstuvwxyz234567"
)
func
garlic32StB
(
s
string
)
([]
byte
,
error
)
{
//s = strings.Replace(s, ".b32.i2p", "", -1)
// garlic address without the ".b32.i2p" substring
// an i2p base32 address with a length of greater than 55 characters is
// using an Encrypted Leaseset v2.
if
len
(
s
)
<
55
{
if
len
(
s
)
!=
52
{
// all other base32 addresses will always be exactly 52 characters
return
nil
,
fmt
.
Errorf
(
"failed to parse garlic addr: %s not a i2p base32 address. len: %d"
,
s
,
len
(
s
))
}
}
//compute the length to pad the address to, usually 56 or 64
padout
:=
func
(
s
string
)
string
{
if
len
(
s
)
%
8
==
0
{
return
s
}
x
:=
int
((
len
(
s
)
/
8
)
+
1
)
*
8
for
len
(
s
)
<
x
{
s
+=
"="
}
return
s
}
garlicHostBytes
,
err
:=
garlicBase32Encoding
.
DecodeString
(
padout
(
s
))
// using an Encrypted Leaseset v2. all other base32 addresses will always be
// exactly 52 characters
if
len
(
s
)
<
55
&&
len
(
s
)
!=
52
{
return
nil
,
fmt
.
Errorf
(
"failed to parse garlic addr: %s not a i2p base32 address. len: %d"
,
s
,
len
(
s
))
}
for
len
(
s
)
%
8
!=
0
{
s
+=
"="
}
garlicHostBytes
,
err
:=
garlicBase32Encoding
.
DecodeString
(
s
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to decode base32 garlic addr: %s, err: %v len: %v"
,
s
,
err
,
len
(
s
))
}
...
...
@@ -291,12 +277,9 @@ func garlic32BtS(b []byte) (string, error) {
func
garlic32Validate
(
b
[]
byte
)
error
{
// an i2p base64 for an Encrypted Leaseset v2 will be at least 35 bytes
// long
if
len
(
b
)
<
35
{
// other than that, they will be exactly 32 bytes
if
len
(
b
)
!=
32
{
return
fmt
.
Errorf
(
"failed to validate garlic addr: %s not an i2p base32 address. len: %d
\n
"
,
b
,
len
(
b
))
}
// long other than that, they will be exactly 32 bytes
if
len
(
b
)
<
35
&&
len
(
b
)
!=
32
{
return
fmt
.
Errorf
(
"failed to validate garlic addr: %s not an i2p base32 address. len: %d
\n
"
,
b
,
len
(
b
))
}
return
nil
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment