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 } +// 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 } +// 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 { buf: Vec } +impl fmt::Show for SslStream where S: fmt::Show { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + write!(fmt, "SslStream {{ stream: {:?}, ssl: {:?} }}", self.stream, self.ssl) + } +} + impl SslStream { fn new_base(ssl:Ssl, stream: S) -> SslStream { SslStream { @@ -567,6 +587,7 @@ impl Writer for SslStream { } /// A utility type to help in cases where the use of SSL is decided at runtime. +#[derive(Show)] pub enum MaybeSslStream where S: Stream { /// A connection using SSL Ssl(SslStream),