diff options
| author | Valerii Hiora <[email protected]> | 2014-09-24 19:17:17 +0300 |
|---|---|---|
| committer | Valerii Hiora <[email protected]> | 2014-09-26 10:39:08 +0300 |
| commit | 4fd169a1e5d465a10d5a815877479baa960a16eb (patch) | |
| tree | 5ddc3e107274bdf72f00aeaeac67fc698b553473 /src/macros.rs | |
| parent | Merge pull request #46 from vhbit/tls1-2-support (diff) | |
| download | rust-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-x | src/macros.rs | 61 |
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)) +} |