Skip to content

Commit d729d00

Browse files
committed
chore: wip
1 parent 1d56581 commit d729d00

2 files changed

Lines changed: 43 additions & 26 deletions

File tree

src/asn1-validator.ts

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,84 +2,101 @@
22
* Copyright (c) 2019 Digital Bazaar, Inc.
33
*/
44

5-
import { asn1 } from './asn1'
5+
import { Class, Type } from './asn1'
66

77
export interface Asn1Validator {
88
name: string
9-
tagClass: asn1.Class
10-
type: asn1.Type
9+
tagClass: number
10+
type: number
1111
constructed: boolean
1212
value: Asn1Validator[]
13+
capture?: string
14+
captureAsn1?: string
15+
captureBitStringContents?: string
16+
captureBitStringValue?: string
17+
optional?: boolean
18+
composed?: boolean
19+
}
20+
21+
export interface ValidatorMap {
22+
privateKeyValidator: Asn1Validator
23+
publicKeyValidator: Asn1Validator
1324
}
1425

1526
export const privateKeyValidator: Asn1Validator = {
1627
// PrivateKeyInfo
1728
name: 'PrivateKeyInfo',
18-
tagClass: asn1.Class.UNIVERSAL,
19-
type: asn1.Type.SEQUENCE,
29+
tagClass: Class.UNIVERSAL,
30+
type: Type.SEQUENCE,
2031
constructed: true,
2132
value: [{
2233
// Version (INTEGER)
2334
name: 'PrivateKeyInfo.version',
24-
tagClass: asn1.Class.UNIVERSAL,
25-
type: asn1.Type.INTEGER,
35+
tagClass: Class.UNIVERSAL,
36+
type: Type.INTEGER,
2637
constructed: false,
2738
capture: 'privateKeyVersion',
39+
value: []
2840
}, {
2941
// privateKeyAlgorithm
3042
name: 'PrivateKeyInfo.privateKeyAlgorithm',
31-
tagClass: asn1.Class.UNIVERSAL,
32-
type: asn1.Type.SEQUENCE,
43+
tagClass: Class.UNIVERSAL,
44+
type: Type.SEQUENCE,
3345
constructed: true,
3446
value: [{
3547
name: 'AlgorithmIdentifier.algorithm',
36-
tagClass: asn1.Class.UNIVERSAL,
37-
type: asn1.Type.OID,
48+
tagClass: Class.UNIVERSAL,
49+
type: Type.OID,
3850
constructed: false,
3951
capture: 'privateKeyOid',
52+
value: []
4053
}],
4154
}, {
4255
// PrivateKey
4356
name: 'PrivateKeyInfo',
44-
tagClass: asn1.Class.UNIVERSAL,
45-
type: asn1.Type.OCTETSTRING,
57+
tagClass: Class.UNIVERSAL,
58+
type: Type.OCTETSTRING,
4659
constructed: false,
4760
capture: 'privateKey',
61+
value: []
4862
}],
4963
}
5064

5165
export const publicKeyValidator: Asn1Validator = {
5266
name: 'SubjectPublicKeyInfo',
53-
tagClass: asn1.Class.UNIVERSAL,
54-
type: asn1.Type.SEQUENCE,
67+
tagClass: Class.UNIVERSAL,
68+
type: Type.SEQUENCE,
5569
constructed: true,
5670
captureAsn1: 'subjectPublicKeyInfo',
5771
value: [{
5872
name: 'SubjectPublicKeyInfo.AlgorithmIdentifier',
59-
tagClass: asn1.Class.UNIVERSAL,
60-
type: asn1.Type.SEQUENCE,
73+
tagClass: Class.UNIVERSAL,
74+
type: Type.SEQUENCE,
6175
constructed: true,
6276
value: [{
6377
name: 'AlgorithmIdentifier.algorithm',
64-
tagClass: asn1.Class.UNIVERSAL,
65-
type: asn1.Type.OID,
78+
tagClass: Class.UNIVERSAL,
79+
type: Type.OID,
6680
constructed: false,
6781
capture: 'publicKeyOid',
82+
value: []
6883
}],
6984
},
7085
// capture group for ed25519PublicKey
7186
{
72-
tagClass: asn1.Class.UNIVERSAL,
73-
type: asn1.Type.BITSTRING,
87+
name: 'SubjectPublicKeyInfo.subjectPublicKey',
88+
tagClass: Class.UNIVERSAL,
89+
type: Type.BITSTRING,
7490
constructed: false,
7591
composed: true,
7692
captureBitStringValue: 'ed25519PublicKey',
77-
}, // FIXME: this is capture group for rsaPublicKey, use it in this API or // discard? /* { // subjectPublicKey name: 'SubjectPublicKeyInfo.subjectPublicKey', tagClass: asn1.Class.UNIVERSAL, type: asn1.Type.BITSTRING, constructed: false, value: [{ // RSAPublicKey name: 'SubjectPublicKeyInfo.subjectPublicKey.RSAPublicKey', tagClass: asn1.Class.UNIVERSAL, type: asn1.Type.SEQUENCE, constructed: true, optional: true, captureAsn1: 'rsaPublicKey' }] } */
78-
]}
93+
value: []
94+
}]
95+
}
7996

80-
const asn1Validator: Asn1Validator = {
97+
const validator: ValidatorMap = {
8198
privateKeyValidator,
8299
publicKeyValidator,
83100
}
84101

85-
export default asn1Validator
102+
export default validator

src/asn1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1515,6 +1515,6 @@ export const asn1: Asn1 = {
15151515
validate,
15161516
prettyPrint,
15171517
toDer
1518-
}
1518+
} as const
15191519

15201520
export default asn1

0 commit comments

Comments
 (0)