File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -128,6 +128,10 @@ impl Client {
128128 certificate : DtlsCertificate ,
129129 now : Instant ,
130130 ) -> Result < Client , Error > {
131+ assert ! (
132+ !certificate. certificate. is_empty( ) ,
133+ "Client certificate cannot be empty"
134+ ) ;
131135 // unwrap: malformed private_key bytes are a programmer error from the
132136 // caller who constructed DtlsCertificate; panic matches the prior
133137 // CryptoContext::new behavior which also panicked on empty/invalid
Original file line number Diff line number Diff line change @@ -126,6 +126,10 @@ enum State {
126126impl Server {
127127 /// Create a new DTLS server
128128 pub fn new ( config : Arc < Config > , certificate : crate :: DtlsCertificate , now : Instant ) -> Server {
129+ assert ! (
130+ !certificate. certificate. is_empty( ) ,
131+ "Server certificate cannot be empty"
132+ ) ;
129133 // unwrap: malformed private_key bytes are a programmer error from the
130134 // caller who constructed DtlsCertificate; panic matches the prior
131135 // CryptoContext::new behavior which also panicked on empty/invalid
Original file line number Diff line number Diff line change @@ -876,6 +876,18 @@ mod test {
876876 let _ = Dtls :: new_12_psk ( config, Instant :: now ( ) ) ;
877877 }
878878
879+ #[ test]
880+ #[ should_panic( expected = "Server certificate cannot be empty" ) ]
881+ fn new_12_panics_on_empty_certificate ( ) {
882+ let cert = generate_self_signed_certificate ( ) . expect ( "Failed to generate cert" ) ;
883+ let config = Arc :: new ( Config :: default ( ) ) ;
884+ let empty = DtlsCertificate {
885+ certificate : vec ! [ ] ,
886+ private_key : cert. private_key ,
887+ } ;
888+ let _ = Dtls :: new_12 ( config, empty, Instant :: now ( ) ) ;
889+ }
890+
879891 #[ test]
880892 fn test_auto_server_send_application_data_pending ( ) {
881893 let mut dtls = new_instance_auto ( ) ;
You can’t perform that action at this time.
0 commit comments