Export group.ConstantTimeCompare.
This commit is contained in:
+3
-3
@@ -31,8 +31,8 @@ type Password RawPassword
|
||||
// out of memory when doing too many BCrypt hashes at the same time.
|
||||
var hashSemaphore = make(chan struct{}, runtime.GOMAXPROCS(-1))
|
||||
|
||||
// constantTimeCompare compares a and b in time proportional to the length of a.
|
||||
func constantTimeCompare(a, b string) bool {
|
||||
// ConstantTimeCompare compares a and b in time proportional to the length of a.
|
||||
func ConstantTimeCompare(a, b string) bool {
|
||||
as := []byte(a)
|
||||
bs := make([]byte, len(as))
|
||||
copy(bs, b)
|
||||
@@ -48,7 +48,7 @@ func (p Password) Match(pw string) (bool, error) {
|
||||
if p.Key == nil {
|
||||
return false, errors.New("missing key")
|
||||
}
|
||||
return constantTimeCompare(pw, *p.Key), nil
|
||||
return ConstantTimeCompare(pw, *p.Key), nil
|
||||
case "wildcard":
|
||||
return true, nil
|
||||
case "pbkdf2":
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ func TestConstantTimeCompare(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
e := constantTimeCompare(test.a, test.b)
|
||||
e := ConstantTimeCompare(test.a, test.b)
|
||||
if e != (test.a == test.b) {
|
||||
t.Errorf("constantTimeCompare(%v, %v): got %v",
|
||||
test.a, test.b, e,
|
||||
|
||||
Reference in New Issue
Block a user