From aee226d725baf1abc581d75f08e92722d058cf24 Mon Sep 17 00:00:00 2001 From: Oleg Bespalov Date: Wed, 10 Apr 2024 15:38:22 +0200 Subject: [PATCH] hmac: fix for the sign and verify --- webcrypto/subtle_crypto.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/webcrypto/subtle_crypto.go b/webcrypto/subtle_crypto.go index e951216..065fdd6 100644 --- a/webcrypto/subtle_crypto.go +++ b/webcrypto/subtle_crypto.go @@ -266,7 +266,7 @@ func (sc *SubtleCrypto) Sign(algorithm, key, data goja.Value) *goja.Promise { // 10. switch normalized.Name { case HMAC: - keyAlgorithm, ok := ck.Algorithm.(HMACKeyAlgorithm) + keyAlgorithm, ok := ck.Algorithm.(hasHash) if !ok { reject(NewError(InvalidAccessError, "key algorithm does not describe a HMAC key")) return @@ -278,9 +278,9 @@ func (sc *SubtleCrypto) Sign(algorithm, key, data goja.Value) *goja.Promise { return } - hashFn, err := keyAlgorithm.HashFn() - if err != nil { - reject(err) + hashFn, ok := getHashFn(keyAlgorithm.hash()) + if !ok { + reject(NewError(NotSupportedError, "unsupported hash algorithm "+keyAlgorithm.hash())) return } @@ -374,7 +374,7 @@ func (sc *SubtleCrypto) Verify(algorithm, key, signature, data goja.Value) *goja switch normalizedAlgorithm.Name { case HMAC: - keyAlgorithm, ok := ck.Algorithm.(HMACKeyAlgorithm) + keyAlgorithm, ok := ck.Algorithm.(hasHash) if !ok { reject(NewError(InvalidAccessError, "key algorithm does not describe a HMAC key")) return @@ -386,9 +386,9 @@ func (sc *SubtleCrypto) Verify(algorithm, key, signature, data goja.Value) *goja return } - hashFn, err := keyAlgorithm.HashFn() - if err != nil { - reject(err) + hashFn, ok := getHashFn(keyAlgorithm.hash()) + if !ok { + reject(NewError(NotSupportedError, "unsupported hash algorithm "+keyAlgorithm.hash())) return }