Export group.ConstantTimeCompare.

This commit is contained in:
Juliusz Chroboczek
2026-04-30 00:18:16 +02:00
parent 4683c3c126
commit ab44a661cb
2 changed files with 4 additions and 4 deletions
+3 -3
View File
@@ -31,8 +31,8 @@ type Password RawPassword
// out of memory when doing too many BCrypt hashes at the same time. // out of memory when doing too many BCrypt hashes at the same time.
var hashSemaphore = make(chan struct{}, runtime.GOMAXPROCS(-1)) var hashSemaphore = make(chan struct{}, runtime.GOMAXPROCS(-1))
// constantTimeCompare compares a and b in time proportional to the length of a. // ConstantTimeCompare compares a and b in time proportional to the length of a.
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, b) copy(bs, b)
@@ -48,7 +48,7 @@ func (p Password) Match(pw string) (bool, error) {
if p.Key == nil { if p.Key == nil {
return false, errors.New("missing key") return false, errors.New("missing key")
} }
return constantTimeCompare(pw, *p.Key), nil return ConstantTimeCompare(pw, *p.Key), nil
case "wildcard": case "wildcard":
return true, nil return true, nil
case "pbkdf2": case "pbkdf2":
+1 -1
View File
@@ -25,7 +25,7 @@ func TestConstantTimeCompare(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
e := constantTimeCompare(test.a, test.b) e := ConstantTimeCompare(test.a, test.b)
if e != (test.a == test.b) { if e != (test.a == test.b) {
t.Errorf("constantTimeCompare(%v, %v): got %v", t.Errorf("constantTimeCompare(%v, %v): got %v",
test.a, test.b, e, test.a, test.b, e,