Skip to content
Merged
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
35 changes: 33 additions & 2 deletions boring/src/ssl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ impl From<u16> for ExtensionType {
}

/// An SSL/TLS protocol version.
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[derive(Copy, Clone, PartialEq, Eq)]
pub struct SslVersion(u16);

impl SslVersion {
Expand All @@ -540,6 +540,32 @@ impl SslVersion {
pub const TLS1_3: SslVersion = SslVersion(ffi::TLS1_3_VERSION as _);
}

impl fmt::Debug for SslVersion {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(match *self {
Self::SSL3 => "SSL3",
Self::TLS1 => "TLS1",
Self::TLS1_1 => "TLS1_1",
Self::TLS1_2 => "TLS1_2",
Self::TLS1_3 => "TLS1_3",
_ => return write!(f, "{:#06x}", self.0),
})
}
}

impl fmt::Display for SslVersion {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(match *self {
Self::SSL3 => "SSLv3",
Self::TLS1 => "TLSv1",
Self::TLS1_1 => "TLSv1.1",
Self::TLS1_2 => "TLSv1.2",
Self::TLS1_3 => "TLSv1.3",
_ => return write!(f, "unknown ({:#06x})", self.0),
})
}
}

/// A signature verification algorithm.
#[repr(transparent)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
Expand Down Expand Up @@ -1789,7 +1815,12 @@ impl ClientHello {
self.ssl().servername(type_)
}

/// Returns a string describing the protocol version of the session.
/// Returns the version sent by the client in its Client Hello record.
pub fn client_version(&self) -> SslVersion {
SslVersion(self.0.version)
}

/// Returns a string describing the protocol version of the connection.
pub fn version_str(&self) -> &'static str {
self.ssl().version_str()
}
Expand Down