-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbcrypt.go
More file actions
36 lines (30 loc) · 742 Bytes
/
Copy pathbcrypt.go
File metadata and controls
36 lines (30 loc) · 742 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package gomml
import (
"fmt"
"github.com/golang/mock/gomock"
"golang.org/x/crypto/bcrypt"
)
type bcryptMatcher struct {
password []byte
}
// BCrypt is a Matcher that matches if the hashed parameter to the mock
// function is equivalent to the password.
//
// Example usage:
//
// dbMock.EXPECT().
// Insert(gomml.BCrypt("password").
// Return(errors.New("DB error"))
//
func BCrypt(password []byte) gomock.Matcher {
return &bcryptMatcher{password}
}
func (m *bcryptMatcher) Matches(x interface{}) bool {
if hpw, ok := x.([]byte); ok {
return bcrypt.CompareHashAndPassword(hpw, m.password) == nil
}
return false
}
func (m *bcryptMatcher) String() string {
return fmt.Sprintf("matches to %s with bcrypt", m.password)
}