diff options
| author | Erik Johnston <[email protected]> | 2016-02-17 22:04:49 +0000 |
|---|---|---|
| committer | Erik Johnston <[email protected]> | 2016-02-17 22:38:32 +0000 |
| commit | 1e9667ea89cf1f52c65b4b70d1ef0dfd2770332e (patch) | |
| tree | e55a2c2913e20249d22034b1d4611a54ec59ebb5 /openssl/src/ssl/mod.rs | |
| parent | Merge branch 'release' (diff) | |
| download | rust-openssl-1e9667ea89cf1f52c65b4b70d1ef0dfd2770332e.tar.xz rust-openssl-1e9667ea89cf1f52c65b4b70d1ef0dfd2770332e.zip | |
Add support for SSL_CIPHER
Diffstat (limited to 'openssl/src/ssl/mod.rs')
| -rw-r--r-- | openssl/src/ssl/mod.rs | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs index 8e6d061d..f5605b60 100644 --- a/openssl/src/ssl/mod.rs +++ b/openssl/src/ssl/mod.rs @@ -769,6 +769,46 @@ impl SslContext { } } +pub struct SslCipher { + cipher: *const ffi::SSL_CIPHER, +} + +impl SslCipher { + pub fn name(&self) -> &'static str { + let name = unsafe { + let ptr = ffi::SSL_CIPHER_get_name(self.cipher); + CStr::from_ptr(ptr as *const _) + }; + + str::from_utf8(name.to_bytes()).unwrap() + } + + pub fn version(&self) -> &'static str { + let version = unsafe { + let ptr = ffi::SSL_CIPHER_get_version(self.cipher); + CStr::from_ptr(ptr as *const _) + }; + + str::from_utf8(version.to_bytes()).unwrap() + } + + pub fn bits(&self) -> (i32, i32) { + unsafe { + let mut algo_bits : c_int = 0; + let actual_bits = ffi::SSL_CIPHER_get_bits(self.cipher, &mut algo_bits); + (actual_bits, algo_bits) + } + } + + pub fn description(&self) -> String { + unsafe { + let desc_ptr = ffi::SSL_CIPHER_description(self.cipher, ptr::null_mut(), 0); + String::from_utf8(CStr::from_ptr(desc_ptr).to_bytes().to_vec()).unwrap() + } + } +} + + pub struct Ssl { ssl: *mut ffi::SSL, } @@ -836,6 +876,18 @@ impl Ssl { } } + pub fn get_current_cipher(&self) -> Option<SslCipher> { + unsafe { + let ptr = ffi::SSL_get_current_cipher(self.ssl); + + if ptr.is_null() { + None + } else { + Some(SslCipher{ cipher: ptr }) + } + } + } + pub fn state_string(&self) -> &'static str { let state = unsafe { let ptr = ffi::SSL_state_string(self.ssl); |