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
46366339
Unverified
Commit
46366339
authored
Mar 30, 2021
by
Marten Seemann
Committed by
GitHub
Mar 30, 2021
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #143 from marten-seemann/fix-linters
fix go vet and staticcheck failures
parents
d7d65e55
927b81c5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
32 deletions
+6
-32
codec.go
codec.go
+0
-26
transcoders.go
transcoders.go
+6
-6
No files found.
codec.go
View file @
46366339
...
...
@@ -176,29 +176,3 @@ func sizeForAddr(p Protocol, b []byte) (skip, size int, err error) {
return
n
,
size
,
nil
}
}
func
bytesSplit
(
b
[]
byte
)
([][]
byte
,
error
)
{
var
ret
[][]
byte
for
len
(
b
)
>
0
{
code
,
n
,
err
:=
ReadVarintCode
(
b
)
if
err
!=
nil
{
return
nil
,
err
}
p
:=
ProtocolWithCode
(
code
)
if
p
.
Code
==
0
{
return
nil
,
fmt
.
Errorf
(
"no protocol with code %d"
,
b
[
0
])
}
n2
,
size
,
err
:=
sizeForAddr
(
p
,
b
[
n
:
])
if
err
!=
nil
{
return
nil
,
err
}
length
:=
n
+
n2
+
size
ret
=
append
(
ret
,
b
[
:
length
])
b
=
b
[
length
:
]
}
return
ret
,
nil
}
transcoders.go
View file @
46366339
...
...
@@ -137,12 +137,12 @@ var TranscoderOnion = NewTranscoderFromFunctions(onionStB, onionBtS, nil)
func
onionStB
(
s
string
)
([]
byte
,
error
)
{
addr
:=
strings
.
Split
(
s
,
":"
)
if
len
(
addr
)
!=
2
{
return
nil
,
fmt
.
Errorf
(
"failed to parse onion addr: %s does not contain a port number
.
"
,
s
)
return
nil
,
fmt
.
Errorf
(
"failed to parse onion addr: %s does not contain a port number"
,
s
)
}
// onion address without the ".onion" substring
if
len
(
addr
[
0
])
!=
16
{
return
nil
,
fmt
.
Errorf
(
"failed to parse onion addr: %s not a Tor onion address
.
"
,
s
)
return
nil
,
fmt
.
Errorf
(
"failed to parse onion addr: %s not a Tor onion address"
,
s
)
}
onionHostBytes
,
err
:=
base32
.
StdEncoding
.
DecodeString
(
strings
.
ToUpper
(
addr
[
0
]))
if
err
!=
nil
{
...
...
@@ -180,7 +180,7 @@ var TranscoderOnion3 = NewTranscoderFromFunctions(onion3StB, onion3BtS, nil)
func
onion3StB
(
s
string
)
([]
byte
,
error
)
{
addr
:=
strings
.
Split
(
s
,
":"
)
if
len
(
addr
)
!=
2
{
return
nil
,
fmt
.
Errorf
(
"failed to parse onion addr: %s does not contain a port number
.
"
,
s
)
return
nil
,
fmt
.
Errorf
(
"failed to parse onion addr: %s does not contain a port number"
,
s
)
}
// onion address without the ".onion" substring
...
...
@@ -228,7 +228,7 @@ func garlic64StB(s string) ([]byte, error) {
// 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
))
return
nil
,
fmt
.
Errorf
(
"failed to parse garlic addr: %s not an i2p base64 address. len: %d"
,
s
,
len
(
s
))
}
garlicHostBytes
,
err
:=
garlicBase64Encoding
.
DecodeString
(
s
)
if
err
!=
nil
{
...
...
@@ -249,7 +249,7 @@ func garlic64BtS(b []byte) (string, error) {
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
))
return
fmt
.
Errorf
(
"failed to validate garlic addr: %s not an i2p base64 address. len: %d"
,
b
,
len
(
b
))
}
return
nil
}
...
...
@@ -286,7 +286,7 @@ func garlic32Validate(b []byte) error {
// an i2p base64 for an Encrypted Leaseset v2 will be at least 35 bytes
// 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
fmt
.
Errorf
(
"failed to validate garlic addr: %s not an i2p base32 address. len: %d"
,
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