use std::ptr;
use std::slice;
use foreign_types::ForeignTypeRef;
use super::{NameType, SslRef, SslVersion, TlsExtType};
#[repr(transparent)]
pub struct ClientHello<'ssl>(pub(super) &'ssl ffi::SSL_CLIENT_HELLO);
impl ClientHello<'_> {
pub fn get_extension(&self, ext_type: TlsExtType) -> Option<&[u8]> {
unsafe {
let mut ptr = ptr::null();
let mut len = 0;
let r = ffi::SSL_early_callback_ctx_extension_get(
self.0,
ext_type.as_raw() as _,
&mut ptr,
&mut len,
);
if r == 0 {
None
} else {
Some(slice::from_raw_parts(ptr, len))
}
}
}
pub fn ssl_mut(&mut self) -> &mut SslRef {
unsafe { SslRef::from_ptr_mut(self.0.ssl) }
}
pub fn ssl(&self) -> &SslRef {
unsafe { SslRef::from_ptr(self.0.ssl) }
}
pub fn servername(&self, type_: NameType) -> Option<&str> {
self.ssl().servername(type_)
}
pub fn client_version(&self) -> SslVersion {
SslVersion(self.0.version.into())
}
pub fn version_str(&self) -> &'static str {
self.ssl().version_str()
}
}