Skip to content

Commit

Permalink
hmac: fix for the sign and verify
Browse files Browse the repository at this point in the history
  • Loading branch information
olegbespalov committed Apr 11, 2024
1 parent 21a21a7 commit aee226d
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions webcrypto/subtle_crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down Expand Up @@ -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
Expand All @@ -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
}

Expand Down

0 comments on commit aee226d

Please sign in to comment.