Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HMAC fix for the sign and verify #68

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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