|
1 | | -import { Enum } from "./enum.d.ts" |
2 | | -import { Uint16, Constrained } from "../src/dep.ts"; |
| 1 | +import { Constrained, Uint16 } from "../src/dep.ts"; |
| 2 | +import { Enum } from "../src/enum.js"; |
| 3 | + |
3 | 4 | /** |
4 | 5 | * Enumeration of signature schemes as defined in RFC 8446. |
5 | 6 | * @see https://datatracker.ietf.org/doc/html/rfc8446#section-4.2.3 |
6 | 7 | */ |
7 | 8 | export class SignatureScheme extends Enum { |
8 | | - /** RSASSA-PKCS1-v1_5 algorithms */ |
9 | | - static RSA_PKCS1_SHA256: SignatureScheme; |
10 | | - static RSA_PKCS1_SHA384: SignatureScheme; |
11 | | - static RSA_PKCS1_SHA512: SignatureScheme; |
12 | | - |
13 | | - /** ECDSA algorithms */ |
14 | | - static ECDSA_SECP256R1_SHA256: SignatureScheme; |
15 | | - static ECDSA_SECP384R1_SHA384: SignatureScheme; |
16 | | - static ECDSA_SECP521R1_SHA512: SignatureScheme; |
17 | | - |
18 | | - /** RSASSA-PSS algorithms with public key OID rsaEncryption */ |
19 | | - static RSA_PSS_RSAE_SHA256: SignatureScheme; |
20 | | - static RSA_PSS_RSAE_SHA384: SignatureScheme; |
21 | | - static RSA_PSS_RSAE_SHA512: SignatureScheme; |
22 | | - |
23 | | - /** EdDSA algorithms */ |
24 | | - static ED25519: SignatureScheme; |
25 | | - static ED448: SignatureScheme; |
26 | | - |
27 | | - /** RSASSA-PSS algorithms with public key OID RSASSA-PSS */ |
28 | | - static RSA_PSS_PSS_SHA256: SignatureScheme; |
29 | | - static RSA_PSS_PSS_SHA384: SignatureScheme; |
30 | | - static RSA_PSS_PSS_SHA512: SignatureScheme; |
31 | | - |
32 | | - /** |
33 | | - * Parses an octet array and returns a valid SignatureScheme. |
34 | | - * |
35 | | - * @static |
36 | | - * @param {Uint8Array} octet - The octet array to parse. |
37 | | - * @returns {SignatureScheme} The corresponding SignatureScheme instance. |
38 | | - * @throws {Error} If the octet does not correspond to a known SignatureScheme. |
39 | | - */ |
40 | | - static from(octet: Uint8Array): SignatureScheme; |
41 | | - |
42 | | - /** Returns the bit length of the SignatureScheme. */ |
43 | | - get bit(): number; |
44 | | - |
45 | | - /** |
46 | | - * Converts the SignatureScheme to a Uint16 representation. |
47 | | - * |
48 | | - * @returns {Uint16} The Uint16 representation of the SignatureScheme. |
49 | | - */ |
50 | | - get Uint16(): Uint16; |
| 9 | + /** RSASSA-PKCS1-v1_5 algorithms */ |
| 10 | + static RSA_PKCS1_SHA256: SignatureScheme; |
| 11 | + static RSA_PKCS1_SHA384: SignatureScheme; |
| 12 | + static RSA_PKCS1_SHA512: SignatureScheme; |
| 13 | + |
| 14 | + /** ECDSA algorithms */ |
| 15 | + static ECDSA_SECP256R1_SHA256: SignatureScheme; |
| 16 | + static ECDSA_SECP384R1_SHA384: SignatureScheme; |
| 17 | + static ECDSA_SECP521R1_SHA512: SignatureScheme; |
| 18 | + |
| 19 | + /** RSASSA-PSS algorithms with public key OID rsaEncryption */ |
| 20 | + static RSA_PSS_RSAE_SHA256: SignatureScheme; |
| 21 | + static RSA_PSS_RSAE_SHA384: SignatureScheme; |
| 22 | + static RSA_PSS_RSAE_SHA512: SignatureScheme; |
| 23 | + |
| 24 | + /** EdDSA algorithms */ |
| 25 | + static ED25519: SignatureScheme; |
| 26 | + static ED448: SignatureScheme; |
| 27 | + |
| 28 | + /** RSASSA-PSS algorithms with public key OID RSASSA-PSS */ |
| 29 | + static RSA_PSS_PSS_SHA256: SignatureScheme; |
| 30 | + static RSA_PSS_PSS_SHA384: SignatureScheme; |
| 31 | + static RSA_PSS_PSS_SHA512: SignatureScheme; |
| 32 | + |
| 33 | + /** Legacy algorithms */ |
| 34 | + static RSA_PKCS1_SHA1: SignatureScheme; |
| 35 | + static ECDSA_SHA1: SignatureScheme; |
| 36 | + |
| 37 | + /** Reserved Code Points */ |
| 38 | + static dsa_sha1_RESERVED: SignatureScheme; |
| 39 | + static dsa_sha256_RESERVED: SignatureScheme; |
| 40 | + static dsa_sha384_RESERVED: SignatureScheme; |
| 41 | + static dsa_sha512_RESERVED: SignatureScheme; |
| 42 | + |
| 43 | + /** |
| 44 | + * Parses an octet array and returns a valid SignatureScheme. |
| 45 | + * @param {Uint8Array} octet - The octet array to parse. |
| 46 | + * @returns {SignatureScheme} The corresponding SignatureScheme instance. |
| 47 | + * @throws {Error} If the octet does not correspond to a known SignatureScheme. |
| 48 | + */ |
| 49 | + static from(octet: Uint8Array): SignatureScheme; |
| 50 | + |
| 51 | + /** |
| 52 | + * Returns the bit length of the SignatureScheme. |
| 53 | + * @returns {number} The bit length, which is always 16. |
| 54 | + */ |
| 55 | + get bit(): number; |
| 56 | + |
| 57 | + /** |
| 58 | + * Converts the SignatureScheme to a Uint16 representation. |
| 59 | + * @returns {Uint16} The Uint16 representation of the SignatureScheme. |
| 60 | + */ |
| 61 | + get Uint16(): Uint16; |
| 62 | + |
| 63 | + /** |
| 64 | + * Generates a CertificateVerify object. |
| 65 | + * @param {Uint8Array} clientHelloMsg - Client Hello message. |
| 66 | + * @param {Uint8Array} serverHelloMsg - Server Hello message. |
| 67 | + * @param {Uint8Array} certificateMsg - Certificate message. |
| 68 | + * @param {CryptoKey} RSAprivateKey - RSA private key. |
| 69 | + * @returns {Promise<CertificateVerify>} CertificateVerify object. |
| 70 | + */ |
| 71 | + certificateVerify( |
| 72 | + clientHelloMsg: Uint8Array, |
| 73 | + serverHelloMsg: Uint8Array, |
| 74 | + certificateMsg: Uint8Array, |
| 75 | + RSAprivateKey: CryptoKey |
| 76 | + ): Promise<CertificateVerify>; |
51 | 77 | } |
| 78 | + |
| 79 | +/** |
| 80 | + * Represents a CertificateVerify structure. |
| 81 | + */ |
| 82 | +export class CertificateVerify extends Uint8Array { |
| 83 | + /** The signature algorithm used. */ |
| 84 | + algorithm: SignatureScheme; |
| 85 | + |
| 86 | + /** The signature. */ |
| 87 | + signature: Uint8Array; |
| 88 | + |
| 89 | + /** |
| 90 | + * Parses a byte array into a CertificateVerify object. |
| 91 | + * @param {Uint8Array} array - The byte array to parse. |
| 92 | + * @returns {CertificateVerify} The parsed CertificateVerify object. |
| 93 | + */ |
| 94 | + static from(array: Uint8Array): CertificateVerify; |
| 95 | + |
| 96 | + /** |
| 97 | + * Constructs a new CertificateVerify object. |
| 98 | + * @param {SignatureScheme} signatureScheme - The signature scheme. |
| 99 | + * @param {Uint8Array} signature - The signature. |
| 100 | + */ |
| 101 | + constructor(signatureScheme: SignatureScheme, signature: Uint8Array); |
| 102 | +} |
| 103 | + |
| 104 | +/** |
| 105 | + * Represents a constrained signature. |
| 106 | + */ |
| 107 | +export class Signature extends Constrained { |
| 108 | + /** The raw opaque signature data. */ |
| 109 | + opaque: Uint8Array; |
| 110 | + |
| 111 | + /** |
| 112 | + * Parses a byte array into a Signature object. |
| 113 | + * @param {Uint8Array} array - The byte array to parse. |
| 114 | + * @returns {Signature} The parsed Signature object. |
| 115 | + */ |
| 116 | + static from(array: Uint8Array): Signature; |
| 117 | + |
| 118 | + /** |
| 119 | + * Constructs a new Signature object. |
| 120 | + * @param {Uint8Array} opaque - The raw opaque signature data. |
| 121 | + */ |
| 122 | + constructor(opaque: Uint8Array); |
| 123 | +} |
| 124 | + |
| 125 | +/** |
| 126 | + * Generates a signature from input data and a private RSA key. |
| 127 | + * @param {Uint8Array} clientHelloMsg - Client Hello message. |
| 128 | + * @param {Uint8Array} serverHelloMsg - Server Hello message. |
| 129 | + * @param {Uint8Array} certificateMsg - Certificate message. |
| 130 | + * @param {CryptoKey} RSAprivateKey - RSA private key. |
| 131 | + * @returns {Promise<Uint8Array>} The generated signature. |
| 132 | + */ |
| 133 | +export function signatureFrom( |
| 134 | + clientHelloMsg: Uint8Array, |
| 135 | + serverHelloMsg: Uint8Array, |
| 136 | + certificateMsg: Uint8Array, |
| 137 | + RSAprivateKey: CryptoKey |
| 138 | +): Promise<Uint8Array>; |
0 commit comments