Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Théo Crevon <[email protected]>
  • Loading branch information
olegbespalov and oleiade committed Oct 25, 2024
1 parent 6813847 commit 234194a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 7 additions & 1 deletion webcrypto/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package webcrypto

import (
"errors"
"strings"

"github.com/grafana/sobek"
)
Expand Down Expand Up @@ -191,7 +192,12 @@ func newKeyGenerator(rt *sobek.Runtime, normalized Algorithm, params sobek.Value
case RSASsaPkcs1v15, RSAPss, RSAOaep:
kg, err = newRsaHashedKeyGenParams(rt, normalized, params)
default:
return nil, NewError(NotImplemented, "unsupported algorithm for key generation: "+normalized.Name)
validAlgorithms := []string{AESCbc, AESCtr, AESGcm, AESKw, HMAC, ECDH, ECDSA, RSASsaPkcs1v15, RSAPss, RSAOaep}
return nil, NewError(
NotImplemented,
"unsupported key generation algorithm '"+normalized.Name+"', "+
"accepted values are: "+strings.Join(validAlgorithms, ", "),
)
}

if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion webcrypto/subtle_crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,11 @@ func (sc *SubtleCrypto) Digest(algorithm sobek.Value, data sobek.Value) *sobek.P
var ok bool
hashFn, ok = getHashFn(normalized.Name)
if !ok {
return NewError(NotSupportedError, "unsupported algorithm, can't map hash function: "+normalized.Name)
return NewError(
NotSupportedError,
"unsupported digest algorithm '"+normalized.Name+"', "+
"accepted values are: SHA-1, SHA-256, SHA-384, and SHA-512",
)
}

return nil
Expand Down

0 comments on commit 234194a

Please sign in to comment.