diff options
Diffstat (limited to 'openssl/src/verify.rs')
| -rw-r--r-- | openssl/src/verify.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/openssl/src/verify.rs b/openssl/src/verify.rs index 002b0ca0..7b2fa612 100644 --- a/openssl/src/verify.rs +++ b/openssl/src/verify.rs @@ -1,6 +1,7 @@ use libc::c_uint; use ffi; use foreign_types::ForeignTypeRef; +use std::net::IpAddr; use cvt; use error::ErrorStack; @@ -43,4 +44,25 @@ impl X509VerifyParamRef { )).map(|_| ()) } } + + pub fn set_ip(&mut self, ip: IpAddr) -> Result<(), ErrorStack> { + unsafe { + let mut buf = [0; 16]; + let len = match ip { + IpAddr::V4(addr) => { + buf[..4].copy_from_slice(&addr.octets()); + 4 + } + IpAddr::V6(addr) => { + buf.copy_from_slice(&addr.octets()); + 16 + } + }; + cvt(ffi::X509_VERIFY_PARAM_set1_ip( + self.as_ptr(), + buf.as_ptr() as *const _, + len, + )).map(|_| ()) + } + } } |