Skip to content

Commit

Permalink
rename RTCCertificate::new to RTCCertificate::from_existing
Browse files Browse the repository at this point in the history
  • Loading branch information
melekes committed Jun 21, 2022
1 parent 7e79797 commit 500124c
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/peer_connection/certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,15 @@ impl RTCCertificate {
})
}

/// new constructs a `RTCCertificate` from an existing certificate. Use this method when you
/// have a persistent certificate (i.e. you don't want to generate a new one for each DTLS
/// connection).
pub fn new(certificate: dtls::crypto::Certificate, pem: &str, expires: SystemTime) -> Self {
/// Constructs a `RTCCertificate` from an existing certificate.
///
/// Use this method when you have a persistent certificate (i.e. you don't want to generate a
/// new one for each DTLS connection).
pub fn from_existing(
certificate: dtls::crypto::Certificate,
pem: &str,
expires: SystemTime,
) -> Self {
Self {
certificate,
stats_id: format!(
Expand Down Expand Up @@ -389,15 +394,15 @@ mod test {
}

#[test]
fn test_new() -> Result<()> {
fn test_from_existing() -> Result<()> {
// NOTE `dtls_cert` key pair and `key_pair` are different, but it's fine here.
let key_pair = KeyPair::generate(&rcgen::PKCS_ECDSA_P256_SHA256)?;
let dtls_cert = dtls::crypto::Certificate::generate_self_signed(["localhost".to_owned()])?;

let expires = SystemTime::now();
let pem = key_pair.serialize_pem();

let cert = RTCCertificate::new(dtls_cert, &pem, expires);
let cert = RTCCertificate::from_existing(dtls_cert, &pem, expires);

assert_ne!("", cert.stats_id);
assert_eq!(expires, cert.expires());
Expand Down

0 comments on commit 500124c

Please sign in to comment.