Skip to content

Commit c92170c

Browse files
committed
fix: crash when importKey is provided empty bytes for data
1 parent 331073c commit c92170c

File tree

5 files changed

+24
-10
lines changed

5 files changed

+24
-10
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ node_modules/
33
tsconfig.tsbuildinfo
44
package-lock.json
55
.vscode/settings.json
6+
.vscode/mcp.json

bun.lockb

0 Bytes
Binary file not shown.

packages/example/ios/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,6 @@ SPEC CHECKSUMS:
652652
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
653653
Yoga: 4c3aa327e4a6a23eeacd71f61c81df1bcdf677d5
654654

655-
PODFILE CHECKSUM: 30bd43484b3dbde5a95cbc2b8bc0e28edb1e7bb6
655+
PODFILE CHECKSUM: 47469ccd5c1c311cbf9db829bd8c082c7fc29cca
656656

657657
COCOAPODS: 1.15.2

packages/example/src/testing/tests/webcryptoTests/import_export.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
import { assert, expect } from 'chai';
21
import { Buffer } from '@craftzdog/react-native-buffer';
2+
import { assert, expect } from 'chai';
33
import {
44
fromByteArray,
55
toByteArray,
66
trimBase64Padding,
77
} from 'react-native-quick-base64';
88
import crypto from 'react-native-quick-crypto';
9-
import { describe, it } from '../../MochaRNAdapter';
10-
import {
11-
ab2str,
12-
binaryLikeToArrayBuffer,
13-
} from '../../../../../react-native-quick-crypto/src/Utils';
14-
import { assertThrowsAsync } from '../util';
159
import type {
1610
CryptoKey,
1711
CryptoKeyPair,
@@ -23,8 +17,14 @@ import type {
2317
SubtleAlgorithm,
2418
} from '../../../../../react-native-quick-crypto/src/keys';
2519
import type { RandomTypedArrays } from '../../../../../react-native-quick-crypto/src/random';
26-
import pubTestKeyEc256 from '../../fixtures/keys/ec_p256_public';
20+
import {
21+
ab2str,
22+
binaryLikeToArrayBuffer,
23+
} from '../../../../../react-native-quick-crypto/src/Utils';
2724
import privTestKeyEc256 from '../../fixtures/keys/ec_p256_private';
25+
import pubTestKeyEc256 from '../../fixtures/keys/ec_p256_public';
26+
import { describe, it } from '../../MochaRNAdapter';
27+
import { assertThrowsAsync } from '../util';
2828

2929
const { subtle, createPublicKey, createPrivateKey } = crypto;
3030

@@ -132,6 +132,20 @@ describe('subtle - importKey / exportKey', () => {
132132
);
133133
});
134134

135+
136+
it(' importKey - raw - pbkdf2 - empty byte source #735', async () => {
137+
const key = await crypto.subtle.importKey(
138+
'raw',
139+
new Uint8Array(),
140+
{
141+
name: 'PBKDF2',
142+
hash: 'SHA-256',
143+
},
144+
false,
145+
['deriveBits', 'deriveKey']);
146+
expect(key).to.not.equal(null);
147+
});
148+
135149
// Import/Export AES Secret Key
136150
{
137151
it('AES import raw / export raw', async () => {

packages/react-native-quick-crypto/cpp/MGLKeys.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,6 @@ KeyObjectData::KeyObjectData(KeyType type,
806806

807807
std::shared_ptr<KeyObjectData> KeyObjectData::CreateSecret(ByteSource key)
808808
{
809-
CHECK(key);
810809
return std::shared_ptr<KeyObjectData>(new KeyObjectData(std::move(key)));
811810
}
812811

0 commit comments

Comments
 (0)