Skip to content

Commit

Permalink
Test loading the expected signing key formats
Browse files Browse the repository at this point in the history
  • Loading branch information
ctz committed Feb 6, 2022
1 parent 5288fcf commit fe64924
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions rustls/src/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,3 +464,59 @@ impl fmt::Display for SignError {
}

impl StdError for SignError {}

#[test]
fn can_load_ecdsa_nistp256_pkcs8() {
let key = key::PrivateKey(include_bytes!("testdata/nistp256key.pkcs8.der").to_vec());
assert!(any_supported_type(&key).is_ok());
assert!(any_ecdsa_type(&key).is_ok());
assert!(any_eddsa_type(&key).is_err());
}

#[test]
fn can_load_ecdsa_nistp256_sec1() {
let key = key::PrivateKey(include_bytes!("testdata/nistp256key.der").to_vec());
assert!(any_supported_type(&key).is_ok());
assert!(any_ecdsa_type(&key).is_ok());
assert!(any_eddsa_type(&key).is_err());
}

#[test]
fn can_load_ecdsa_nistp384_pkcs8() {
let key = key::PrivateKey(include_bytes!("testdata/nistp384key.pkcs8.der").to_vec());
assert!(any_supported_type(&key).is_ok());
assert!(any_ecdsa_type(&key).is_ok());
assert!(any_eddsa_type(&key).is_err());
}

#[test]
fn can_load_ecdsa_nistp384_sec1() {
let key = key::PrivateKey(include_bytes!("testdata/nistp384key.der").to_vec());
assert!(any_supported_type(&key).is_ok());
assert!(any_ecdsa_type(&key).is_ok());
assert!(any_eddsa_type(&key).is_err());
}

#[test]
fn can_load_eddsa_pkcs8() {
let key = key::PrivateKey(include_bytes!("testdata/eddsakey.der").to_vec());
assert!(any_supported_type(&key).is_ok());
assert!(any_eddsa_type(&key).is_ok());
assert!(any_ecdsa_type(&key).is_err());
}

#[test]
fn can_load_rsa2048_pkcs8() {
let key = key::PrivateKey(include_bytes!("testdata/rsa2048key.pkcs8.der").to_vec());
assert!(any_supported_type(&key).is_ok());
assert!(any_eddsa_type(&key).is_err());
assert!(any_ecdsa_type(&key).is_err());
}

#[test]
fn can_load_rsa2048_pkcs1() {
let key = key::PrivateKey(include_bytes!("testdata/rsa2048key.pkcs1.der").to_vec());
assert!(any_supported_type(&key).is_ok());
assert!(any_eddsa_type(&key).is_err());
assert!(any_ecdsa_type(&key).is_err());
}
Binary file added rustls/src/testdata/eddsakey.der
Binary file not shown.
Binary file added rustls/src/testdata/nistp256key.der
Binary file not shown.
Binary file added rustls/src/testdata/nistp256key.pkcs8.der
Binary file not shown.
Binary file added rustls/src/testdata/nistp384key.der
Binary file not shown.
Binary file added rustls/src/testdata/nistp384key.pkcs8.der
Binary file not shown.
Binary file added rustls/src/testdata/rsa2048key.pkcs1.der
Binary file not shown.
Binary file added rustls/src/testdata/rsa2048key.pkcs8.der
Binary file not shown.

0 comments on commit fe64924

Please sign in to comment.