From 234194aefb67065d84c37f2f750e8e3acf91c7c6 Mon Sep 17 00:00:00 2001 From: Oleg Bespalov Date: Fri, 25 Oct 2024 14:33:06 +0200 Subject: [PATCH] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Théo Crevon --- webcrypto/key.go | 8 +++++++- webcrypto/subtle_crypto.go | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/webcrypto/key.go b/webcrypto/key.go index fa0b5e4..0f56a4b 100644 --- a/webcrypto/key.go +++ b/webcrypto/key.go @@ -2,6 +2,7 @@ package webcrypto import ( "errors" + "strings" "github.com/grafana/sobek" ) @@ -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 { diff --git a/webcrypto/subtle_crypto.go b/webcrypto/subtle_crypto.go index 30a34fc..00b6367 100644 --- a/webcrypto/subtle_crypto.go +++ b/webcrypto/subtle_crypto.go @@ -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