Skip to content

Commit

Permalink
fix: refactor types for rsaFunctionFor to include BufferLike (#590)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanYeeW authored Jan 24, 2025
1 parent 5984b4d commit a1c857c
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions packages/react-native-quick-crypto/src/Cipher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,14 +417,35 @@ function rsaFunctionFor(
defaultPadding: number,
keyType: 'public' | 'private',
) {
return (options: EncodingOptions, buffer: BinaryLike) => {
return (options: EncodingOptions | BinaryLike, buffer: BinaryLike) => {
const { format, type, data, passphrase } =
keyType === 'private'
? preparePrivateKey(options)
: preparePublicOrPrivateKey(options);
const padding = options.padding || defaultPadding;
const { oaepHash, encoding } = options;
let { oaepLabel } = options;

const padding =
options &&
typeof options === 'object' &&
'padding' in options &&
typeof options.padding === 'number'
? options.padding
: defaultPadding;

const oaepHash =
options && typeof options === 'object' && 'oaepHash' in options
? options.oaepHash
: undefined;

const encoding =
options && typeof options === 'object' && 'encoding' in options
? options.encoding
: undefined;

let oaepLabel =
options && typeof options === 'object' && 'oaepLabel' in options
? options.oaepLabel
: undefined;

if (oaepHash !== undefined) validateString(oaepHash, 'key.oaepHash');
if (oaepLabel !== undefined)
oaepLabel = binaryLikeToArrayBuffer(oaepLabel, encoding);
Expand Down

0 comments on commit a1c857c

Please sign in to comment.