Skip to content

Commit

Permalink
Make all unsupported algorithms return a more informative error
Browse files Browse the repository at this point in the history
Signed-off-by: hslatman <herman+github@smallstep.com>
  • Loading branch information
hslatman committed Aug 8, 2023
1 parent 754dc9d commit 0eac3fc
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
4 changes: 1 addition & 3 deletions signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ func NewSigner(alg Algorithm, key crypto.Signer) (Signer, error) {
return &ed25519Signer{
key: key,
}, nil
case AlgorithmRS256, AlgorithmRS384, AlgorithmRS512:
return nil, fmt.Errorf("can't create new Signer for %s: %w", alg, ErrAlgorithmNotSupported)
default:
return nil, ErrAlgorithmNotSupported
return nil, fmt.Errorf("can't create new Signer for %s: %w", alg, ErrAlgorithmNotSupported)
}
}
7 changes: 6 additions & 1 deletion signer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,12 @@ func TestNewSigner(t *testing.T) {
{
name: "unknown algorithm",
alg: 0,
wantErr: "algorithm not supported",
wantErr: "can't create new Signer for Reserved: algorithm not supported",
},
{
name: "unassigned algorithm",
alg: -1,
wantErr: "can't create new Signer for unknown algorithm value -1: algorithm not supported",
},
}
for _, tt := range tests {
Expand Down
4 changes: 1 addition & 3 deletions verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ func NewVerifier(alg Algorithm, key crypto.PublicKey) (Verifier, error) {
return &ed25519Verifier{
key: vk,
}, nil
case AlgorithmRS256, AlgorithmRS384, AlgorithmRS512:
return nil, fmt.Errorf("can't create new Verifier for %s: %w", alg, ErrAlgorithmNotSupported)
default:
return nil, ErrAlgorithmNotSupported
return nil, fmt.Errorf("can't create new Verifier for %s: %w", alg, ErrAlgorithmNotSupported)
}
}
7 changes: 6 additions & 1 deletion verifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,12 @@ func TestNewVerifier(t *testing.T) {
{
name: "unknown algorithm",
alg: 0,
wantErr: "algorithm not supported",
wantErr: "can't create new Verifier for Reserved: algorithm not supported",
},
{
name: "unassigned algorithm",
alg: -1,
wantErr: "can't create new Verifier for unknown algorithm value -1: algorithm not supported",
},
{
name: "bogus ecdsa public key (point not on curve)",
Expand Down

0 comments on commit 0eac3fc

Please sign in to comment.