Skip to content
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
crypto,test: improve hmac coverage with webcrypto tests
PR-URL: #37571
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
obi-el authored and aduh95 committed Mar 8, 2021
commit 4811210ca7e49e12512912f3b1bc8fa0ba67ed0f
47 changes: 47 additions & 0 deletions test/parallel/test-webcrypto-export-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,53 @@ const { subtle, getRandomValues } = require('crypto').webcrypto;
code: 'ERR_INVALID_ARG_TYPE'
});
});
assert.rejects(
subtle.importKey('raw', keyData, {
name: 'HMAC'
}, false, ['sign', 'verify']), {
code: 'ERR_MISSING_OPTION'
}).then(common.mustCall());
assert.rejects(
subtle.importKey('raw', keyData, {
name: 'HMAC',
hash: 'SHA-256'
}, false, ['deriveBits']), {
name: 'SyntaxError',
message: 'Unsupported key usage for an HMAC key'
}).then(common.mustCall());
assert.rejects(
subtle.importKey('node.keyObject', '', {
name: 'HMAC',
hash: 'SHA-256'
}, false, ['sign', 'verify']), {
code: 'ERR_INVALID_ARG_TYPE'
}).then(common.mustCall());
assert.rejects(
subtle.importKey('raw', keyData, {
name: 'HMAC',
hash: 'SHA-256',
length: 0
}, false, ['sign', 'verify']), {
name: 'DataError',
message: 'Zero-length key is not supported'
}).then(common.mustCall());
assert.rejects(
subtle.importKey('raw', keyData, {
name: 'HMAC',
hash: 'SHA-256',
length: 1
}, false, ['sign', 'verify']), {
name: 'DataError',
message: 'Invalid key length'
}).then(common.mustCall());
assert.rejects(
subtle.importKey('jwk', null, {
name: 'HMAC',
hash: 'SHA-256',
}, false, ['sign', 'verify']), {
name: 'DataError',
message: 'Invalid JWK keyData'
}).then(common.mustCall());
}

// Import/Export HMAC Secret Key
Expand Down