-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add WebTransport multiaddr components #176
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -11,6 +11,7 @@ import ( | |||
"strings" | ||||
|
||||
"github.com/ipfs/go-cid" | ||||
"github.com/multiformats/go-multibase" | ||||
mh "github.com/multiformats/go-multihash" | ||||
) | ||||
|
||||
|
@@ -373,3 +374,20 @@ func dnsStB(s string) ([]byte, error) { | |||
func dnsBtS(b []byte) (string, error) { | ||||
return string(b), nil | ||||
} | ||||
|
||||
var TranscoderCertHash = NewTranscoderFromFunctions(certHashStB, certHashBtS, nil) | ||||
|
||||
func certHashStB(s string) ([]byte, error) { | ||||
_, data, err := multibase.Decode(s) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there any other requirements here? e.g. is it a multihash, is it just 32 bytes, etc. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are. First of all, it needs to be a multihash. Do you want to check that here, just to make sure we're not encoding garbage? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't live in this repo much, I was mostly copying from what we do with the p2p multiaddr Line 314 in f5adc3b
This seems to indicate that if adding some basic checking is relatively cheap then we might as well put it here. If web transport isn't specifically 32 bytes (plus the extra couple multihash bytes) then leaving that part defined in the transport seems reasonable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added the validation on encoding. |
||||
if err != nil { | ||||
return nil, err | ||||
} | ||||
if _, err := mh.Decode(data); err != nil { | ||||
return nil, err | ||||
} | ||||
return data, nil | ||||
} | ||||
|
||||
func certHashBtS(b []byte) (string, error) { | ||||
return multibase.Encode(multibase.Base64url, b) | ||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you claim the code on https://github.com/multiformats/multiaddr/blob/master/protocols.csv?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
multiformats/multiaddr#130