@@ -1097,7 +1097,7 @@ export function setRsaPublicKey(n: BigInteger, e: BigInteger): {
10971097
10981098 if ( scheme === 'RSASSA-PKCS1-V1_5' ) {
10991099 scheme = {
1100- verify ( digest , d ) {
1100+ verify ( digest : string | Uint8Array , d : string ) {
11011101 // remove padding
11021102 d = _decodePkcs1_v1_5 ( d , key , true )
11031103 // d is ASN.1 BER-encoded DigestInfo
@@ -1106,7 +1106,7 @@ export function setRsaPublicKey(n: BigInteger, e: BigInteger): {
11061106 } )
11071107
11081108 // validate DigestInfo
1109- const capture = { }
1109+ const capture : PrivateKeyInfoCapture = { }
11101110 const errors : CustomError [ ] = [ ]
11111111 if ( ! asn1 . validate ( obj , digestInfoValidator , capture , errors ) ) {
11121112 const error : CustomError = new Error (
@@ -1150,7 +1150,7 @@ export function setRsaPublicKey(n: BigInteger, e: BigInteger): {
11501150 }
11511151 else if ( scheme === 'NONE' || scheme === 'NULL' || scheme === null ) {
11521152 scheme = {
1153- verify ( digest , d ) {
1153+ verify ( digest : string | Uint8Array , d : string ) {
11541154 // remove padding
11551155 d = _decodePkcs1_v1_5 ( d , key , true )
11561156 return digest === d
@@ -1192,7 +1192,7 @@ export function setRsaPublicKey(n: BigInteger, e: BigInteger): {
11921192
11931193 if ( scheme === 'RSAES-PKCS1-V1_5' ) {
11941194 scheme = {
1195- encode ( m , key , pub ) {
1195+ encode ( m : string , key : any , pub : any ) {
11961196 return _encodePkcs1_v1_5 ( m , key , 0x02 ) . getBytes ( )
11971197 } ,
11981198 }
@@ -1289,7 +1289,7 @@ export function setPrivateKey(
12891289 be removed. */
12901290
12911291 // private key operation
1292- let bt = false
1292+ let bt : number | null = null
12931293
12941294 if ( typeof scheme === 'string' )
12951295 scheme = scheme . toUpperCase ( )
@@ -1765,8 +1765,12 @@ function _generateKeyPair(state: {
17651765 qBits : number
17661766 bits : number
17671767 e : BigInteger
1768- p : BigInteger
1769- q : BigInteger
1768+ p : BigInteger | null
1769+ q : BigInteger | null
1770+ p1 : BigInteger | null
1771+ q1 : BigInteger | null
1772+ phi : BigInteger | null
1773+ n : BigInteger | null
17701774} , options : {
17711775 algorithm ?: string
17721776 workers ?: number
@@ -1824,29 +1828,29 @@ function _generateKeyPair(state: {
18241828 state . q = num
18251829
18261830 // ensure p is larger than q (swap them if not)
1827- if ( state . p . compareTo ( state . q ) < 0 ) {
1831+ if ( state . p ? .compareTo ( state . q || BigInteger . ZERO ) || 0 < 0 ) {
18281832 const tmp = state . p
18291833 state . p = state . q
18301834 state . q = tmp
18311835 }
18321836
18331837 // ensure p is coprime with e
1834- if ( state . p . subtract ( BigInteger . ONE ) . gcd ( state . e ) . compareTo ( BigInteger . ONE ) !== 0 ) {
1838+ if ( state . p ? .subtract ( BigInteger . ONE ) . gcd ( state . e ) . compareTo ( BigInteger . ONE ) !== 0 ) {
18351839 state . p = null
18361840 generate ( )
18371841 return
18381842 }
18391843
18401844 // ensure q is coprime with e
1841- if ( state . q . subtract ( BigInteger . ONE ) . gcd ( state . e ) . compareTo ( BigInteger . ONE ) !== 0 ) {
1845+ if ( state . q ? .subtract ( BigInteger . ONE ) . gcd ( state . e ) . compareTo ( BigInteger . ONE ) !== 0 ) {
18421846 state . q = null
18431847 getPrime ( state . qBits , finish )
18441848 return
18451849 }
18461850
18471851 // compute phi: (p - 1)(q - 1) (Euler's totient function)
1848- state . p1 = state . p . subtract ( BigInteger . ONE )
1849- state . q1 = state . q . subtract ( BigInteger . ONE )
1852+ state . p1 = state . p ? .subtract ( BigInteger . ONE )
1853+ state . q1 = state . q ? .subtract ( BigInteger . ONE )
18501854 state . phi = state . p1 . multiply ( state . q1 )
18511855
18521856 // ensure e and phi are coprime
0 commit comments