Skip to content

Commit 6ab3558

Browse files
committed
Migrate AlgorithmIdentifier values from rustls-webpki
Any downstream crate defining a custom `rustls::CryptoProvider` currently needs to take a dependency on `rustls-webpki` to reuse these values (alternatively they can redefine these values, but meh.) Moving them here removes that need.
1 parent 87d80c1 commit 6ab3558

17 files changed

+103
-0
lines changed

src/alg_id.rs

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
//! Encodings of the PKIX AlgorithmIdentifier type.
2+
//!
3+
//! This module contains a set of common values, and exists to keep the
4+
//! names of these separate from the actual algorithm implementations.
5+
6+
use super::AlgorithmIdentifier;
7+
8+
// See src/data/README.md.
9+
10+
/// AlgorithmIdentifier for `id-ecPublicKey` with named curve `secp256r1`.
11+
pub const ECDSA_P256: AlgorithmIdentifier =
12+
AlgorithmIdentifier::from_slice(include_bytes!("data/alg-ecdsa-p256.der"));
13+
14+
/// AlgorithmIdentifier for `id-ecPublicKey` with named curve `secp384r1`.
15+
pub const ECDSA_P384: AlgorithmIdentifier =
16+
AlgorithmIdentifier::from_slice(include_bytes!("data/alg-ecdsa-p384.der"));
17+
18+
/// AlgorithmIdentifier for `id-ecPublicKey` with named curve `secp521r1`.
19+
pub const ECDSA_P521: AlgorithmIdentifier =
20+
AlgorithmIdentifier::from_slice(include_bytes!("data/alg-ecdsa-p521.der"));
21+
22+
/// AlgorithmIdentifier for `ecdsa-with-SHA256`.
23+
pub const ECDSA_SHA256: AlgorithmIdentifier =
24+
AlgorithmIdentifier::from_slice(include_bytes!("data/alg-ecdsa-sha256.der"));
25+
26+
/// AlgorithmIdentifier for `ecdsa-with-SHA384`.
27+
pub const ECDSA_SHA384: AlgorithmIdentifier =
28+
AlgorithmIdentifier::from_slice(include_bytes!("data/alg-ecdsa-sha384.der"));
29+
30+
/// AlgorithmIdentifier for `ecdsa-with-SHA512`.
31+
pub const ECDSA_SHA512: AlgorithmIdentifier =
32+
AlgorithmIdentifier::from_slice(include_bytes!("data/alg-ecdsa-sha512.der"));
33+
34+
/// AlgorithmIdentifier for `rsaEncryption`.
35+
pub const RSA_ENCRYPTION: AlgorithmIdentifier =
36+
AlgorithmIdentifier::from_slice(include_bytes!("data/alg-rsa-encryption.der"));
37+
38+
/// AlgorithmIdentifier for `sha256WithRSAEncryption`.
39+
pub const RSA_PKCS1_SHA256: AlgorithmIdentifier =
40+
AlgorithmIdentifier::from_slice(include_bytes!("data/alg-rsa-pkcs1-sha256.der"));
41+
42+
/// AlgorithmIdentifier for `sha384WithRSAEncryption`.
43+
pub const RSA_PKCS1_SHA384: AlgorithmIdentifier =
44+
AlgorithmIdentifier::from_slice(include_bytes!("data/alg-rsa-pkcs1-sha384.der"));
45+
46+
/// AlgorithmIdentifier for `sha512WithRSAEncryption`.
47+
pub const RSA_PKCS1_SHA512: AlgorithmIdentifier =
48+
AlgorithmIdentifier::from_slice(include_bytes!("data/alg-rsa-pkcs1-sha512.der"));
49+
50+
/// AlgorithmIdentifier for `rsassaPss` with:
51+
///
52+
/// - hashAlgorithm: sha256
53+
/// - maskGenAlgorithm: mgf1 with sha256
54+
/// - saltLength: 32
55+
pub const RSA_PSS_SHA256: AlgorithmIdentifier =
56+
AlgorithmIdentifier::from_slice(include_bytes!("data/alg-rsa-pss-sha256.der"));
57+
58+
/// AlgorithmIdentifier for `rsassaPss` with:
59+
///
60+
/// - hashAlgorithm: sha384
61+
/// - maskGenAlgorithm: mgf1 with sha384
62+
/// - saltLength: 48
63+
pub const RSA_PSS_SHA384: AlgorithmIdentifier =
64+
AlgorithmIdentifier::from_slice(include_bytes!("data/alg-rsa-pss-sha384.der"));
65+
66+
/// AlgorithmIdentifier for `rsassaPss` with:
67+
///
68+
/// - hashAlgorithm: sha512
69+
/// - maskGenAlgorithm: mgf1 with sha512
70+
/// - saltLength: 64
71+
pub const RSA_PSS_SHA512: AlgorithmIdentifier =
72+
AlgorithmIdentifier::from_slice(include_bytes!("data/alg-rsa-pss-sha512.der"));
73+
74+
/// AlgorithmIdentifier for `ED25519`.
75+
pub const ED25519: AlgorithmIdentifier =
76+
AlgorithmIdentifier::from_slice(include_bytes!("data/alg-ed25519.der"));

src/data/README.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
These files contain the binary DER encoding of the *values* of some
2+
ASN.1 [`AlgorithmIdentifier`]s, without the outer `SEQUENCE` tag or the outer
3+
length component.
4+
5+
These files were encoded with the help of [der-ascii]. They can be decoded
6+
using:
7+
8+
```sh
9+
go get github.com/google/der-ascii/cmd/der2ascii
10+
der2ascii -i <filename> -o <filename>.ascii
11+
```
12+
13+
New or modified der-ascii files can be encoded using:
14+
15+
```sh
16+
go get github.com/google/der-ascii/cmd/ascii2der
17+
ascii2der i <filename>.ascii -o <filename>
18+
```
19+
20+
[`AlgorithmIdentifier`]: https://tools.ietf.org/html/rfc5280#section-4.1.1.2]
21+
[der-ascii]: https://github.com/google/der-ascii

src/data/alg-ecdsa-p256.der

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*�H�=*�H�=

src/data/alg-ecdsa-p384.der

16 Bytes
Binary file not shown.

src/data/alg-ecdsa-p521.der

16 Bytes
Binary file not shown.

src/data/alg-ecdsa-sha256.der

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*�H�=

src/data/alg-ecdsa-sha384.der

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*�H�=

src/data/alg-ecdsa-sha512.der

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*�H�=

src/data/alg-ed25519.der

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
+ep

src/data/alg-rsa-encryption.der

13 Bytes
Binary file not shown.

src/data/alg-rsa-pkcs1-sha256.der

13 Bytes
Binary file not shown.

src/data/alg-rsa-pkcs1-sha384.der

13 Bytes
Binary file not shown.

src/data/alg-rsa-pkcs1-sha512.der

13 Bytes
Binary file not shown.

src/data/alg-rsa-pss-sha256.der

65 Bytes
Binary file not shown.

src/data/alg-rsa-pss-sha384.der

65 Bytes
Binary file not shown.

src/data/alg-rsa-pss-sha512.der

65 Bytes
Binary file not shown.

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ use std::time::SystemTime;
8383
#[cfg(all(target_family = "wasm", target_os = "unknown", feature = "web"))]
8484
use web_time::SystemTime;
8585

86+
pub mod alg_id;
8687
mod base64;
8788
mod server_name;
8889

0 commit comments

Comments
 (0)