@@ -92,7 +92,7 @@ export interface RSAKey {
9292}
9393
9494export interface RSAKeyWithOps extends RSAKey {
95- encrypt : ( data : string | Uint8Array , scheme : string , schemeOptions ?: any ) => string
95+ encrypt : ( data : string | Uint8Array , scheme : string , schemeOptions ?: any ) => string | Uint8Array
9696 decrypt : ( data : string | Uint8Array , scheme : string , schemeOptions ?: any ) => string
9797 verify : ( digest : string | Uint8Array , signature : string | Uint8Array , scheme : string , options ?: any ) => boolean
9898 sign : ( md : string | Uint8Array , scheme ?: string ) => string
@@ -2039,11 +2039,12 @@ export function base64ToBigInt(b64: string): BigInteger {
20392039
20402040export function addRSAKeyOps ( key : RSAKey ) : RSAKeyWithOps {
20412041 const keyWithOps = key as RSAKeyWithOps
2042+ let encodeScheme : EncodeScheme
2043+
20422044 keyWithOps . encrypt = function ( data : string | Uint8Array , scheme : string , schemeOptions ?: any ) {
2043- let encodeScheme : EncodeScheme
20442045 if ( scheme === 'RSAES-PKCS1-V1_5' ) {
20452046 encodeScheme = {
2046- encode ( m : string | Uint8Array , key : RSAKey , pub : boolean ) {
2047+ encode ( m : string | Uint8Array , key : RSAKey , pub : boolean ) : string | Uint8Array {
20472048 return _encodePkcs1_v1_5 ( m as string , key , 0x02 ) . getBytes ( )
20482049 } ,
20492050 }
@@ -2141,9 +2142,9 @@ export function addRSAKeyOps(key: RSAKey): RSAKeyWithOps {
21412142
21422143 // validate DigestInfo
21432144 const capture = { }
2144- const errors = [ ]
2145+ const errors : CustomError [ ] = [ ]
21452146 if ( ! asn1 . validate ( obj , digestInfoValidator , capture , errors ) ) {
2146- var error = new Error (
2147+ const error : CustomError = new Error (
21472148 'ASN.1 object does not contain a valid RSASSA-PKCS1-v1_5 '
21482149 + 'DigestInfo value.' ,
21492150 )
@@ -2163,7 +2164,7 @@ export function addRSAKeyOps(key: RSAKey): RSAKeyWithOps {
21632164 || oid === oids . sha512
21642165 || oid === oids [ 'sha512-224' ]
21652166 || oid === oids [ 'sha512-256' ] ) ) {
2166- var error = new Error (
2167+ const error : CustomError = new Error (
21672168 'Unknown RSASSA-PKCS1-v1_5 DigestAlgorithm identifier.' ,
21682169 )
21692170 error . oid = oid
@@ -2218,4 +2219,5 @@ export const rsa: RSA = {
22182219 privateKeyFromPem,
22192220 privateKeyToPem,
22202221 privateKeyInfoToPem,
2222+ publicKeyValidator,
22212223}
0 commit comments