Skip to content

Commit 2eff550

Browse files
committed
small tests from bcrypt_test added
1 parent df6e25a commit 2eff550

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

biicrypt/biicrypt_test.go

+27
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,30 @@ func TestBiiCryptReformatSecret(t *testing.T) {
5555
t.Fatalf("Expected password and password generated from new secret do not match")
5656
}
5757
}
58+
59+
func BenchmarkEqual(b *testing.B) {
60+
b.StopTimer()
61+
passwd := []byte("somepasswordyoulike")
62+
hash, secret, _ := GenerateFromPassword(passwd, DefaultCost)
63+
b.StartTimer()
64+
for i := 0; i < b.N; i++ {
65+
other_hash, _ := GenerateWithSecret(passwd, secret)
66+
subtle.ConstantTimeCompare(hash, other_hash)
67+
}
68+
}
69+
70+
func BenchmarkDefaultCost(b *testing.B) {
71+
b.StopTimer()
72+
passwd := []byte("mylongpassword1234")
73+
b.StartTimer()
74+
for i := 0; i < b.N; i++ {
75+
GenerateFromPassword(passwd, DefaultCost)
76+
}
77+
}
78+
79+
func TestPasswordTooLong(t *testing.T) {
80+
_, _, err := GenerateFromPassword(make([]byte, 73), 1)
81+
if err != ErrPasswordTooLong {
82+
t.Errorf("unexpected error: got %q, want %q", err, ErrPasswordTooLong)
83+
}
84+
}

0 commit comments

Comments
 (0)