• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PeculiarVentures / x509 / 15564777427

10 Jun 2025 04:16PM UTC coverage: 90.282% (+1.9%) from 88.355%
15564777427

push

github

microshine
chore(deps): deduplicate dependencies

726 of 843 branches covered (86.12%)

Branch coverage included in aggregate %.

2795 of 3057 relevant lines covered (91.43%)

55.14 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.72
/src/ec_algorithm.ts
1
import { AlgorithmIdentifier } from "@peculiar/asn1-x509";
2✔
2
import * as asn1Ecc from "@peculiar/asn1-ecc";
2✔
3
import { container, injectable } from "tsyringe";
2✔
4
import { diAlgorithm, IAlgorithm } from "./algorithm";
2✔
5
import { HashedAlgorithm } from "./types";
6
import { AsnConvert } from "@peculiar/asn1-schema";
2✔
7

8
const idVersionOne = "1.3.36.3.3.2.8.1.1";
2✔
9
/**
10
 * ```
11
 * brainpoolP160r1 OBJECT IDENTIFIER ::= { versionOne 1 }
12
 * ```
13
 */
14
const idBrainpoolP160r1 = `${idVersionOne}.1`;
2✔
15
/**
16
 * ```
17
 * brainpoolP160t1 OBJECT IDENTIFIER ::= { versionOne 2 }
18
 * ```
19
 */
20
const idBrainpoolP160t1 = `${idVersionOne}.2`;
2✔
21
/**
22
 * ```
23
 * brainpoolP192r1 OBJECT IDENTIFIER ::= { versionOne 3 }
24
 * ```
25
 */
26
const idBrainpoolP192r1 = `${idVersionOne}.3`;
2✔
27
/**
28
 * ```
29
 * brainpoolP192t1 OBJECT IDENTIFIER ::= { versionOne 4 }
30
 * ```
31
 */
32
const idBrainpoolP192t1 = `${idVersionOne}.4`;
2✔
33
/**
34
 * ```
35
 * brainpoolP224r1 OBJECT IDENTIFIER ::= { versionOne 5 }
36
 * ```
37
 */
38
const idBrainpoolP224r1 = `${idVersionOne}.5`;
2✔
39
/**
40
 * ```
41
 * brainpoolP224t1 OBJECT IDENTIFIER ::= { versionOne 6 }
42
 * ```
43
 */
44
const idBrainpoolP224t1 = `${idVersionOne}.6`;
2✔
45
/**
46
 * ```
47
 * brainpoolP256r1 OBJECT IDENTIFIER ::= { versionOne 7 }
48
 * ```
49
 */
50
const idBrainpoolP256r1 = `${idVersionOne}.7`;
2✔
51
/**
52
 * ```
53
 * brainpoolP256t1 OBJECT IDENTIFIER ::= { versionOne 8 }
54
 * ```
55
 */
56
const idBrainpoolP256t1 = `${idVersionOne}.8`;
2✔
57
/**
58
 * ```
59
 * brainpoolP320r1 OBJECT IDENTIFIER ::= { versionOne 9 }
60
 * ```
61
 */
62
const idBrainpoolP320r1 = `${idVersionOne}.9`;
2✔
63
/**
64
 * ```
65
 * brainpoolP320t1 OBJECT IDENTIFIER ::= { versionOne 10 }
66
 * ```
67
 */
68
const idBrainpoolP320t1 = `${idVersionOne}.10`;
2✔
69
/**
70
 * ```
71
 * brainpoolP384r1 OBJECT IDENTIFIER ::= { versionOne 11 }
72
 * ```
73
 */
74
const idBrainpoolP384r1 = `${idVersionOne}.11`;
2✔
75
/**
76
 * ```
77
 * brainpoolP384t1 OBJECT IDENTIFIER ::= { versionOne 12 }
78
 * ```
79
 */
80
const idBrainpoolP384t1 = `${idVersionOne}.12`;
2✔
81
/**
82
 * ```
83
 * brainpoolP512r1 OBJECT IDENTIFIER ::= { versionOne 13 }
84
 * ```
85
 */
86
const idBrainpoolP512r1 = `${idVersionOne}.13`;
2✔
87
/**
88
 * ```
89
 * brainpoolP512t1 OBJECT IDENTIFIER ::= { versionOne 14 }
90
 * ```
91
 */
92
const idBrainpoolP512t1 = `${idVersionOne}.14`;
2✔
93

94
const brainpoolP160r1 = "brainpoolP160r1";
2✔
95
const brainpoolP160t1 = "brainpoolP160t1";
2✔
96
const brainpoolP192r1 = "brainpoolP192r1";
2✔
97
const brainpoolP192t1 = "brainpoolP192t1";
2✔
98
const brainpoolP224r1 = "brainpoolP224r1";
2✔
99
const brainpoolP224t1 = "brainpoolP224t1";
2✔
100
const brainpoolP256r1 = "brainpoolP256r1";
2✔
101
const brainpoolP256t1 = "brainpoolP256t1";
2✔
102
const brainpoolP320r1 = "brainpoolP320r1";
2✔
103
const brainpoolP320t1 = "brainpoolP320t1";
2✔
104
const brainpoolP384r1 = "brainpoolP384r1";
2✔
105
const brainpoolP384t1 = "brainpoolP384t1";
2✔
106
const brainpoolP512r1 = "brainpoolP512r1";
2✔
107
const brainpoolP512t1 = "brainpoolP512t1";
2✔
108

109
const ECDSA = "ECDSA";
2✔
110
/**
111
 * EC algorithm provider
112
 */
113
@injectable()
2✔
114
export class EcAlgorithm implements IAlgorithm {
2✔
115

116
  public static SECP256K1 = "1.3.132.0.10";
2✔
117

118
  public toAsnAlgorithm(alg: HashedAlgorithm | EcKeyGenParams): AlgorithmIdentifier | null {
2✔
119
    switch (alg.name.toLowerCase()) {
152✔
120
      case ECDSA.toLowerCase():
152✔
121
        if ("hash" in alg) {
98✔
122
          const hash = typeof alg.hash === "string" ? alg.hash : alg.hash.name;
62✔
123
          switch (hash.toLowerCase()) {
62✔
124
            case "sha-1":
62✔
125
              return asn1Ecc.ecdsaWithSHA1;
4✔
126
            case "sha-256":
62✔
127
              return asn1Ecc.ecdsaWithSHA256;
52✔
128
            case "sha-384":
62✔
129
              return asn1Ecc.ecdsaWithSHA384;
4✔
130
            case "sha-512":
62✔
131
              return asn1Ecc.ecdsaWithSHA512;
2✔
132
          }
62✔
133
        } else if ("namedCurve" in alg) {
98✔
134
          let parameters = "";
36✔
135
          switch (alg.namedCurve) {
36✔
136
            case "P-256":
36✔
137
              parameters = asn1Ecc.id_secp256r1;
2✔
138
              break;
2✔
139
            case "K-256":
36✔
140
              parameters = EcAlgorithm.SECP256K1;
2✔
141
              break;
2✔
142
            case "P-384":
36✔
143
              parameters = asn1Ecc.id_secp384r1;
2✔
144
              break;
2✔
145
            case "P-521":
36✔
146
              parameters = asn1Ecc.id_secp521r1;
2✔
147
              break;
2✔
148
            case brainpoolP160r1:
36✔
149
              parameters = idBrainpoolP160r1;
2✔
150
              break;
2✔
151
            case brainpoolP160t1:
36✔
152
              parameters = idBrainpoolP160t1;
2✔
153
              break;
2✔
154
            case brainpoolP192r1:
36✔
155
              parameters = idBrainpoolP192r1;
2✔
156
              break;
2✔
157
            case brainpoolP192t1:
36✔
158
              parameters = idBrainpoolP192t1;
2✔
159
              break;
2✔
160
            case brainpoolP224r1:
36✔
161
              parameters = idBrainpoolP224r1;
2✔
162
              break;
2✔
163
            case brainpoolP224t1:
36✔
164
              parameters = idBrainpoolP224t1;
2✔
165
              break;
2✔
166
            case brainpoolP256r1:
36✔
167
              parameters = idBrainpoolP256r1;
2✔
168
              break;
2✔
169
            case brainpoolP256t1:
36✔
170
              parameters = idBrainpoolP256t1;
2✔
171
              break;
2✔
172
            case brainpoolP320r1:
36✔
173
              parameters = idBrainpoolP320r1;
2✔
174
              break;
2✔
175
            case brainpoolP320t1:
36✔
176
              parameters = idBrainpoolP320t1;
2✔
177
              break;
2✔
178
            case brainpoolP384r1:
36✔
179
              parameters = idBrainpoolP384r1;
2✔
180
              break;
2✔
181
            case brainpoolP384t1:
36✔
182
              parameters = idBrainpoolP384t1;
2✔
183
              break;
2✔
184
            case brainpoolP512r1:
36✔
185
              parameters = idBrainpoolP512r1;
2✔
186
              break;
2✔
187
            case brainpoolP512t1:
36✔
188
              parameters = idBrainpoolP512t1;
2✔
189
              break;
2✔
190
          }
36✔
191
          if (parameters) {
36✔
192
            return new AlgorithmIdentifier({
36✔
193
              algorithm: asn1Ecc.id_ecPublicKey,
36✔
194
              parameters: AsnConvert.serialize(new asn1Ecc.ECParameters({ namedCurve: parameters })),
36✔
195
            });
36✔
196
          }
36✔
197
        }
36✔
198
    }
152✔
199

200
    return null;
54✔
201
  }
152✔
202

203
  public toWebAlgorithm(alg: AlgorithmIdentifier): HashedAlgorithm | EcKeyGenParams | null {
2✔
204
    switch (alg.algorithm) {
546✔
205
      case asn1Ecc.id_ecdsaWithSHA1:
546✔
206
        return { name: ECDSA, hash: { name: "SHA-1" } };
4✔
207
      case asn1Ecc.id_ecdsaWithSHA256:
546✔
208
        return { name: ECDSA, hash: { name: "SHA-256" } };
92✔
209
      case asn1Ecc.id_ecdsaWithSHA384:
546✔
210
        return { name: ECDSA, hash: { name: "SHA-384" } };
4✔
211
      case asn1Ecc.id_ecdsaWithSHA512:
546✔
212
        return { name: ECDSA, hash: { name: "SHA-512" } };
2✔
213
      case asn1Ecc.id_ecPublicKey: {
546✔
214
        if (!alg.parameters) {
168!
215
          throw new TypeError("Cannot get required parameters from EC algorithm");
×
216
        }
×
217
        const parameters = AsnConvert.parse(alg.parameters, asn1Ecc.ECParameters);
168✔
218
        switch (parameters.namedCurve) {
168✔
219
          case asn1Ecc.id_secp256r1:
168✔
220
            return { name: ECDSA, namedCurve: "P-256" };
120✔
221
          case EcAlgorithm.SECP256K1:
168✔
222
            return { name: ECDSA, namedCurve: "K-256" };
4✔
223
          case asn1Ecc.id_secp384r1:
168✔
224
            return { name: ECDSA, namedCurve: "P-384" };
8✔
225
          case asn1Ecc.id_secp521r1:
168✔
226
            return { name: ECDSA, namedCurve: "P-521" };
2✔
227
          case idBrainpoolP160r1:
168✔
228
            return { name: ECDSA, namedCurve: brainpoolP160r1 };
2✔
229
          case idBrainpoolP160t1:
168✔
230
            return { name: ECDSA, namedCurve: brainpoolP160t1 };
2✔
231
          case idBrainpoolP192r1:
168✔
232
            return { name: ECDSA, namedCurve: brainpoolP192r1 };
2✔
233
          case idBrainpoolP192t1:
168✔
234
            return { name: ECDSA, namedCurve: brainpoolP192t1 };
2✔
235
          case idBrainpoolP224r1:
168✔
236
            return { name: ECDSA, namedCurve: brainpoolP224r1 };
2✔
237
          case idBrainpoolP224t1:
168✔
238
            return { name: ECDSA, namedCurve: brainpoolP224t1 };
2✔
239
          case idBrainpoolP256r1:
168✔
240
            return { name: ECDSA, namedCurve: brainpoolP256r1 };
6✔
241
          case idBrainpoolP256t1:
168✔
242
            return { name: ECDSA, namedCurve: brainpoolP256t1 };
2✔
243
          case idBrainpoolP320r1:
168✔
244
            return { name: ECDSA, namedCurve: brainpoolP320r1 };
2✔
245
          case idBrainpoolP320t1:
168✔
246
            return { name: ECDSA, namedCurve: brainpoolP320t1 };
2✔
247
          case idBrainpoolP384r1:
168✔
248
            return { name: ECDSA, namedCurve: brainpoolP384r1 };
2✔
249
          case idBrainpoolP384t1:
168✔
250
            return { name: ECDSA, namedCurve: brainpoolP384t1 };
2✔
251
          case idBrainpoolP512r1:
168✔
252
            return { name: ECDSA, namedCurve: brainpoolP512r1 };
2✔
253
          case idBrainpoolP512t1:
168✔
254
            return { name: ECDSA, namedCurve: brainpoolP512t1 };
2✔
255
        }
168✔
256
      }
168✔
257
    }
546✔
258

259
    return null;
278✔
260
  }
546✔
261

262
}
2✔
263

264
// register EC algorithm provider as a singleton object
265
container.registerSingleton(diAlgorithm, EcAlgorithm);
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc