aboutsummaryrefslogtreecommitdiff
path: root/openssl/src/lib.rs
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2016-10-17 09:14:33 -0700
committerGitHub <[email protected]>2016-10-17 09:14:33 -0700
commitf6bf022cf214869fc5a4be80617759fe7ee89d8f (patch)
tree0a13df9c28a0a967ba7477979c2c0883aa6ef456 /openssl/src/lib.rs
parentMerge pull request #475 from sfackler/no-enums (diff)
parentFix missing import (diff)
downloadrust-openssl-f6bf022cf214869fc5a4be80617759fe7ee89d8f.tar.xz
rust-openssl-f6bf022cf214869fc5a4be80617759fe7ee89d8f.zip
Merge pull request #476 from sfackler/error-handling
Overhaul error handling plus random APIs
Diffstat (limited to 'openssl/src/lib.rs')
-rw-r--r--openssl/src/lib.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/openssl/src/lib.rs b/openssl/src/lib.rs
index 62968742..39c9fffe 100644
--- a/openssl/src/lib.rs
+++ b/openssl/src/lib.rs
@@ -16,6 +16,10 @@ extern crate tempdir;
#[doc(inline)]
pub use ffi::init;
+use libc::c_int;
+
+use error::ErrorStack;
+
mod macros;
pub mod asn1;
@@ -28,3 +32,27 @@ pub mod nid;
pub mod ssl;
pub mod version;
pub mod x509;
+
+pub fn cvt_p<T>(r: *mut T) -> Result<*mut T, ErrorStack> {
+ if r.is_null() {
+ Err(ErrorStack::get())
+ } else {
+ Ok(r)
+ }
+}
+
+pub fn cvt(r: c_int) -> Result<c_int, ErrorStack> {
+ if r <= 0 {
+ Err(ErrorStack::get())
+ } else {
+ Ok(r)
+ }
+}
+
+pub fn cvt_n(r: c_int) -> Result<c_int, ErrorStack> {
+ if r < 0 {
+ Err(ErrorStack::get())
+ } else {
+ Ok(r)
+ }
+}