|
1 | 1 | // from https://github.com/indutny/self-signed/blob/gh-pages/lib/asn1.js |
2 | 2 | // Fedor, you are amazing. |
3 | | -'use strict' |
4 | 3 |
|
5 | | -var asn1 = require('asn1.js') |
| 4 | +'use strict'; |
6 | 5 |
|
7 | | -exports.certificate = require('./certificate') |
| 6 | +var asn1 = require('asn1.js'); |
| 7 | + |
| 8 | +exports.certificate = require('./certificate'); |
8 | 9 |
|
9 | 10 | var RSAPrivateKey = asn1.define('RSAPrivateKey', function () { |
10 | | - this.seq().obj( |
11 | | - this.key('version').int(), |
12 | | - this.key('modulus').int(), |
13 | | - this.key('publicExponent').int(), |
14 | | - this.key('privateExponent').int(), |
15 | | - this.key('prime1').int(), |
16 | | - this.key('prime2').int(), |
17 | | - this.key('exponent1').int(), |
18 | | - this.key('exponent2').int(), |
19 | | - this.key('coefficient').int() |
20 | | - ) |
21 | | -}) |
22 | | -exports.RSAPrivateKey = RSAPrivateKey |
| 11 | + this.seq().obj( |
| 12 | + this.key('version')['int'](), |
| 13 | + this.key('modulus')['int'](), |
| 14 | + this.key('publicExponent')['int'](), |
| 15 | + this.key('privateExponent')['int'](), |
| 16 | + this.key('prime1')['int'](), |
| 17 | + this.key('prime2')['int'](), |
| 18 | + this.key('exponent1')['int'](), |
| 19 | + this.key('exponent2')['int'](), |
| 20 | + this.key('coefficient')['int']() |
| 21 | + ); |
| 22 | +}); |
| 23 | +exports.RSAPrivateKey = RSAPrivateKey; |
23 | 24 |
|
24 | 25 | var RSAPublicKey = asn1.define('RSAPublicKey', function () { |
25 | | - this.seq().obj( |
26 | | - this.key('modulus').int(), |
27 | | - this.key('publicExponent').int() |
28 | | - ) |
29 | | -}) |
30 | | -exports.RSAPublicKey = RSAPublicKey |
31 | | - |
32 | | -var PublicKey = asn1.define('SubjectPublicKeyInfo', function () { |
33 | | - this.seq().obj( |
34 | | - this.key('algorithm').use(AlgorithmIdentifier), |
35 | | - this.key('subjectPublicKey').bitstr() |
36 | | - ) |
37 | | -}) |
38 | | -exports.PublicKey = PublicKey |
| 26 | + this.seq().obj( |
| 27 | + this.key('modulus')['int'](), |
| 28 | + this.key('publicExponent')['int']() |
| 29 | + ); |
| 30 | +}); |
| 31 | +exports.RSAPublicKey = RSAPublicKey; |
39 | 32 |
|
40 | 33 | var AlgorithmIdentifier = asn1.define('AlgorithmIdentifier', function () { |
41 | | - this.seq().obj( |
42 | | - this.key('algorithm').objid(), |
43 | | - this.key('none').null_().optional(), |
44 | | - this.key('curve').objid().optional(), |
45 | | - this.key('params').seq().obj( |
46 | | - this.key('p').int(), |
47 | | - this.key('q').int(), |
48 | | - this.key('g').int() |
49 | | - ).optional() |
50 | | - ) |
51 | | -}) |
| 34 | + this.seq().obj( |
| 35 | + this.key('algorithm').objid(), |
| 36 | + this.key('none').null_().optional(), |
| 37 | + this.key('curve').objid().optional(), |
| 38 | + this.key('params').seq().obj( |
| 39 | + this.key('p')['int'](), |
| 40 | + this.key('q')['int'](), |
| 41 | + this.key('g')['int']() |
| 42 | + ).optional() |
| 43 | + ); |
| 44 | +}); |
| 45 | + |
| 46 | +var PublicKey = asn1.define('SubjectPublicKeyInfo', function () { |
| 47 | + this.seq().obj( |
| 48 | + this.key('algorithm').use(AlgorithmIdentifier), |
| 49 | + this.key('subjectPublicKey').bitstr() |
| 50 | + ); |
| 51 | +}); |
| 52 | +exports.PublicKey = PublicKey; |
52 | 53 |
|
53 | 54 | var PrivateKeyInfo = asn1.define('PrivateKeyInfo', function () { |
54 | | - this.seq().obj( |
55 | | - this.key('version').int(), |
56 | | - this.key('algorithm').use(AlgorithmIdentifier), |
57 | | - this.key('subjectPrivateKey').octstr() |
58 | | - ) |
59 | | -}) |
60 | | -exports.PrivateKey = PrivateKeyInfo |
| 55 | + this.seq().obj( |
| 56 | + this.key('version')['int'](), |
| 57 | + this.key('algorithm').use(AlgorithmIdentifier), |
| 58 | + this.key('subjectPrivateKey').octstr() |
| 59 | + ); |
| 60 | +}); |
| 61 | +exports.PrivateKey = PrivateKeyInfo; |
61 | 62 | var EncryptedPrivateKeyInfo = asn1.define('EncryptedPrivateKeyInfo', function () { |
62 | | - this.seq().obj( |
63 | | - this.key('algorithm').seq().obj( |
64 | | - this.key('id').objid(), |
65 | | - this.key('decrypt').seq().obj( |
66 | | - this.key('kde').seq().obj( |
67 | | - this.key('id').objid(), |
68 | | - this.key('kdeparams').seq().obj( |
69 | | - this.key('salt').octstr(), |
70 | | - this.key('iters').int() |
71 | | - ) |
72 | | - ), |
73 | | - this.key('cipher').seq().obj( |
74 | | - this.key('algo').objid(), |
75 | | - this.key('iv').octstr() |
76 | | - ) |
77 | | - ) |
78 | | - ), |
79 | | - this.key('subjectPrivateKey').octstr() |
80 | | - ) |
81 | | -}) |
| 63 | + this.seq().obj( |
| 64 | + this.key('algorithm').seq().obj( |
| 65 | + this.key('id').objid(), |
| 66 | + this.key('decrypt').seq().obj( |
| 67 | + this.key('kde').seq().obj( |
| 68 | + this.key('id').objid(), |
| 69 | + this.key('kdeparams').seq().obj( |
| 70 | + this.key('salt').octstr(), |
| 71 | + this.key('iters')['int']() |
| 72 | + ) |
| 73 | + ), |
| 74 | + this.key('cipher').seq().obj( |
| 75 | + this.key('algo').objid(), |
| 76 | + this.key('iv').octstr() |
| 77 | + ) |
| 78 | + ) |
| 79 | + ), |
| 80 | + this.key('subjectPrivateKey').octstr() |
| 81 | + ); |
| 82 | +}); |
82 | 83 |
|
83 | | -exports.EncryptedPrivateKey = EncryptedPrivateKeyInfo |
| 84 | +exports.EncryptedPrivateKey = EncryptedPrivateKeyInfo; |
84 | 85 |
|
85 | 86 | var DSAPrivateKey = asn1.define('DSAPrivateKey', function () { |
86 | | - this.seq().obj( |
87 | | - this.key('version').int(), |
88 | | - this.key('p').int(), |
89 | | - this.key('q').int(), |
90 | | - this.key('g').int(), |
91 | | - this.key('pub_key').int(), |
92 | | - this.key('priv_key').int() |
93 | | - ) |
94 | | -}) |
95 | | -exports.DSAPrivateKey = DSAPrivateKey |
| 87 | + this.seq().obj( |
| 88 | + this.key('version')['int'](), |
| 89 | + this.key('p')['int'](), |
| 90 | + this.key('q')['int'](), |
| 91 | + this.key('g')['int'](), |
| 92 | + this.key('pub_key')['int'](), |
| 93 | + this.key('priv_key')['int']() |
| 94 | + ); |
| 95 | +}); |
| 96 | +exports.DSAPrivateKey = DSAPrivateKey; |
96 | 97 |
|
97 | 98 | exports.DSAparam = asn1.define('DSAparam', function () { |
98 | | - this.int() |
99 | | -}) |
100 | | - |
101 | | -var ECPrivateKey = asn1.define('ECPrivateKey', function () { |
102 | | - this.seq().obj( |
103 | | - this.key('version').int(), |
104 | | - this.key('privateKey').octstr(), |
105 | | - this.key('parameters').optional().explicit(0).use(ECParameters), |
106 | | - this.key('publicKey').optional().explicit(1).bitstr() |
107 | | - ) |
108 | | -}) |
109 | | -exports.ECPrivateKey = ECPrivateKey |
| 99 | + this['int'](); |
| 100 | +}); |
110 | 101 |
|
111 | 102 | var ECParameters = asn1.define('ECParameters', function () { |
112 | | - this.choice({ |
113 | | - namedCurve: this.objid() |
114 | | - }) |
115 | | -}) |
| 103 | + this.choice({ |
| 104 | + namedCurve: this.objid() |
| 105 | + }); |
| 106 | +}); |
| 107 | + |
| 108 | +var ECPrivateKey = asn1.define('ECPrivateKey', function () { |
| 109 | + this.seq().obj( |
| 110 | + this.key('version')['int'](), |
| 111 | + this.key('privateKey').octstr(), |
| 112 | + this.key('parameters').optional().explicit(0).use(ECParameters), |
| 113 | + this.key('publicKey').optional().explicit(1).bitstr() |
| 114 | + ); |
| 115 | +}); |
| 116 | +exports.ECPrivateKey = ECPrivateKey; |
116 | 117 |
|
117 | 118 | exports.signature = asn1.define('signature', function () { |
118 | | - this.seq().obj( |
119 | | - this.key('r').int(), |
120 | | - this.key('s').int() |
121 | | - ) |
122 | | -}) |
| 119 | + this.seq().obj( |
| 120 | + this.key('r')['int'](), |
| 121 | + this.key('s')['int']() |
| 122 | + ); |
| 123 | +}); |
0 commit comments