Skip to content

Commit

Permalink
small tests from bcrypt_test added
Browse files Browse the repository at this point in the history
  • Loading branch information
BiiChris committed Sep 15, 2023
1 parent df6e25a commit 2eff550
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions biicrypt/biicrypt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,30 @@ func TestBiiCryptReformatSecret(t *testing.T) {
t.Fatalf("Expected password and password generated from new secret do not match")
}
}

func BenchmarkEqual(b *testing.B) {
b.StopTimer()
passwd := []byte("somepasswordyoulike")
hash, secret, _ := GenerateFromPassword(passwd, DefaultCost)
b.StartTimer()
for i := 0; i < b.N; i++ {
other_hash, _ := GenerateWithSecret(passwd, secret)
subtle.ConstantTimeCompare(hash, other_hash)
}
}

func BenchmarkDefaultCost(b *testing.B) {
b.StopTimer()
passwd := []byte("mylongpassword1234")
b.StartTimer()
for i := 0; i < b.N; i++ {
GenerateFromPassword(passwd, DefaultCost)
}
}

func TestPasswordTooLong(t *testing.T) {
_, _, err := GenerateFromPassword(make([]byte, 73), 1)
if err != ErrPasswordTooLong {
t.Errorf("unexpected error: got %q, want %q", err, ErrPasswordTooLong)
}
}

0 comments on commit 2eff550

Please sign in to comment.