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.
|
// 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
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user