diff options
| author | Steven Fackler <[email protected]> | 2016-04-28 22:16:29 -0700 |
|---|---|---|
| committer | Steven Fackler <[email protected]> | 2016-04-28 22:16:29 -0700 |
| commit | caf9272c85ddc68071aac8a0a3aa2d88dd322427 (patch) | |
| tree | f235ebe947e6a108bb0abde7ebf86de4993c63c5 /openssl/src/x509/mod.rs | |
| parent | Merge branch 'release' (diff) | |
| download | rust-openssl-caf9272c85ddc68071aac8a0a3aa2d88dd322427.tar.xz rust-openssl-caf9272c85ddc68071aac8a0a3aa2d88dd322427.zip | |
Start on GeneralName
Diffstat (limited to 'openssl/src/x509/mod.rs')
| -rw-r--r-- | openssl/src/x509/mod.rs | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/openssl/src/x509/mod.rs b/openssl/src/x509/mod.rs index a69f61d5..cb2c7494 100644 --- a/openssl/src/x509/mod.rs +++ b/openssl/src/x509/mod.rs @@ -2,13 +2,14 @@ use libc::{c_char, c_int, c_long, c_ulong, c_uint, c_void}; use std::io; use std::io::prelude::*; use std::cmp::Ordering; -use std::ffi::{CString, CStr}; +use std::ffi::CString; use std::iter::repeat; use std::mem; use std::ptr; use std::ops::Deref; use std::fmt; use std::str; +use std::slice; use std::collections::HashMap; use asn1::Asn1Time; @@ -29,14 +30,12 @@ use self::extension::{ExtensionType, Extension}; #[cfg(test)] mod tests; -pub struct SslString { - s: &'static str, -} +pub struct SslString(&'static str); impl<'s> Drop for SslString { fn drop(&mut self) { unsafe { - ffi::CRYPTO_free(self.s.as_ptr() as *mut c_void); + ffi::CRYPTO_free(self.0.as_ptr() as *mut c_void); } } } @@ -45,25 +44,26 @@ impl Deref for SslString { type Target = str; fn deref(&self) -> &str { - self.s + self.0 } } impl SslString { - unsafe fn new(buf: *const c_char) -> SslString { - SslString { s: str::from_utf8(CStr::from_ptr(buf as *const _).to_bytes()).unwrap() } + unsafe fn new(buf: *const c_char, len: c_int) -> SslString { + let slice = slice::from_raw_parts(buf as *const _, len as usize); + SslString(str::from_utf8_unchecked(slice)) } } impl fmt::Display for SslString { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - fmt::Display::fmt(self.s, f) + fmt::Display::fmt(self.0, f) } } impl fmt::Debug for SslString { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - fmt::Debug::fmt(self.s, f) + fmt::Debug::fmt(self.0, f) } } @@ -570,7 +570,7 @@ impl<'x> X509Name<'x> { assert!(!str_from_asn1.is_null()); - Some(SslString::new(str_from_asn1)) + Some(SslString::new(str_from_asn1, len)) } } } |