diff options
| author | Benjamin Fry <[email protected]> | 2017-03-23 21:37:42 -0700 |
|---|---|---|
| committer | Bastian Köcher <[email protected]> | 2018-03-07 13:53:29 +0100 |
| commit | 3187366cc5fb8619dd496b9bfccaba8c66c6923f (patch) | |
| tree | a730079bf2c7e75335760cc32b0c176fdd9b1efe /openssl/src | |
| parent | Little tweaks (diff) | |
| download | rust-openssl-3187366cc5fb8619dd496b9bfccaba8c66c6923f.tar.xz rust-openssl-3187366cc5fb8619dd496b9bfccaba8c66c6923f.zip | |
restructure to self contained function
Diffstat (limited to 'openssl/src')
| -rw-r--r-- | openssl/src/x509/mod.rs | 15 | ||||
| -rw-r--r-- | openssl/src/x509/tests.rs | 5 |
2 files changed, 12 insertions, 8 deletions
diff --git a/openssl/src/x509/mod.rs b/openssl/src/x509/mod.rs index dcd4296a..5dd12b0e 100644 --- a/openssl/src/x509/mod.rs +++ b/openssl/src/x509/mod.rs @@ -112,13 +112,20 @@ impl X509StoreContextRef { } /// Verifies the certificate associated in the `init()` method + /// * `cert_chain` - the certificates chain /// - /// The context must be re-initialized before each call to this method. - pub fn verify_cert(&self) -> Result<Option<X509VerifyError>, ErrorStack> { + /// # Result + /// + /// The Result must be `Some(None)` to be a valid certificate, otherwise the cert is not valid. + pub fn verify_cert(trust: &store::X509StoreRef, cert: &X509Ref, cert_chain: &StackRef<X509>) -> Result<Option<X509VerifyError>, ErrorStack> { unsafe { - try!(cvt(ffi::X509_verify_cert(self.as_ptr())).map(|_| ())) + ffi::init(); + let context = try!(cvt_p(ffi::X509_STORE_CTX_new()).map(|p| X509StoreContext(p))); + try!(cvt(ffi::X509_STORE_CTX_init(context.as_ptr(), trust.as_ptr(), cert.as_ptr(), cert_chain.as_ptr())) + .map(|_| ())); + try!(cvt(ffi::X509_verify_cert(context.as_ptr())).map(|_| ())); + Ok(context.error()) } - Ok(self.error()) } /// Set the error code of the context. diff --git a/openssl/src/x509/tests.rs b/openssl/src/x509/tests.rs index 6ef4f18e..05baac12 100644 --- a/openssl/src/x509/tests.rs +++ b/openssl/src/x509/tests.rs @@ -303,8 +303,5 @@ fn test_verify_cert() { store_bldr.add_cert(ca).unwrap(); let store = store_bldr.build(); - let store_ctx = X509StoreContext::new().unwrap(); - store_ctx.init(&store, &cert, &Stack::new().unwrap()).unwrap(); - - assert!(store_ctx.verify_cert().unwrap().is_none()); + assert!(X509StoreContext::verify_cert(&store, &cert, &Stack::new().unwrap()).unwrap().is_none()); } |