Minor doc fixes and feature mentions

This commit is contained in:
Valerii Hiora 2014-10-08 09:06:16 +03:00
parent c9eef510ce
commit 6f399239d8
3 changed files with 26 additions and 7 deletions

View File

@ -43,7 +43,7 @@ impl MemBio {
/// Consumes current bio and returns wrapped value /// Consumes current bio and returns wrapped value
/// Note that data ownership is lost and /// Note that data ownership is lost and
/// should be handled manually /// should be managed manually
pub unsafe fn unwrap(mut self) -> *mut ffi::BIO { pub unsafe fn unwrap(mut self) -> *mut ffi::BIO {
self.owned = false; self.owned = false;
self.bio self.bio

View File

@ -45,17 +45,19 @@ fn init() {
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
pub enum SslMethod { pub enum SslMethod {
#[cfg(feature = "sslv2")] #[cfg(feature = "sslv2")]
/// Only support the SSLv2 protocol /// Only support the SSLv2 protocol, requires `feature="sslv2"`
Sslv2, Sslv2,
/// Support the SSLv2, SSLv3 and TLSv1 protocols
Sslv23,
/// Only support the SSLv3 protocol /// Only support the SSLv3 protocol
Sslv3, Sslv3,
/// Only support the TLSv1 protocol /// Only support the TLSv1 protocol
Tlsv1, Tlsv1,
/// Support the SSLv2, SSLv3 and TLSv1 protocols
Sslv23,
#[cfg(feature = "tlsv1_1")] #[cfg(feature = "tlsv1_1")]
/// Support TLSv1.1 protocol, requires `feature="tlsv1_1"`
Tlsv1_1, Tlsv1_1,
#[cfg(feature = "tlsv1_2")] #[cfg(feature = "tlsv1_2")]
/// Support TLSv1.2 protocol, requires `feature="tlsv1_2"`
Tlsv1_2, Tlsv1_2,
} }
@ -256,7 +258,7 @@ impl SslContext {
})) }))
} }
/// Specifies the file that is client certificate /// Specifies the file that contains certificate
pub fn set_certificate_file(&mut self, file: &Path, pub fn set_certificate_file(&mut self, file: &Path,
file_type: X509FileType) -> Option<SslError> { file_type: X509FileType) -> Option<SslError> {
wrap_ssl_result(file.with_c_str(|file| { wrap_ssl_result(file.with_c_str(|file| {
@ -266,7 +268,7 @@ impl SslContext {
})) }))
} }
/// Specifies the file that is client private key /// Specifies the file that contains private key
pub fn set_private_key_file(&mut self, file: &Path, pub fn set_private_key_file(&mut self, file: &Path,
file_type: X509FileType) -> Option<SslError> { file_type: X509FileType) -> Option<SslError> {
wrap_ssl_result(file.with_c_str(|file| { wrap_ssl_result(file.with_c_str(|file| {

View File

@ -45,6 +45,7 @@ impl X509StoreContext {
} }
} }
#[doc(hidden)]
trait AsStr<'a> { trait AsStr<'a> {
fn as_str(&self) -> &'a str; fn as_str(&self) -> &'a str;
} }
@ -116,6 +117,7 @@ impl AsStr<'static> for ExtKeyUsage {
// FIXME: a dirty hack as there is no way to // FIXME: a dirty hack as there is no way to
// implement ToString for Vec as both are defined // implement ToString for Vec as both are defined
// in another crate // in another crate
#[doc(hidden)]
trait ToStr { trait ToStr {
fn to_str(&self) -> String; fn to_str(&self) -> String;
} }
@ -141,6 +143,15 @@ pub struct X509Generator {
} }
impl X509Generator { impl X509Generator {
/// Creates a new generator with the following defaults:
///
/// bit length: 1024
///
/// validity period: 365 days
///
/// CN: "rust-openssl"
///
/// hash: SHA1
pub fn new() -> X509Generator { pub fn new() -> X509Generator {
X509Generator { X509Generator {
bits: 1024, bits: 1024,
@ -152,27 +163,32 @@ impl X509Generator {
} }
} }
/// Sets desired bit length
pub fn set_bitlength(mut self, bits: uint) -> X509Generator { pub fn set_bitlength(mut self, bits: uint) -> X509Generator {
self.bits = bits; self.bits = bits;
self self
} }
/// Sets certificate validity period in days since today
pub fn set_valid_period(mut self, days: uint) -> X509Generator { pub fn set_valid_period(mut self, days: uint) -> X509Generator {
self.days = days; self.days = days;
self self
} }
#[allow(non_snake_case)] #[allow(non_snake_case)]
/// Sets Common Name of certificate
pub fn set_CN(mut self, CN: &str) -> X509Generator { pub fn set_CN(mut self, CN: &str) -> X509Generator {
self.CN = CN.to_string(); self.CN = CN.to_string();
self self
} }
/// Sets what for certificate could be used
pub fn set_usage(mut self, purposes: &[KeyUsage]) -> X509Generator { pub fn set_usage(mut self, purposes: &[KeyUsage]) -> X509Generator {
self.key_usage = purposes.to_vec(); self.key_usage = purposes.to_vec();
self self
} }
/// Sets allowed extended usage of certificate
pub fn set_ext_usage(mut self, purposes: &[ExtKeyUsage]) -> X509Generator { pub fn set_ext_usage(mut self, purposes: &[ExtKeyUsage]) -> X509Generator {
self.ext_key_usage = purposes.to_vec(); self.ext_key_usage = purposes.to_vec();
self self
@ -224,6 +240,7 @@ impl X509Generator {
res res
} }
/// Generates a private key and a signed certificate and returns them
pub fn generate<'a>(&self) -> Result<(X509<'a>, PKey), SslError> { pub fn generate<'a>(&self) -> Result<(X509<'a>, PKey), SslError> {
let mut p_key = PKey::new(); let mut p_key = PKey::new();
p_key.gen(self.bits); p_key.gen(self.bits);
@ -315,7 +332,7 @@ impl<'ctx> X509<'ctx> {
let mut mem_bio = try!(MemBio::new()); let mut mem_bio = try!(MemBio::new());
unsafe { unsafe {
try_ssl!(ffi::PEM_write_bio_X509(mem_bio.get_handle(), try_ssl!(ffi::PEM_write_bio_X509(mem_bio.get_handle(),
self.handle)); self.handle));
} }
let buf = try!(mem_bio.read_to_end().map_err(StreamError)); let buf = try!(mem_bio.read_to_end().map_err(StreamError));
writer.write(buf.as_slice()).map_err(StreamError) writer.write(buf.as_slice()).map_err(StreamError)