Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/dtls12/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ impl Client {
certificate: DtlsCertificate,
now: Instant,
) -> Result<Client, Error> {
assert!(
!certificate.certificate.is_empty(),
"Client certificate cannot be empty"
);
// unwrap: malformed private_key bytes are a programmer error from the
// caller who constructed DtlsCertificate; panic matches the prior
// CryptoContext::new behavior which also panicked on empty/invalid
Expand Down
4 changes: 4 additions & 0 deletions src/dtls12/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ enum State {
impl Server {
/// Create a new DTLS server
pub fn new(config: Arc<Config>, certificate: crate::DtlsCertificate, now: Instant) -> Server {
assert!(
!certificate.certificate.is_empty(),
"Server certificate cannot be empty"
);
// unwrap: malformed private_key bytes are a programmer error from the
// caller who constructed DtlsCertificate; panic matches the prior
// CryptoContext::new behavior which also panicked on empty/invalid
Expand Down
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,18 @@ mod test {
let _ = Dtls::new_12_psk(config, Instant::now());
}

#[test]
#[should_panic(expected = "Server certificate cannot be empty")]
fn new_12_panics_on_empty_certificate() {
let cert = generate_self_signed_certificate().expect("Failed to generate cert");
let config = Arc::new(Config::default());
let empty = DtlsCertificate {
certificate: vec![],
private_key: cert.private_key,
};
let _ = Dtls::new_12(config, empty, Instant::now());
}

#[test]
fn test_auto_server_send_application_data_pending() {
let mut dtls = new_instance_auto();
Expand Down
Loading