Fix constantTimeCompare.
This commit is contained in:
1 parent
df71f66fdf
commit
aebe91ddac
2 files changed
+5
-2
No files matched your search
+1
-1
@@ -35,7 +35,7 @@ var hashSemaphore = make(chan struct{}, runtime.GOMAXPROCS(-1))
|
|||||||
func constantTimeCompare(a, b string) bool {
|
func constantTimeCompare(a, b string) bool {
|
||||||
as := []byte(a)
|
as := []byte(a)
|
||||||
bs := make([]byte, len(as))
|
bs := make([]byte, len(as))
|
||||||
copy(bs, a)
|
copy(bs, b)
|
||||||
equal := subtle.ConstantTimeCompare(as, bs) == 1
|
equal := subtle.ConstantTimeCompare(as, bs) == 1
|
||||||
return len(a) == len(b) && equal
|
return len(a) == len(b) && equal
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,10 @@ func TestGood(t *testing.T) {
|
|||||||
|
|
||||||
func TestBad(t *testing.T) {
|
func TestBad(t *testing.T) {
|
||||||
if match, err := pw2.Match("bad"); err != nil || match {
|
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 {
|
if match, err := pw3.Match("bad"); err != nil || match {
|
||||||
t.Errorf("pw3 matches")
|
t.Errorf("pw3 matches")
|
||||||
|
|||||||
Reference in new issue
Block a user