Skip to content
This repository was archived by the owner on Aug 19, 2022. It is now read-only.

Commit 2b58ab5

Browse files
use bytes.Compare instead of reimplementing it
1 parent fbb6727 commit 2b58ab5

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

crypto.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package libp2ptls
22

33
import (
4+
"bytes"
45
"crypto/ecdsa"
56
"crypto/elliptic"
67
"crypto/rand"
@@ -227,13 +228,5 @@ func preferServerCipherSuites() bool {
227228
func comparePeerIDs(p1, p2 peer.ID) int {
228229
p1Hash := sha256.Sum256([]byte(p1))
229230
p2Hash := sha256.Sum256([]byte(p2))
230-
for i := 0; i < sha256.Size; i++ {
231-
if p1Hash[i] < p2Hash[i] {
232-
return -1
233-
}
234-
if p1Hash[i] > p2Hash[i] {
235-
return 1
236-
}
237-
}
238-
return 0
231+
return bytes.Compare(p1Hash[:], p2Hash[:])
239232
}

0 commit comments

Comments
 (0)