| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3533,6 +3533,9 @@ and it will be impossible to extract the private key from the returned object. | |||
| 3533 | 3533 | <!-- YAML | |
| 3534 | 3534 | added: v11.6.0 | |
| 3535 | 3535 | changes: | |
| 3536 | + - version: REPLACEME | ||
| 3537 | + pr-url: https://github.com/nodejs/node/pull/44201 | ||
| 3538 | + description: The key can now be zero-length. | ||
| 3536 | 3539 | - version: v15.0.0 | |
| 3537 | 3540 | pr-url: https://github.com/nodejs/node/pull/35093 | |
| 3538 | 3541 | description: The key can also be an ArrayBuffer or string. The encoding | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -38,7 +38,6 @@ const { | |||
| 38 | 38 | ERR_ILLEGAL_CONSTRUCTOR, | |
| 39 | 39 | ERR_INVALID_ARG_TYPE, | |
| 40 | 40 | ERR_INVALID_ARG_VALUE, | |
| 41 | - ERR_OUT_OF_RANGE, | ||
| 42 | 41 | } | |
| 43 | 42 | } = require('internal/errors'); | |
| 44 | 43 | ||
@@ -588,8 +587,6 @@ function prepareSecretKey(key, encoding, bufferOnly = false) { | |||
| 588 | 587 | ||
| 589 | 588 | function createSecretKey(key, encoding) { | |
| 590 | 589 | key = prepareSecretKey(key, encoding, true); | |
| 591 | - if (key.byteLength === 0) | ||
| 592 | - throw new ERR_OUT_OF_RANGE('key.byteLength', '> 0', key.byteLength); | ||
| 593 | 590 | const handle = new KeyObjectHandle(); | |
| 594 | 591 | handle.init(kKeyTypeSecret, key); | |
| 595 | 592 | return new SecretKeyObject(handle); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -871,7 +871,6 @@ void KeyObjectData::MemoryInfo(MemoryTracker* tracker) const { | |||
| 871 | 871 | } | |
| 872 | 872 | ||
| 873 | 873 | std::shared_ptr<KeyObjectData> KeyObjectData::CreateSecret(ByteSource key) { | |
| 874 | - CHECK(key); | ||
| 875 | 874 | return std::shared_ptr<KeyObjectData>(new KeyObjectData(std::move(key))); | |
| 876 | 875 | } | |
| 877 | 876 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -450,3 +450,12 @@ assert.strictEqual( | |||
| 450 | 450 | () => crypto.createHmac('sha7', 'key'), | |
| 451 | 451 | /Invalid digest/); | |
| 452 | 452 | } | |
| 453 | + | ||
| 454 | + { | ||
| 455 | + const buf = Buffer.alloc(0); | ||
| 456 | + const keyObject = crypto.createSecretKey(Buffer.alloc(0)); | ||
| 457 | + assert.deepStrictEqual( | ||
| 458 | + crypto.createHmac('sha256', buf).update('foo').digest(), | ||
| 459 | + crypto.createHmac('sha256', keyObject).update('foo').digest(), | ||
| 460 | + ); | ||
| 461 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,18 +33,6 @@ const publicDsa = fixtures.readKey('dsa_public_1025.pem', 'ascii'); | |||
| 33 | 33 | const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem', | |
| 34 | 34 | 'ascii'); | |
| 35 | 35 | ||
| 36 | - { | ||
| 37 | - // Attempting to create an empty key should throw. | ||
| 38 | - assert.throws(() => { | ||
| 39 | - createSecretKey(Buffer.alloc(0)); | ||
| 40 | - }, { | ||
| 41 | - name: 'RangeError', | ||
| 42 | - code: 'ERR_OUT_OF_RANGE', | ||
| 43 | - message: 'The value of "key.byteLength" is out of range. ' + | ||
| 44 | - 'It must be > 0. Received 0' | ||
| 45 | - }); | ||
| 46 | - } | ||
| 47 | - | ||
| 48 | 36 | { | |
| 49 | 37 | // Attempting to create a key of a wrong type should throw | |
| 50 | 38 | const TYPE = 'wrong_type'; | |
@@ -870,3 +858,13 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem', | |||
| 870 | 858 | assert(!first.privateKey.equals(second.privateKey)); | |
| 871 | 859 | assert(!first.privateKey.equals(second.publicKey)); | |
| 872 | 860 | } | |
| 861 | + | ||
| 862 | + { | ||
| 863 | + const first = createSecretKey(Buffer.alloc(0)); | ||
| 864 | + const second = createSecretKey(new ArrayBuffer(0)); | ||
| 865 | + const third = createSecretKey(Buffer.alloc(1)); | ||
| 866 | + assert(first.equals(first)); | ||
| 867 | + assert(first.equals(second)); | ||
| 868 | + assert(!first.equals(third)); | ||
| 869 | + assert(!third.equals(first)); | ||
| 870 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments