Skip to content

Commit

Permalink
feat: Add test vectors to verify input params
Browse files Browse the repository at this point in the history
  • Loading branch information
lubux committed Nov 11, 2024
1 parent 40b5617 commit 98027f2
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions openpgp/s2k/s2k_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,49 @@ func testSerializeConfigOK(t *testing.T, c *Config) *Params {

return params
}

func TestValidateArgon2Params(t *testing.T) {
tests := []struct {
params Params
wantErr bool
}{
{
params: Params{parallelism: 4, passes: 3, memoryExp: 6},
wantErr: false,
},
{
params: Params{parallelism: 0, passes: 3, memoryExp: 6},
wantErr: true,
},
{
params: Params{parallelism: 4, passes: 0, memoryExp: 6},
wantErr: true,
},
{
params: Params{parallelism: 4, passes: 3, memoryExp: 4},
wantErr: true,
},
{
params: Params{parallelism: 4, passes: 3, memoryExp: 32},
wantErr: true,
},
{
params: Params{parallelism: 4, passes: 3, memoryExp: 5},
wantErr: false,
},
{
params: Params{parallelism: 4, passes: 3, memoryExp: 31},
wantErr: false,
},
}

for _, tt := range tests {
err := validateArgon2Params(&tt.params)
if tt.wantErr && err == nil {
t.Errorf("validateArgon2Params: expected an error")
}
if !tt.wantErr && err != nil {
t.Error("validateArgon2Params: expected no error")
}
}
}

0 comments on commit 98027f2

Please sign in to comment.