aboutsummaryrefslogtreecommitdiff
path: root/src/macros.rs
diff options
context:
space:
mode:
authorValerii Hiora <[email protected]>2014-09-24 19:17:17 +0300
committerValerii Hiora <[email protected]>2014-09-26 10:39:08 +0300
commit4fd169a1e5d465a10d5a815877479baa960a16eb (patch)
tree5ddc3e107274bdf72f00aeaeac67fc698b553473 /src/macros.rs
parentMerge pull request #46 from vhbit/tls1-2-support (diff)
downloadrust-openssl-4fd169a1e5d465a10d5a815877479baa960a16eb.tar.xz
rust-openssl-4fd169a1e5d465a10d5a815877479baa960a16eb.zip
Certificate/pkey generation & PEM export
Required quite a lot of refactoring
Diffstat (limited to 'src/macros.rs')
-rwxr-xr-xsrc/macros.rs61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/macros.rs b/src/macros.rs
new file mode 100755
index 00000000..b11f9dad
--- /dev/null
+++ b/src/macros.rs
@@ -0,0 +1,61 @@
+#![macro_escape]
+
+#[macro_export]
+macro_rules! try_ssl_stream {
+ ($e:expr) => (
+ match $e {
+ Ok(ok) => ok,
+ Err(err) => return Err(StreamError(err))
+ }
+ )
+}
+
+/// Shortcut return with SSL error if something went wrong
+#[macro_export]
+macro_rules! try_ssl_if {
+ ($e:expr) => (
+ if $e {
+ return Err(SslError::get())
+ }
+ )
+}
+
+/// Shortcut return with SSL error if last error result is 0
+/// (default)
+#[macro_export]
+macro_rules! try_ssl{
+ ($e:expr) => (try_ssl_if!($e == 0))
+}
+
+/// Shortcut return with SSL if got a null result
+#[macro_export]
+macro_rules! try_ssl_null{
+ ($e:expr) => (try_ssl_if!($e == ptr::null_mut()))
+}
+
+
+/// Lifts current SSL error code into Result<(), Error>
+/// if expression is true
+/// Lifting is actually a shortcut of the following form:
+///
+/// ```ignore
+/// let _ = try!(something)
+/// Ok(())
+/// ```
+#[macro_export]
+macro_rules! lift_ssl_if{
+ ($e:expr) => ( {
+ if $e {
+ Err(SslError::get())
+ } else {
+ Ok(())
+ }
+ })
+}
+
+/// Lifts current SSL error code into Result<(), Error>
+/// if SSL returned 0 (default error indication)
+#[macro_export]
+macro_rules! lift_ssl {
+ ($e:expr) => (lift_ssl_if!($e == 0))
+}