Skip to content

Commit dade46f

Browse files
committed
chore: wip
1 parent 4504c00 commit dade46f

4 files changed

Lines changed: 113 additions & 137 deletions

File tree

src/algorithms/asymmetric/rsa.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,7 @@ export function setRsaPublicKey(n: BigInteger, e: BigInteger): {
11621162
const d = decrypt(signature, key, true, false)
11631163

11641164
return scheme.verify(digest, d, key.n.bitLength())
1165-
}
1165+
},
11661166
}
11671167

11681168
/**
@@ -1282,7 +1282,7 @@ export function setPrivateKey(
12821282
*
12831283
* @return the signature as a byte string.
12841284
*/
1285-
sign: function (md: any, scheme: any) {
1285+
sign(md: any, scheme: any) {
12861286
/* Note: The internal implementation of RSA operations is being
12871287
transitioned away from a PKCS#1 v1.5 hard-coded scheme. Some legacy
12881288
code like the use of an encoding block identifier 'bt' will eventually
@@ -1310,24 +1310,24 @@ export function setPrivateKey(
13101310
},
13111311

13121312
/**
1313-
* Decrypts the given data with this private key. The decryption scheme
1314-
* must match the one used to encrypt the data.
1315-
*
1316-
* @param data the byte string to decrypt.
1317-
* @param scheme the decryption scheme to use:
1318-
* 'RSAES-PKCS1-V1_5' (default),
1319-
* 'RSA-OAEP',
1320-
* 'RAW', 'NONE', or null to perform raw RSA decryption.
1321-
* @param schemeOptions any scheme-specific options.
1322-
*
1323-
* @return the decrypted byte string.
1324-
*/
1325-
decrypt: function (data: string, scheme: string, schemeOptions: any) {
1313+
* Decrypts the given data with this private key. The decryption scheme
1314+
* must match the one used to encrypt the data.
1315+
*
1316+
* @param data the byte string to decrypt.
1317+
* @param scheme the decryption scheme to use:
1318+
* 'RSAES-PKCS1-V1_5' (default),
1319+
* 'RSA-OAEP',
1320+
* 'RAW', 'NONE', or null to perform raw RSA decryption.
1321+
* @param schemeOptions any scheme-specific options.
1322+
*
1323+
* @return the decrypted byte string.
1324+
*/
1325+
decrypt(data: string, scheme: string, schemeOptions: any) {
13261326
if (typeof scheme === 'string') {
13271327
scheme = scheme.toUpperCase()
13281328
}
13291329

1330-
else if (scheme === undefined) {
1330+
else if (scheme === undefined) {
13311331
scheme = 'RSAES-PKCS1-V1_5'
13321332
}
13331333

@@ -1353,7 +1353,7 @@ export function setPrivateKey(
13531353

13541354
// decode according to scheme
13551355
return scheme.decode(d, key, false)
1356-
}
1356+
},
13571357
}
13581358

13591359
return key
@@ -1478,7 +1478,7 @@ export function privateKeyToAsn1(key: {
14781478
])
14791479
}
14801480

1481-
type PublicKeyCapture = {
1481+
interface PublicKeyCapture {
14821482
publicKeyModulus?: string
14831483
publicKeyExponent?: Asn1Object
14841484
}
@@ -1498,7 +1498,7 @@ export function publicKeyFromAsn1(obj?: Asn1Object): RSAKey {
14981498
// get oid
14991499
const oid = asn1.derToOid(capture.publicKeyOid)
15001500
if (oid !== oids.rsaEncryption) {
1501-
var error = new Error('Cannot read public key. Unknown OID.')
1501+
const error = new Error('Cannot read public key. Unknown OID.')
15021502
error.oid = oid
15031503
throw error
15041504
}

src/pki.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { RSA } from './algorithms/asymmetric/rsa'
2-
import type { PemMessage } from './encoding/pem'
32
import { privateKeyFromAsn1, privateKeyToAsn1, rsa } from './algorithms/asymmetric/rsa'
43
/**
54
* TypeScript implementation of a basic Public Key Infrastructure, including
@@ -10,7 +9,7 @@ import { privateKeyFromAsn1, privateKeyToAsn1, rsa } from './algorithms/asymmetr
109
*/
1110
import { asn1 } from './encoding/asn1'
1211
import { pem } from './encoding/pem'
13-
import { certificateToAsn1, CRIAttributesAsArray, getCertificationRequestInfo } from './x509'
12+
import { certificateExtensionsToAsn1, certificateToAsn1, CRIAttributesAsArray, getCertificationRequestInfo } from './x509'
1413

1514
interface CustomError extends Error {
1615
headerType?: string
@@ -78,6 +77,7 @@ export function privateKeyInfoToPem(pki: any, maxline: number = 64): string {
7877
}
7978

8079
export interface Pki {
80+
certificateExtensionsToAsn1: typeof certificateExtensionsToAsn1
8181
certificateToAsn1: typeof certificateToAsn1
8282
CRIAttributesAsArray: typeof CRIAttributesAsArray
8383
getCertificationRequestInfo: typeof getCertificationRequestInfo
@@ -88,6 +88,7 @@ export interface Pki {
8888
}
8989

9090
export const pki: Pki = {
91+
certificateExtensionsToAsn1,
9192
certificateToAsn1,
9293
getCertificationRequestInfo,
9394
CRIAttributesAsArray,

src/utils/index.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,31 +1171,32 @@ export function bytesToIPv6(bytes: string): string | null {
11711171
const idx = ip.length
11721172
if (!last || idx !== last.end + 1) {
11731173
zeroGroups.push({ start: idx, end: idx })
1174-
} else {
1174+
}
1175+
else {
11751176
last.end = idx
1176-
if ((last.end - last.start) >
1177-
(zeroGroups[zeroMaxGroup].end - zeroGroups[zeroMaxGroup].start)) {
1177+
if ((last.end - last.start)
1178+
> (zeroGroups[zeroMaxGroup].end - zeroGroups[zeroMaxGroup].start)) {
11781179
zeroMaxGroup = zeroGroups.length - 1
11791180
}
11801181
}
11811182
}
1182-
ip.push(hex);
1183+
ip.push(hex)
11831184
}
11841185
if (zeroGroups.length > 0) {
11851186
const group = zeroGroups[zeroMaxGroup]
11861187
// only shorten group of length > 0
11871188
if (group.end - group.start > 0) {
11881189
ip.splice(group.start, group.end - group.start + 1, '')
11891190
if (group.start === 0) {
1190-
ip.unshift('');
1191+
ip.unshift('')
11911192
}
11921193
if (group.end === 7) {
1193-
ip.push('');
1194+
ip.push('')
11941195
}
11951196
}
11961197
}
11971198

1198-
return ip.join(':');
1199+
return ip.join(':')
11991200
};
12001201

12011202
export interface Util {

0 commit comments

Comments
 (0)