Fix constantTimeCompare.
This commit is contained in:
+1
-1
@@ -35,7 +35,7 @@ var hashSemaphore = make(chan struct{}, runtime.GOMAXPROCS(-1))
|
||||
func constantTimeCompare(a, b string) bool {
|
||||
as := []byte(a)
|
||||
bs := make([]byte, len(as))
|
||||
copy(bs, a)
|
||||
copy(bs, b)
|
||||
equal := subtle.ConstantTimeCompare(as, bs) == 1
|
||||
return len(a) == len(b) && equal
|
||||
}
|
||||
|
||||
@@ -58,7 +58,10 @@ func TestGood(t *testing.T) {
|
||||
|
||||
func TestBad(t *testing.T) {
|
||||
if match, err := pw2.Match("bad"); err != nil || match {
|
||||
t.Errorf("pw2 matches")
|
||||
t.Errorf("pw2 matches bad")
|
||||
}
|
||||
if match, err := pw2.Match("bad1"); err != nil || match {
|
||||
t.Errorf("pw2 matches bad1")
|
||||
}
|
||||
if match, err := pw3.Match("bad"); err != nil || match {
|
||||
t.Errorf("pw3 matches")
|
||||
|
||||
Reference in New Issue
Block a user