fix: improve error handling in DeriveKey function to return errors for empty secret and zero length key requests

This commit is contained in:
2025-12-30 01:27:30 -06:00
parent f96af89269
commit 5c19b76367
2 changed files with 44 additions and 16 deletions

View File

@@ -77,8 +77,8 @@ func TestDeriveKeyEdgeCases(t *testing.T) {
t.Run("EmptySecret", func(t *testing.T) {
_, err := DeriveKey([]byte{}, salt, info, 32)
if err != nil {
t.Errorf("DeriveKey failed with empty secret: %v", err)
if err == nil {
t.Errorf("DeriveKey should fail with empty secret")
}
})
@@ -97,12 +97,9 @@ func TestDeriveKeyEdgeCases(t *testing.T) {
})
t.Run("ZeroLength", func(t *testing.T) {
key, err := DeriveKey(secret, salt, info, 0)
if err != nil {
t.Errorf("DeriveKey failed with zero length: %v", err)
}
if len(key) != 0 {
t.Errorf("DeriveKey with zero length returned non-empty key: %x", key)
_, err := DeriveKey(secret, salt, info, 0)
if err == nil {
t.Errorf("DeriveKey should fail with zero length")
}
})
}