Fix constantTimeCompare.

This commit is contained in:
Juliusz Chroboczek
2025-01-21 23:40:49 +01:00
parent df71f66fdf
commit aebe91ddac
2 changed files with 5 additions and 2 deletions
+1 -1
View File
@@ -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
}
+4 -1
View File
@@ -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")