Skip to content

Commit a1c857c

Browse files
authored
fix: refactor types for rsaFunctionFor to include BufferLike (#590)
1 parent 5984b4d commit a1c857c

File tree

1 file changed

+25
-4
lines changed
  • packages/react-native-quick-crypto/src

1 file changed

+25
-4
lines changed

packages/react-native-quick-crypto/src/Cipher.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,14 +417,35 @@ function rsaFunctionFor(
417417
defaultPadding: number,
418418
keyType: 'public' | 'private',
419419
) {
420-
return (options: EncodingOptions, buffer: BinaryLike) => {
420+
return (options: EncodingOptions | BinaryLike, buffer: BinaryLike) => {
421421
const { format, type, data, passphrase } =
422422
keyType === 'private'
423423
? preparePrivateKey(options)
424424
: preparePublicOrPrivateKey(options);
425-
const padding = options.padding || defaultPadding;
426-
const { oaepHash, encoding } = options;
427-
let { oaepLabel } = options;
425+
426+
const padding =
427+
options &&
428+
typeof options === 'object' &&
429+
'padding' in options &&
430+
typeof options.padding === 'number'
431+
? options.padding
432+
: defaultPadding;
433+
434+
const oaepHash =
435+
options && typeof options === 'object' && 'oaepHash' in options
436+
? options.oaepHash
437+
: undefined;
438+
439+
const encoding =
440+
options && typeof options === 'object' && 'encoding' in options
441+
? options.encoding
442+
: undefined;
443+
444+
let oaepLabel =
445+
options && typeof options === 'object' && 'oaepLabel' in options
446+
? options.oaepLabel
447+
: undefined;
448+
428449
if (oaepHash !== undefined) validateString(oaepHash, 'key.oaepHash');
429450
if (oaepLabel !== undefined)
430451
oaepLabel = binaryLikeToArrayBuffer(oaepLabel, encoding);

0 commit comments

Comments
 (0)