feat(app) lab 3 implemented

This commit is contained in:
imadev
2026-10-30 18:11:30 +03:00
parent f731f9b460
commit 48a616e910
57 changed files with 1390 additions and 303 deletions
+18
View File
@@ -44,3 +44,21 @@ func TestPasswordHashIsSalted(t *testing.T) {
t.Fatal("invalid encoded hash was accepted")
}
}
func TestVerifyPasswordRejectsMalformedCostAndEmptyDigest(t *testing.T) {
malformed := []string{
// Empty digest would make argon2 derive a zero-length key.
"$argon2id$v=19$m=65536,t=2,p=4$c2FsdA$",
// Zero cost parameters are outside argon2's supported range and would
// otherwise panic inside the KDF.
"$argon2id$v=19$m=65536,t=0,p=4$c2FsdA$YWJjZA",
"$argon2id$v=19$m=65536,t=2,p=0$c2FsdA$YWJjZA",
"$argon2id$v=19$m=1,t=2,p=4$c2FsdA$YWJjZA",
}
for _, encoded := range malformed {
ok, err := VerifyPassword(encoded, "same-password-123")
if err == nil || ok {
t.Fatalf("VerifyPassword(%q) = (%v, %v), want ErrInvalidHash", encoded, ok, err)
}
}
}