Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit 08efac8

Browse files
committed
Handle error when calculating SHA peer id
1 parent 29bbd0f commit 08efac8

File tree

1 file changed

+21
-7
lines changed
  • vendor/gx/ipfs/QmYVXrKrKHDC9FobgmcmshCDyWwdrfwfanNQN4oxJ9Fk3h/go-libp2p-peer

1 file changed

+21
-7
lines changed

vendor/gx/ipfs/QmYVXrKrKHDC9FobgmcmshCDyWwdrfwfanNQN4oxJ9Fk3h/go-libp2p-peer/peer.go

+21-7
Original file line numberDiff line numberDiff line change
@@ -165,37 +165,51 @@ func IDFromPublicKey(pk ic.PubKey) (ID, error) {
165165
if AdvancedEnableInlining && len(b) <= maxInlineKeyLength {
166166
alg = mh.ID
167167
}
168-
hash, _ := mh.Sum(b, alg, -1)
168+
// OpenBazaar: handle the Sum error
169+
hash, err := mh.Sum(b, alg, -1)
170+
if err != nil {
171+
return "", err
172+
}
169173
return ID(hash), nil
170174
}
171175

172176
// HashedIDFromPublicKey will always return the SHA256 hash of
173-
// the pubkey bytes. OpenBazaar: temporary helper to isolate the
177+
// the pubkey bytes.
178+
// OpenBazaar: temporary helper to isolate the
174179
// hash-producing ID behavior.
175180
func HashedIDFromPublicKey(pk ic.PubKey) (ID, error) {
176181
b, err := pk.Bytes()
177182
if err != nil {
178183
return "", err
179184
}
180-
hash, _ := mh.Sum(b, mh.SHA2_256, -1)
185+
hash, err := mh.Sum(b, mh.SHA2_256, -1)
186+
if err != nil {
187+
return "", err
188+
}
181189
return ID(hash), nil
182190
}
183191

184192
// InlineIDFromPublicKey will always return the new inline ID format
185-
// of the pubkey bytes. OpenBazaar: temporary helper function to
193+
// of the pubkey bytes.
194+
// OpenBazaar: temporary helper function to
186195
// remain forward compatible with inline keys
187196
func InlineIDFromPublicKey(pk ic.PubKey) (ID, error) {
188197
b, err := pk.Bytes()
189198
if err != nil {
190199
return "", err
191200
}
192-
hash, _ := mh.Sum(b, mh.ID, -1)
201+
hash, err := mh.Sum(b, mh.SHA2_256, -1)
202+
if err != nil {
203+
return "", err
204+
}
193205
return ID(hash), nil
194206
}
195207

196208
// AlternativeIDFromPublicKey returns SHA256 hash ID when AdvancedEnableInlining
197-
// is true, and returns new InlineID otherwise. This allows legacy IDs to be compared
198-
// after they are no longer available by the default IDFromPublicKey function.
209+
// is true, and returns new InlineID otherwise.
210+
// OpenBazaar: This allows legacy IDs
211+
// to be compared after they are no longer available by the default IDFromPublicKey
212+
// function.
199213
func AlternativeIDFromPublicKey(pubkey ic.PubKey) (ID, error) {
200214
if AdvancedEnableInlining {
201215
return HashedIDFromPublicKey(pubkey)

0 commit comments

Comments
 (0)