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
477514c8
Commit
477514c8
authored
Apr 05, 2019
by
idk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add comments to garlic64 addresses and use the validator
parent
ebd6de6a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
3 deletions
+5
-3
transcoders.go
transcoders.go
+5
-3
No files found.
transcoders.go
View file @
477514c8
...
...
@@ -218,7 +218,8 @@ var TranscoderGarlic64 = NewTranscoderFromFunctions(garlic64StB, garlic64BtS, ga
var
garlicBase64Encoding
=
base64
.
NewEncoding
(
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-~"
)
func
garlic64StB
(
s
string
)
([]
byte
,
error
)
{
// i2p base64 address
// i2p base64 address will be between 516 and 616 characters long, depending on
// certificate type
if
len
(
s
)
<
516
||
len
(
s
)
>
616
{
return
nil
,
fmt
.
Errorf
(
"failed to parse garlic addr: %s not an i2p base64 address. len: %d
\n
"
,
s
,
len
(
s
))
}
...
...
@@ -231,14 +232,15 @@ func garlic64StB(s string) ([]byte, error) {
}
func
garlic64BtS
(
b
[]
byte
)
(
string
,
error
)
{
if
len
(
b
)
<
386
{
return
""
,
fmt
.
Errorf
(
"failed to validate garlic addr: %s not an i2p base64 address. len: %d
\n
"
,
b
,
len
(
b
))
if
err
:=
garlic64Validate
(
b
);
err
!=
nil
{
return
""
,
err
}
addr
:=
garlicBase64Encoding
.
EncodeToString
(
b
)
return
addr
,
nil
}
func
garlic64Validate
(
b
[]
byte
)
error
{
// A garlic64 address will always be greater than 386 bytes long when encoded.
if
len
(
b
)
<
386
{
return
fmt
.
Errorf
(
"failed to validate garlic addr: %s not an i2p base64 address. len: %d
\n
"
,
b
,
len
(
b
))
}
...
...
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