| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -66,25 +66,25 @@ const kData = (new TextEncoder()).encode('hello'); | |||
| 66 | 66 | })); | |
| 67 | 67 | })().then(common.mustCall()); | |
| 68 | 68 | ||
| 69 | - [1, [], {}, null, undefined].forEach((i) => { | ||
| 70 | - assert.rejects(subtle.digest(i), { message: /Unrecognized name/ }); | ||
| 71 | - }); | ||
| 69 | + Promise.all([1, [], {}, null, undefined].map((i) => | ||
| 70 | + assert.rejects(subtle.digest(i), { message: /Unrecognized name/ }) | ||
| 71 | + )).then(common.mustCall()); | ||
| 72 | 72 | ||
| 73 | - assert.rejects(subtle.digest(''), { message: /Unrecognized name/ }); | ||
| 73 | + assert.rejects(subtle.digest(''), { message: /Unrecognized name/ }).then(common.mustCall()); | ||
| 74 | 74 | ||
| 75 | - [1, [], {}, null, undefined].forEach((i) => { | ||
| 75 | + Promise.all([1, [], {}, null, undefined].map((i) => | ||
| 76 | 76 | assert.rejects(subtle.digest('SHA-256', i), { | |
| 77 | 77 | code: 'ERR_INVALID_ARG_TYPE' | |
| 78 | - }); | ||
| 79 | - }); | ||
| 78 | + }) | ||
| 79 | + )).then(common.mustCall()); | ||
| 80 | 80 | ||
| 81 | 81 | // If there is a mismatch between length and the expected digest size for | |
| 82 | 82 | // the selected algorithm, we fail. The length is a Node.js specific | |
| 83 | 83 | // addition to the API, and is added as a support for future additional | |
| 84 | 84 | // hash algorithms that support variable digest output lengths. | |
| 85 | 85 | assert.rejects(subtle.digest({ name: 'SHA-512', length: 510 }, kData), { | |
| 86 | 86 | message: /Digest method not supported/ | |
| 87 | - }); | ||
| 87 | + }).then(common.mustCall()); | ||
| 88 | 88 | ||
| 89 | 89 | const kSourceData = { | |
| 90 | 90 | empty: '', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -65,7 +65,7 @@ assert.rejects( | |||
| 65 | 65 | ['sign']), | |
| 66 | 66 | { | |
| 67 | 67 | message: /NODE-ED25519 raw keys must be exactly 32-bytes/ | |
| 68 | - }); | ||
| 68 | + }).then(common.mustCall()); | ||
| 69 | 69 | ||
| 70 | 70 | assert.rejects( | |
| 71 | 71 | subtle.importKey( | |
@@ -79,7 +79,7 @@ assert.rejects( | |||
| 79 | 79 | ['sign']), | |
| 80 | 80 | { | |
| 81 | 81 | message: /NODE-ED448 raw keys must be exactly 57-bytes/ | |
| 82 | - }); | ||
| 82 | + }).then(common.mustCall()); | ||
| 83 | 83 | ||
| 84 | 84 | const testVectors = { | |
| 85 | 85 | 'NODE-ED25519': [ | |
@@ -331,7 +331,7 @@ assert.rejects( | |||
| 331 | 331 | ['sign', 'verify']), | |
| 332 | 332 | { | |
| 333 | 333 | message: /Unsupported named curves for ECDSA/ | |
| 334 | - }); | ||
| 334 | + }).then(common.mustCall()); | ||
| 335 | 335 | ||
| 336 | 336 | assert.rejects( | |
| 337 | 337 | subtle.generateKey( | |
@@ -343,7 +343,7 @@ assert.rejects( | |||
| 343 | 343 | ['sign', 'verify']), | |
| 344 | 344 | { | |
| 345 | 345 | message: /Unsupported named curves for ECDSA/ | |
| 346 | - }); | ||
| 346 | + }).then(common.mustCall()); | ||
| 347 | 347 | ||
| 348 | 348 | assert.rejects( | |
| 349 | 349 | subtle.generateKey( | |
@@ -355,7 +355,7 @@ assert.rejects( | |||
| 355 | 355 | ['sign', 'verify']), | |
| 356 | 356 | { | |
| 357 | 357 | message: /Unsupported named curves for ECDSA/ | |
| 358 | - }); | ||
| 358 | + }).then(common.mustCall()); | ||
| 359 | 359 | ||
| 360 | 360 | assert.rejects( | |
| 361 | 361 | subtle.generateKey( | |
@@ -367,7 +367,7 @@ assert.rejects( | |||
| 367 | 367 | ['sign', 'verify']), | |
| 368 | 368 | { | |
| 369 | 369 | message: /Unsupported named curves for ECDSA/ | |
| 370 | - }); | ||
| 370 | + }).then(common.mustCall()); | ||
| 371 | 371 | ||
| 372 | 372 | { | |
| 373 | 373 | for (const asymmetricKeyType of ['ed25519', 'ed448']) { | |
@@ -398,7 +398,7 @@ assert.rejects( | |||
| 398 | 398 | ), | |
| 399 | 399 | { | |
| 400 | 400 | message: /Invalid algorithm name/ | |
| 401 | - }); | ||
| 401 | + }).then(common.mustCall()); | ||
| 402 | 402 | ||
| 403 | 403 | assert.rejects( | |
| 404 | 404 | subtle.importKey( | |
@@ -413,7 +413,7 @@ assert.rejects( | |||
| 413 | 413 | ), | |
| 414 | 414 | { | |
| 415 | 415 | message: /Invalid algorithm name/ | |
| 416 | - }); | ||
| 416 | + }).then(common.mustCall()); | ||
| 417 | 417 | } | |
| 418 | 418 | } | |
| 419 | 419 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,70 +9,74 @@ const assert = require('assert'); | |||
| 9 | 9 | const { subtle, getRandomValues } = require('crypto').webcrypto; | |
| 10 | 10 | ||
| 11 | 11 | { | |
| 12 | - const keyData = getRandomValues(new Uint8Array(32)); | ||
| 13 | - [1, null, undefined, {}, []].forEach((format) => { | ||
| 14 | - assert.rejects( | ||
| 15 | - subtle.importKey(format, keyData, {}, false, ['wrapKey']), { | ||
| 16 | - code: 'ERR_INVALID_ARG_TYPE' | ||
| 12 | + async function test() { | ||
| 13 | + const keyData = getRandomValues(new Uint8Array(32)); | ||
| 14 | + await Promise.all([1, null, undefined, {}, []].map((format) => | ||
| 15 | + assert.rejects( | ||
| 16 | + subtle.importKey(format, keyData, {}, false, ['wrapKey']), { | ||
| 17 | + code: 'ERR_INVALID_ARG_TYPE' | ||
| 18 | + }) | ||
| 19 | + )); | ||
| 20 | + await assert.rejects( | ||
| 21 | + subtle.importKey('not valid', keyData, {}, false, ['wrapKey']), { | ||
| 22 | + code: 'ERR_INVALID_ARG_VALUE' | ||
| 17 | 23 | }); | |
| 18 | - }); | ||
| 19 | - assert.rejects( | ||
| 20 | - subtle.importKey('not valid', keyData, {}, false, ['wrapKey']), { | ||
| 21 | - code: 'ERR_INVALID_ARG_VALUE' | ||
| 22 | - }); | ||
| 23 | - [1, null, undefined, {}, []].forEach((keyData) => { | ||
| 24 | - assert.rejects( | ||
| 25 | - subtle.importKey('raw', keyData, {}, false, ['deriveBits']), { | ||
| 24 | + await Promise.all([1, null, undefined, {}, []].map((keyData) => | ||
| 25 | + assert.rejects( | ||
| 26 | + subtle.importKey('raw', keyData, {}, false, ['deriveBits']), { | ||
| 27 | + code: 'ERR_INVALID_ARG_TYPE' | ||
| 28 | + }) | ||
| 29 | + )); | ||
| 30 | + await assert.rejects( | ||
| 31 | + subtle.importKey('raw', keyData, { | ||
| 32 | + name: 'HMAC' | ||
| 33 | + }, false, ['sign', 'verify']), { | ||
| 34 | + code: 'ERR_MISSING_OPTION' | ||
| 35 | + }); | ||
| 36 | + await assert.rejects( | ||
| 37 | + subtle.importKey('raw', keyData, { | ||
| 38 | + name: 'HMAC', | ||
| 39 | + hash: 'SHA-256' | ||
| 40 | + }, false, ['deriveBits']), { | ||
| 41 | + name: 'SyntaxError', | ||
| 42 | + message: 'Unsupported key usage for an HMAC key' | ||
| 43 | + }); | ||
| 44 | + await assert.rejects( | ||
| 45 | + subtle.importKey('node.keyObject', '', { | ||
| 46 | + name: 'HMAC', | ||
| 47 | + hash: 'SHA-256' | ||
| 48 | + }, false, ['sign', 'verify']), { | ||
| 26 | 49 | code: 'ERR_INVALID_ARG_TYPE' | |
| 27 | 50 | }); | |
| 28 | - }); | ||
| 29 | - assert.rejects( | ||
| 30 | - subtle.importKey('raw', keyData, { | ||
| 31 | - name: 'HMAC' | ||
| 32 | - }, false, ['sign', 'verify']), { | ||
| 33 | - code: 'ERR_MISSING_OPTION' | ||
| 34 | - }).then(common.mustCall()); | ||
| 35 | - assert.rejects( | ||
| 36 | - subtle.importKey('raw', keyData, { | ||
| 37 | - name: 'HMAC', | ||
| 38 | - hash: 'SHA-256' | ||
| 39 | - }, false, ['deriveBits']), { | ||
| 40 | - name: 'SyntaxError', | ||
| 41 | - message: 'Unsupported key usage for an HMAC key' | ||
| 42 | - }).then(common.mustCall()); | ||
| 43 | - assert.rejects( | ||
| 44 | - subtle.importKey('node.keyObject', '', { | ||
| 45 | - name: 'HMAC', | ||
| 46 | - hash: 'SHA-256' | ||
| 47 | - }, false, ['sign', 'verify']), { | ||
| 48 | - code: 'ERR_INVALID_ARG_TYPE' | ||
| 49 | - }).then(common.mustCall()); | ||
| 50 | - assert.rejects( | ||
| 51 | - subtle.importKey('raw', keyData, { | ||
| 52 | - name: 'HMAC', | ||
| 53 | - hash: 'SHA-256', | ||
| 54 | - length: 0 | ||
| 55 | - }, false, ['sign', 'verify']), { | ||
| 56 | - name: 'DataError', | ||
| 57 | - message: 'Zero-length key is not supported' | ||
| 58 | - }).then(common.mustCall()); | ||
| 59 | - assert.rejects( | ||
| 60 | - subtle.importKey('raw', keyData, { | ||
| 61 | - name: 'HMAC', | ||
| 62 | - hash: 'SHA-256', | ||
| 63 | - length: 1 | ||
| 64 | - }, false, ['sign', 'verify']), { | ||
| 65 | - name: 'DataError', | ||
| 66 | - message: 'Invalid key length' | ||
| 67 | - }).then(common.mustCall()); | ||
| 68 | - assert.rejects( | ||
| 69 | - subtle.importKey('jwk', null, { | ||
| 70 | - name: 'HMAC', | ||
| 71 | - hash: 'SHA-256', | ||
| 72 | - }, false, ['sign', 'verify']), { | ||
| 73 | - name: 'DataError', | ||
| 74 | - message: 'Invalid JWK keyData' | ||
| 75 | - }).then(common.mustCall()); | ||
| 51 | + await assert.rejects( | ||
| 52 | + subtle.importKey('raw', keyData, { | ||
| 53 | + name: 'HMAC', | ||
| 54 | + hash: 'SHA-256', | ||
| 55 | + length: 0 | ||
| 56 | + }, false, ['sign', 'verify']), { | ||
| 57 | + name: 'DataError', | ||
| 58 | + message: 'Zero-length key is not supported' | ||
| 59 | + }); | ||
| 60 | + await assert.rejects( | ||
| 61 | + subtle.importKey('raw', keyData, { | ||
| 62 | + name: 'HMAC', | ||
| 63 | + hash: 'SHA-256', | ||
| 64 | + length: 1 | ||
| 65 | + }, false, ['sign', 'verify']), { | ||
| 66 | + name: 'DataError', | ||
| 67 | + message: 'Invalid key length' | ||
| 68 | + }); | ||
| 69 | + await assert.rejects( | ||
| 70 | + subtle.importKey('jwk', null, { | ||
| 71 | + name: 'HMAC', | ||
| 72 | + hash: 'SHA-256', | ||
| 73 | + }, false, ['sign', 'verify']), { | ||
| 74 | + name: 'DataError', | ||
| 75 | + message: 'Invalid JWK keyData' | ||
| 76 | + }); | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + test().then(common.mustCall()); | ||
| 76 | 80 | } | |
| 77 | 81 | ||
| 78 | 82 | // Import/Export HMAC Secret Key | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -59,10 +59,10 @@ async function importKey(namedCurve, keyData, isPublic = false) { | |||
| 59 | 59 | ||
| 60 | 60 | assert.rejects(importKey('NODE-X25519', Buffer.alloc(10), true), { | |
| 61 | 61 | message: /NODE-X25519 raw keys must be exactly 32-bytes/ | |
| 62 | - }); | ||
| 62 | + }).then(common.mustCall()); | ||
| 63 | 63 | assert.rejects(importKey('NODE-X448', Buffer.alloc(10), true), { | |
| 64 | 64 | message: /NODE-X448 raw keys must be exactly 56-bytes/ | |
| 65 | - }); | ||
| 65 | + }).then(common.mustCall()); | ||
| 66 | 66 | ||
| 67 | 67 | async function test1(namedCurve) { | |
| 68 | 68 | const { | |
@@ -235,7 +235,7 @@ assert.rejects( | |||
| 235 | 235 | ['deriveBits']), | |
| 236 | 236 | { | |
| 237 | 237 | message: /Unsupported named curves for ECDH/ | |
| 238 | - }); | ||
| 238 | + }).then(common.mustCall()); | ||
| 239 | 239 | ||
| 240 | 240 | assert.rejects( | |
| 241 | 241 | subtle.generateKey( | |
@@ -247,7 +247,7 @@ assert.rejects( | |||
| 247 | 247 | ['deriveBits']), | |
| 248 | 248 | { | |
| 249 | 249 | message: /Unsupported named curves for ECDH/ | |
| 250 | - }); | ||
| 250 | + }).then(common.mustCall()); | ||
| 251 | 251 | ||
| 252 | 252 | { | |
| 253 | 253 | // Private JWK import | |
| Back | FazBrowse Home | New Git URL |
0 commit comments