Debian Codegraph @

crt/s2n/bindings/rust/standard/integration/src/utilities/certs.rs

raw symbols SCIP
1 // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2 // SPDX-License-Identifier: Apache-2.0
3
4 use std::sync::LazyLock;
5
6 /// the `pems` folder storing most of the s2n-tls unit test certs
7 const TEST_PEMS_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../../../../tests/pems/");
8
9 pub static ML_DSA_87: LazyLock<CertMaterials> = LazyLock::new(|| CertMaterials {
10 server_key_path: format!("{TEST_PEMS_PATH}mldsa/ML-DSA-87-seed.priv"),
11 server_chain_path: format!("{TEST_PEMS_PATH}mldsa/ML-DSA-87.crt"),
12 ca_path: format!("{TEST_PEMS_PATH}mldsa/ML-DSA-87.crt"),
13 });
14
15 pub static ML_DSA_44: LazyLock<CertMaterials> = LazyLock::new(|| CertMaterials {
16 server_key_path: format!("{TEST_PEMS_PATH}mldsa/ML-DSA-44-seed.priv"),
17 server_chain_path: format!("{TEST_PEMS_PATH}mldsa/ML-DSA-44.crt"),
18 ca_path: format!("{TEST_PEMS_PATH}mldsa/ML-DSA-44.crt"),
19 });
20
21 /// A self-signed cert with a SAN of `www.beaver.com`
22 pub static BEAVER: LazyLock<CertMaterials> = LazyLock::new(|| CertMaterials {
23 server_key_path: format!("{TEST_PEMS_PATH}sni/beaver_key.pem"),
24 server_chain_path: format!("{TEST_PEMS_PATH}sni/beaver_cert.pem"),
25 ca_path: format!("{TEST_PEMS_PATH}sni/beaver_cert.pem"),
26 });
27
28 /// CertMaterials holds the paths to PEM-formatted files
29 #[derive(Debug, Clone)]
30 pub struct CertMaterials {
31 pub server_key_path: String,
32 pub server_chain_path: String,
33 /// This will either be set to the specific CA, or may be set to the server_chain
34 /// path in the case of a self signed cert
35 pub ca_path: String,
36 }
37
38 impl CertMaterials {
39 /// return the cert materials from a "permutation" in test/pems/
40 pub fn from_permutation(permutation: &str) -> Self {
41 let folder = format!("{TEST_PEMS_PATH}permutations/{permutation}");
42 CertMaterials {
43 server_key_path: format!("{folder}/server-key.pem"),
44 server_chain_path: format!("{folder}/server-chain.pem"),
45 ca_path: format!("{folder}/ca-cert.pem"),
46 }
47 }
48
49 pub fn server_chain(&self) -> Vec<u8> {
50 std::fs::read(&self.server_chain_path).unwrap()
51 }
52
53 pub fn server_key(&self) -> Vec<u8> {
54 std::fs::read(&self.server_key_path).unwrap()
55 }
56
57 pub fn ca(&self) -> Vec<u8> {
58 std::fs::read(&self.ca_path).unwrap()
59 }
60 }