🐛 aes-128-cbc not in CipherCCMTypes in createCipheriv function
What's happening?
After upgrading from 0.6.1 to 0.7.1 function createCipheriv shows type error saying
Argument of type '"aes-128-cbc"' is not assignable to parameter of type 'CipherGCMTypes'
Reproducible Code
import { Buffer } from "@craftzdog/react-native-buffer";
import crypto from "react-native-quick-crypto";
const KEY = ...
const IV = ...
const cipher = crypto.createCipheriv("aes-128-cbc", Buffer.from(KEY, "utf8"), Buffer.from(IV, "utf8"));
Relevant log output
Argument of type '"aes-128-cbc"' is not assignable to parameter of type 'CipherGCMTypes'.
Device
Iphone 11
QuickCrypto Version
0.7.1
Can you reproduce this issue in the QuickCrypto Example app?
Yes, I can reproduce the same issue in the Example app here
Additional information
- [ ] I am using Expo
- [X] I have read the Troubleshooting Guide
- [X] I agree to follow this project's Code of Conduct
- [X] I searched for similar issues in this repository and found none.
@Miigaarino,
Are you sure that algorithm is allowed in Node crypto? I don't see it in @node/types here.
@shamilovtim made the types a bit stronger than any in #247 by using @node/types.
See if you can find somewhere online where createCipheriv() should support aes-128-cbc 🙏
In the implementation file (src/Cipher.ts), the createCipheriv function accepts algorithm strings: https://github.com/margelo/react-native-quick-crypto/blob/v0.7.3/src/Cipher.ts#L345-L356
However, in the type definition file (node_modules/react-native-quick-crypto/lib/typescript/Cipher.d.ts), the algorithm parameter is restricted to CipherCCM, CipherOCB, CipherGCM.
export declare function createCipheriv(algorithm: CipherCCMTypes, key: BinaryLikeNode, iv: BinaryLike, options: CipherCCMOptions): CipherCCM;
export declare function createCipheriv(algorithm: CipherOCBTypes, key: BinaryLikeNode, iv: BinaryLike, options: CipherOCBOptions): CipherOCB;
export declare function createCipheriv(algorithm: CipherGCMTypes, key: BinaryLikeNode, iv: BinaryLike, options?: CipherGCMOptions): CipherGCM;
In the implementation file (src/Cipher.ts), the createCipheriv function accepts algorithm strings: https://github.com/margelo/react-native-quick-crypto/blob/v0.7.3/src/Cipher.ts#L345-L356
However, in the type definition file (node_modules/react-native-quick-crypto/lib/typescript/Cipher.d.ts), the algorithm parameter is restricted to CipherCCM, CipherOCB, CipherGCM.
export declare function createCipheriv(algorithm: CipherCCMTypes, key: BinaryLikeNode, iv: BinaryLike, options: CipherCCMOptions): CipherCCM; export declare function createCipheriv(algorithm: CipherOCBTypes, key: BinaryLikeNode, iv: BinaryLike, options: CipherOCBOptions): CipherOCB; export declare function createCipheriv(algorithm: CipherGCMTypes, key: BinaryLikeNode, iv: BinaryLike, options?: CipherGCMOptions): CipherGCM;![]()
That's just one of the overloads. Above it you'll see the other overloads that narrow the algorithm based on the combination of params passed.
@Miigaarino @blluv if this is a bug in this case the bug is in @node/types. Consider opening this issue or a PR in https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/crypto.d.ts#L677-L679 and following up there with either an issue or a PR.
I think I've handled this a bit better in #419
My ask above was for someone to validate if Node supports this. Actually I did handle it in #419 but might not have gotten aes-128-cbc. I'll add a test for all of them soon.