File: key_type.rs

package info (click to toggle)
rust-rustls-pki-types 1.12.0-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid
  • size: 572 kB
  • sloc: makefile: 2; sh: 1
file content (42 lines) | stat: -rw-r--r-- 1,678 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use rustls_pki_types::PrivateKeyDer;

#[test]
fn test_private_key_from_der() {
    const NIST_P256_KEY_SEC1: &[u8] = include_bytes!("../tests/keys/nistp256key.der");
    const NIST_P384_KEY_SEC1: &[u8] = include_bytes!("../tests/keys/nistp384key.der");
    const NIST_P521_KEY_SEC1: &[u8] = include_bytes!("../tests/keys/nistp521key.der");
    for bytes in [NIST_P256_KEY_SEC1, NIST_P384_KEY_SEC1, NIST_P521_KEY_SEC1] {
        assert!(matches!(
            PrivateKeyDer::try_from(bytes).unwrap(),
            PrivateKeyDer::Sec1(_)
        ));
    }

    const RSA_2048_KEY_PKCS1: &[u8] = include_bytes!("../tests/keys/rsa2048key.pkcs1.der");
    assert!(matches!(
        PrivateKeyDer::try_from(RSA_2048_KEY_PKCS1).unwrap(),
        PrivateKeyDer::Pkcs1(_)
    ));

    const NIST_P256_KEY_PKCS8: &[u8] = include_bytes!("../tests/keys/nistp256key.pkcs8.der");
    const NIST_P384_KEY_PKCS8: &[u8] = include_bytes!("../tests/keys/nistp384key.pkcs8.der");
    const NIST_P521_KEY_PKCS8: &[u8] = include_bytes!("../tests/keys/nistp521key.pkcs8.der");
    const RSA_2048_KEY_PKCS8: &[u8] = include_bytes!("../tests/keys/rsa2048key.pkcs8.der");
    const RSA_4096_KEY: &[u8] = include_bytes!("../tests/keys/rsa4096key.pkcs8.der");
    const ED25519_KEY: &[u8] = include_bytes!("../tests/keys/edd25519_v2.der");
    const PKCS8_KEYS: &[&[u8]] = &[
        NIST_P256_KEY_PKCS8,
        NIST_P384_KEY_PKCS8,
        NIST_P521_KEY_PKCS8,
        RSA_2048_KEY_PKCS8,
        RSA_4096_KEY,
        ED25519_KEY,
    ];

    for &bytes in PKCS8_KEYS {
        assert!(matches!(
            PrivateKeyDer::try_from(bytes).unwrap(),
            PrivateKeyDer::Pkcs8(_)
        ));
    }
}