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

PeculiarVentures / x509 / 18688905299

21 Oct 2025 03:22PM UTC coverage: 89.87% (+0.07%) from 89.797%
18688905299

push

github

web-flow
Merge pull request #111 from PeculiarVentures/donskov/eslint-migration

Update ESLint configuration and dependencies

901 of 1050 branches covered (85.81%)

Branch coverage included in aggregate %.

438 of 483 new or added lines in 36 files covered. (90.68%)

4 existing lines in 3 files now uncovered.

3242 of 3560 relevant lines covered (91.07%)

44.01 hits per line

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

86.21
/src/algorithm.ts
1
import { AlgorithmIdentifier } from "@peculiar/asn1-x509";
2✔
2
import { container } from "tsyringe";
2✔
3

4
export interface UnknownAlgorithm extends Algorithm {
5
  name: string;
6
  parameters?: ArrayBuffer | null;
7
}
8

9
export interface IAlgorithm {
10

11
  /**
12
   * Converts WebCrypto algorithm to ASN.1 algorithm
13
   * @param alg WebCrypto algorithm
14
   * @returns ASN.1 algorithm or null
15
   */
16
  toAsnAlgorithm(alg: Algorithm): AlgorithmIdentifier | null;
17

18
  /**
19
   * Converts ASN.1 algorithm to WebCrypto algorithm
20
   * @param alg ASN.1 algorithm
21
   * @returns WebCrypto algorithm or null
22
   */
23
  toWebAlgorithm(alg: AlgorithmIdentifier): Algorithm | null;
24

25
}
26

27
/**
28
 * Dependency Injection algorithm identifier
29
 */
30
export const diAlgorithm = "crypto.algorithm";
2✔
31

32
export class AlgorithmProvider {
2✔
33
  /**
34
   * Returns all registered algorithm providers
35
   */
36
  public getAlgorithms() {
2✔
37
    return container.resolveAll<IAlgorithm>(diAlgorithm);
374✔
38
  }
374✔
39

40
  /**
41
   * Converts WebCrypto algorithm to ASN.1 algorithm
42
   * @param alg WebCrypto algorithm
43
   * @returns ASN.1 algorithm
44
   * @throws Error whenever cannot convert an algorithm
45
   */
46
  public toAsnAlgorithm(alg: Algorithm): AlgorithmIdentifier {
2✔
47
    // prepare hashed algorithm
48
    const algCopy: any = { ...alg };
112✔
49
    if (algCopy.hash && typeof algCopy.hash === "string") {
112✔
50
      algCopy.hash = { name: algCopy.hash };
36✔
51
    }
36✔
52

53
    for (const algorithm of this.getAlgorithms()) {
112✔
54
      const res = algorithm.toAsnAlgorithm(alg);
176✔
55
      if (res) {
176✔
56
        return res;
108✔
57
      }
108✔
58
    }
176✔
59

60
    if (/^[0-9.]+$/.test(alg.name)) {
12!
NEW
61
      const res = new AlgorithmIdentifier({ algorithm: alg.name });
×
62

63
      if ("parameters" in alg) {
×
64
        const unknown = alg as UnknownAlgorithm;
×
65
        res.parameters = unknown.parameters;
×
66
      }
×
67

68
      return res;
×
69
    }
✔
70

71
    throw new Error("Cannot convert WebCrypto algorithm to ASN.1 algorithm");
2✔
72
  }
112✔
73

74
  /**
75
   * ConvertsASN.1 algorithm to WebCrypto algorithm
76
   * @param alg ASN.1 algorithm
77
   * @returns  algorithm
78
   */
79
  public toWebAlgorithm(alg: AlgorithmIdentifier): Algorithm {
2✔
80
    for (const algorithm of this.getAlgorithms()) {
262✔
81
      const res = algorithm.toWebAlgorithm(alg);
454✔
82
      if (res) {
454✔
83
        return res;
258✔
84
      }
258✔
85
    }
454✔
86

87
    const unknown: UnknownAlgorithm = {
4✔
88
      name: alg.algorithm,
4✔
89
      parameters: alg.parameters,
4✔
90
    };
4✔
91

92
    return unknown;
4✔
93
  }
262✔
94
}
2✔
95

96
export const diAlgorithmProvider = "crypto.algorithmProvider";
2✔
97

98
// register AlgorithmProvider as a singleton object
99
container.registerSingleton(diAlgorithmProvider, AlgorithmProvider);
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