| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -45,6 +45,8 @@ const { | |||
| 45 | 45 | kKeyObject, | |
| 46 | 46 | } = require('internal/crypto/util'); | |
| 47 | 47 | ||
| 48 | + const { PromiseReject } = primordials; | ||
| 49 | + | ||
| 48 | 50 | const { | |
| 49 | 51 | codes: { | |
| 50 | 52 | ERR_INVALID_ARG_TYPE, | |
@@ -167,9 +169,9 @@ function asyncAesGcmCipher( | |||
| 167 | 169 | data, | |
| 168 | 170 | { iv, additionalData, tagLength = 128 }) { | |
| 169 | 171 | if (!ArrayPrototypeIncludes(kTagLengths, tagLength)) { | |
| 170 | - throw lazyDOMException( | ||
| 172 | + return PromiseReject(lazyDOMException( | ||
| 171 | 173 | `${tagLength} is not a valid AES-GCM tag length`, | |
| 172 | - 'OperationError'); | ||
| 174 | + 'OperationError')); | ||
| 173 | 175 | } | |
| 174 | 176 | ||
| 175 | 177 | iv = getArrayBufferOrView(iv, 'algorithm.iv'); | |
@@ -188,6 +190,17 @@ function asyncAesGcmCipher( | |||
| 188 | 190 | const slice = ArrayBufferIsView(data) ? | |
| 189 | 191 | TypedArrayPrototypeSlice : ArrayBufferPrototypeSlice; | |
| 190 | 192 | tag = slice(data, -tagByteLength); | |
| 193 | + | ||
| 194 | + // Refs: https://www.w3.org/TR/WebCryptoAPI/#aes-gcm-operations | ||
| 195 | + // | ||
| 196 | + // > If *plaintext* has a length less than *tagLength* bits, then `throw` | ||
| 197 | + // > an `OperationError`. | ||
| 198 | + if (tagByteLength > tag.byteLength) { | ||
| 199 | + return PromiseReject(lazyDOMException( | ||
| 200 | + 'The provided data is too small.', | ||
| 201 | + 'OperationError')); | ||
| 202 | + } | ||
| 203 | + | ||
| 191 | 204 | data = slice(data, 0, -tagByteLength); | |
| 192 | 205 | break; | |
| 193 | 206 | case kWebCryptoCipherEncrypt: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,29 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + | ||
| 5 | + if (!common.hasCrypto) | ||
| 6 | + common.skip('missing crypto'); | ||
| 7 | + | ||
| 8 | + const assert = require('assert'); | ||
| 9 | + const crypto = require('crypto').webcrypto; | ||
| 10 | + | ||
| 11 | + crypto.subtle.importKey( | ||
| 12 | + 'raw', | ||
| 13 | + new Uint8Array(32), | ||
| 14 | + { | ||
| 15 | + name: 'AES-GCM' | ||
| 16 | + }, | ||
| 17 | + false, | ||
| 18 | + [ 'encrypt', 'decrypt' ]) | ||
| 19 | + .then((k) => { | ||
| 20 | + assert.rejects(() => { | ||
| 21 | + return crypto.subtle.decrypt({ | ||
| 22 | + name: 'AES-GCM', | ||
| 23 | + iv: new Uint8Array(12), | ||
| 24 | + }, k, new Uint8Array(0)); | ||
| 25 | + }, { | ||
| 26 | + name: 'OperationError', | ||
| 27 | + message: /The provided data is too small/, | ||
| 28 | + }); | ||
| 29 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments