Skip to content

Commit

Permalink
Merge 8affedb into 3e6204d
Browse files Browse the repository at this point in the history
  • Loading branch information
briansmith committed Sep 4, 2017
2 parents 3e6204d + 8affedb commit d3e87b5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 28 deletions.
15 changes: 3 additions & 12 deletions src/client/mod.rs
Expand Up @@ -489,17 +489,8 @@ impl ClientSessionImpl {
Ok(())
}

pub fn get_peer_certificates(&self) -> Option<Vec<key::Certificate>> {
if self.server_cert_chain.is_empty() {
return None;
}

let mut r = Vec::new();
for cert in &self.server_cert_chain {
r.push(cert.clone());
}

Some(r)
pub fn get_peer_certificates(&self) -> Option<&[key::Certificate]> {
Some(&self.server_cert_chain)
}

pub fn get_alpn_protocol(&self) -> Option<String> {
Expand Down Expand Up @@ -561,7 +552,7 @@ impl Session for ClientSession {
self.imp.common.send_close_notify()
}

fn get_peer_certificates(&self) -> Option<Vec<key::Certificate>> {
fn get_peer_certificates(&self) -> Option<&[key::Certificate]> {
self.imp.get_peer_certificates()
}

Expand Down
16 changes: 3 additions & 13 deletions src/server/mod.rs
Expand Up @@ -486,18 +486,8 @@ impl ServerSessionImpl {
self.common.start_encryption_tls12(self.secrets.as_ref().unwrap());
}

pub fn get_peer_certificates(&self) -> Option<Vec<key::Certificate>> {
if self.client_cert_chain.is_none() {
return None;
}

let mut r = Vec::new();

for cert in self.client_cert_chain.as_ref().unwrap() {
r.push(cert.clone());
}

Some(r)
pub fn get_peer_certificates(&self) -> Option<&[key::Certificate]> {
self.client_cert_chain.as_ref().map(|c| c.as_ref())
}

pub fn get_alpn_protocol(&self) -> Option<String> {
Expand Down Expand Up @@ -591,7 +581,7 @@ impl Session for ServerSession {
self.imp.common.send_close_notify()
}

fn get_peer_certificates(&self) -> Option<Vec<key::Certificate>> {
fn get_peer_certificates(&self) -> Option<&[key::Certificate]> {
self.imp.get_peer_certificates()
}

Expand Down
2 changes: 1 addition & 1 deletion src/session.rs
Expand Up @@ -83,7 +83,7 @@ pub trait Session: Read + Write + Send {
/// if client authentication was completed.
///
/// The return value is None until this value is available.
fn get_peer_certificates(&self) -> Option<Vec<key::Certificate>>;
fn get_peer_certificates(&self) -> Option<&[key::Certificate]>;

/// Retrieves the protocol agreed with the peer via ALPN.
///
Expand Down
4 changes: 2 additions & 2 deletions tests/api.rs
Expand Up @@ -287,7 +287,7 @@ fn client_can_get_server_cert() {
do_handshake(&mut client, &mut server);

let certs = client.get_peer_certificates();
assert_eq!(certs, Some(get_chain()));
assert_eq!(certs, Some(get_chain().as_ref()));
}

#[test]
Expand All @@ -303,7 +303,7 @@ fn server_can_get_client_cert() {
do_handshake(&mut client, &mut server);

let certs = server.get_peer_certificates();
assert_eq!(certs, Some(get_chain()));
assert_eq!(certs, Some(get_chain().as_ref()));
}

fn check_read_and_close(reader: &mut io::Read, expect: &[u8]) {
Expand Down

0 comments on commit d3e87b5

Please sign in to comment.