|
2 | 2 | * Copyright (c) 2019 Digital Bazaar, Inc. |
3 | 3 | */ |
4 | 4 |
|
5 | | -import { asn1 } from './asn1' |
| 5 | +import { Class, Type } from './asn1' |
6 | 6 |
|
7 | 7 | export interface Asn1Validator { |
8 | 8 | name: string |
9 | | - tagClass: asn1.Class |
10 | | - type: asn1.Type |
| 9 | + tagClass: number |
| 10 | + type: number |
11 | 11 | constructed: boolean |
12 | 12 | 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 |
13 | 24 | } |
14 | 25 |
|
15 | 26 | export const privateKeyValidator: Asn1Validator = { |
16 | 27 | // PrivateKeyInfo |
17 | 28 | name: 'PrivateKeyInfo', |
18 | | - tagClass: asn1.Class.UNIVERSAL, |
19 | | - type: asn1.Type.SEQUENCE, |
| 29 | + tagClass: Class.UNIVERSAL, |
| 30 | + type: Type.SEQUENCE, |
20 | 31 | constructed: true, |
21 | 32 | value: [{ |
22 | 33 | // Version (INTEGER) |
23 | 34 | name: 'PrivateKeyInfo.version', |
24 | | - tagClass: asn1.Class.UNIVERSAL, |
25 | | - type: asn1.Type.INTEGER, |
| 35 | + tagClass: Class.UNIVERSAL, |
| 36 | + type: Type.INTEGER, |
26 | 37 | constructed: false, |
27 | 38 | capture: 'privateKeyVersion', |
| 39 | + value: [] |
28 | 40 | }, { |
29 | 41 | // privateKeyAlgorithm |
30 | 42 | name: 'PrivateKeyInfo.privateKeyAlgorithm', |
31 | | - tagClass: asn1.Class.UNIVERSAL, |
32 | | - type: asn1.Type.SEQUENCE, |
| 43 | + tagClass: Class.UNIVERSAL, |
| 44 | + type: Type.SEQUENCE, |
33 | 45 | constructed: true, |
34 | 46 | value: [{ |
35 | 47 | name: 'AlgorithmIdentifier.algorithm', |
36 | | - tagClass: asn1.Class.UNIVERSAL, |
37 | | - type: asn1.Type.OID, |
| 48 | + tagClass: Class.UNIVERSAL, |
| 49 | + type: Type.OID, |
38 | 50 | constructed: false, |
39 | 51 | capture: 'privateKeyOid', |
| 52 | + value: [] |
40 | 53 | }], |
41 | 54 | }, { |
42 | 55 | // PrivateKey |
43 | 56 | name: 'PrivateKeyInfo', |
44 | | - tagClass: asn1.Class.UNIVERSAL, |
45 | | - type: asn1.Type.OCTETSTRING, |
| 57 | + tagClass: Class.UNIVERSAL, |
| 58 | + type: Type.OCTETSTRING, |
46 | 59 | constructed: false, |
47 | 60 | capture: 'privateKey', |
| 61 | + value: [] |
48 | 62 | }], |
49 | 63 | } |
50 | 64 |
|
51 | 65 | export const publicKeyValidator: Asn1Validator = { |
52 | 66 | name: 'SubjectPublicKeyInfo', |
53 | | - tagClass: asn1.Class.UNIVERSAL, |
54 | | - type: asn1.Type.SEQUENCE, |
| 67 | + tagClass: Class.UNIVERSAL, |
| 68 | + type: Type.SEQUENCE, |
55 | 69 | constructed: true, |
56 | 70 | captureAsn1: 'subjectPublicKeyInfo', |
57 | 71 | value: [{ |
58 | 72 | name: 'SubjectPublicKeyInfo.AlgorithmIdentifier', |
59 | | - tagClass: asn1.Class.UNIVERSAL, |
60 | | - type: asn1.Type.SEQUENCE, |
| 73 | + tagClass: Class.UNIVERSAL, |
| 74 | + type: Type.SEQUENCE, |
61 | 75 | constructed: true, |
62 | 76 | value: [{ |
63 | 77 | name: 'AlgorithmIdentifier.algorithm', |
64 | | - tagClass: asn1.Class.UNIVERSAL, |
65 | | - type: asn1.Type.OID, |
| 78 | + tagClass: Class.UNIVERSAL, |
| 79 | + type: Type.OID, |
66 | 80 | constructed: false, |
67 | 81 | capture: 'publicKeyOid', |
| 82 | + value: [] |
68 | 83 | }], |
69 | 84 | }, |
70 | 85 | // capture group for ed25519PublicKey |
71 | 86 | { |
72 | | - tagClass: asn1.Class.UNIVERSAL, |
73 | | - type: asn1.Type.BITSTRING, |
| 87 | + name: 'SubjectPublicKeyInfo.subjectPublicKey', |
| 88 | + tagClass: Class.UNIVERSAL, |
| 89 | + type: Type.BITSTRING, |
74 | 90 | constructed: false, |
75 | 91 | composed: true, |
76 | 92 | 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 | +} |
79 | 96 |
|
80 | | -const asn1Validator: Asn1Validator = { |
| 97 | +const validator: ValidatorMap = { |
81 | 98 | privateKeyValidator, |
82 | 99 | publicKeyValidator, |
83 | 100 | } |
84 | 101 |
|
85 | | -export default asn1Validator |
| 102 | +export default validator |
0 commit comments