diff options
| author | Steven Fackler <[email protected]> | 2015-01-09 20:17:47 -0800 |
|---|---|---|
| committer | Steven Fackler <[email protected]> | 2015-01-09 20:18:32 -0800 |
| commit | 2f5d1e579bb2f1c57862dc1dd06a9c26eca68e50 (patch) | |
| tree | b04a8d63eb1e190f67722c7ac908332ac3620927 /src | |
| parent | Fix doctest (diff) | |
| download | rust-openssl-2f5d1e579bb2f1c57862dc1dd06a9c26eca68e50.tar.xz rust-openssl-2f5d1e579bb2f1c57862dc1dd06a9c26eca68e50.zip | |
Add Show impls
Diffstat (limited to 'src')
| -rw-r--r-- | src/ssl/mod.rs | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/src/ssl/mod.rs b/src/ssl/mod.rs index d97f35c3..c4e41055 100644 --- a/src/ssl/mod.rs +++ b/src/ssl/mod.rs @@ -2,6 +2,7 @@ use libc::{c_int, c_void, c_long}; use std::ffi::{CString, c_str_to_bytes}; use std::io::{IoResult, IoError, EndOfFile, Stream, Reader, Writer}; use std::mem; +use std::fmt; use std::num::FromPrimitive; use std::ptr; use std::sync::{Once, ONCE_INIT, Arc}; @@ -33,9 +34,8 @@ fn init() { } /// Determines the SSL method supported -#[derive(Show, Hash, PartialEq, Eq)] #[allow(non_camel_case_types)] -#[derive(Copy)] +#[derive(Copy, Clone, Show, Hash, PartialEq, Eq)] pub enum SslMethod { #[cfg(feature = "sslv2")] /// Only support the SSLv2 protocol, requires `feature="sslv2"` @@ -71,7 +71,7 @@ impl SslMethod { } /// Determines the type of certificate verification used -#[derive(Copy)] +#[derive(Copy, Clone, Show)] #[repr(i32)] pub enum SslVerifyMode { /// Verify that the server's certificate is trusted @@ -177,6 +177,13 @@ pub struct SslContext { ctx: ptr::Unique<ffi::SSL_CTX> } +// TODO: add useful info here +impl fmt::Show for SslContext { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + write!(fmt, "SslContext") + } +} + impl Drop for SslContext { fn drop(&mut self) { unsafe { ffi::SSL_CTX_free(self.ctx.0) } @@ -293,6 +300,13 @@ pub struct Ssl { ssl: ptr::Unique<ffi::SSL> } +// TODO: put useful information here +impl fmt::Show for Ssl { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + write!(fmt, "Ssl") + } +} + impl Drop for Ssl { fn drop(&mut self) { unsafe { ffi::SSL_free(self.ssl.0) } @@ -412,6 +426,12 @@ pub struct SslStream<S> { buf: Vec<u8> } +impl<S> fmt::Show for SslStream<S> where S: fmt::Show { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + write!(fmt, "SslStream {{ stream: {:?}, ssl: {:?} }}", self.stream, self.ssl) + } +} + impl<S: Stream> SslStream<S> { fn new_base(ssl:Ssl, stream: S) -> SslStream<S> { SslStream { @@ -567,6 +587,7 @@ impl<S: Stream> Writer for SslStream<S> { } /// A utility type to help in cases where the use of SSL is decided at runtime. +#[derive(Show)] pub enum MaybeSslStream<S> where S: Stream { /// A connection using SSL Ssl(SslStream<S>), |