Skip to content

Commit

Permalink
Fix & extend tests to cover sec1 ec keys
Browse files Browse the repository at this point in the history
  • Loading branch information
ctz committed Feb 5, 2022
1 parent 9a7e4a8 commit c204f5c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
//! Item::X509Certificate(cert) => println!("certificate {:?}", cert),
//! Item::RSAKey(key) => println!("rsa pkcs1 key {:?}", key),
//! Item::PKCS8Key(key) => println!("pkcs8 key {:?}", key),
//! Item::ECKey(key) => println!("sec1 ec key {:?}", key),
//! _ => println!("unhandled item"),
//! }
//! }
//! ```
Expand Down
21 changes: 16 additions & 5 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ fn test_pkcs8() {
2);
}

#[test]
fn test_sec1() {
let data = include_bytes!("data/nistp256key.pem");
let mut reader = BufReader::new(&data[..]);

let items = rustls_pemfile::read_all(&mut reader).unwrap();
assert_eq!(items.len(), 1);
assert!(matches!(items[0], rustls_pemfile::Item::ECKey(_)));
}

#[test]
fn smoketest_iterate() {
let data = include_bytes!("data/zen2.pem");
Expand All @@ -40,7 +50,7 @@ fn smoketest_iterate() {
count += 1;
}

assert_eq!(count, 14);
assert_eq!(count, 16);
}

#[test]
Expand All @@ -50,12 +60,13 @@ fn parse_in_order() {

let items = rustls_pemfile::read_all(&mut reader)
.unwrap();
assert_eq!(items.len(), 7);
assert_eq!(items.len(), 8);
assert!(matches!(items[0], rustls_pemfile::Item::X509Certificate(_)));
assert!(matches!(items[1], rustls_pemfile::Item::X509Certificate(_)));
assert!(matches!(items[2], rustls_pemfile::Item::X509Certificate(_)));
assert!(matches!(items[3], rustls_pemfile::Item::X509Certificate(_)));
assert!(matches!(items[4], rustls_pemfile::Item::PKCS8Key(_)));
assert!(matches!(items[5], rustls_pemfile::Item::RSAKey(_)));
assert!(matches!(items[6], rustls_pemfile::Item::PKCS8Key(_)));
assert!(matches!(items[4], rustls_pemfile::Item::ECKey(_)));
assert!(matches!(items[5], rustls_pemfile::Item::PKCS8Key(_)));
assert!(matches!(items[6], rustls_pemfile::Item::RSAKey(_)));
assert!(matches!(items[7], rustls_pemfile::Item::PKCS8Key(_)));
}

0 comments on commit c204f5c

Please sign in to comment.