tabs to spaces

This commit is contained in:
Jethro Beekman 2015-06-30 23:30:45 -07:00
parent 93eb0cfa2d
commit f9a836fae9
1 changed files with 76 additions and 76 deletions

View File

@ -7,12 +7,12 @@ use nid::Nid;
/// variants. /// variants.
#[derive(Clone,Hash,PartialEq,Eq)] #[derive(Clone,Hash,PartialEq,Eq)]
pub enum ExtensionType { pub enum ExtensionType {
KeyUsage, KeyUsage,
ExtKeyUsage, ExtKeyUsage,
SubjectAltName, SubjectAltName,
IssuerAltName, IssuerAltName,
OtherNid(Nid), OtherNid(Nid),
OtherStr(String), OtherStr(String),
} }
/// A X.509 v3 certificate extension. /// A X.509 v3 certificate extension.
@ -21,70 +21,70 @@ pub enum ExtensionType {
/// See RFC 3280 for more information about extensions. /// See RFC 3280 for more information about extensions.
#[derive(Clone)] #[derive(Clone)]
pub enum Extension { pub enum Extension {
/// The purposes of the key contained in the certificate /// The purposes of the key contained in the certificate
KeyUsage(Vec<KeyUsageOption>), KeyUsage(Vec<KeyUsageOption>),
/// The extended purposes of the key contained in the certificate /// The extended purposes of the key contained in the certificate
ExtKeyUsage(Vec<ExtKeyUsageOption>), ExtKeyUsage(Vec<ExtKeyUsageOption>),
/// Subject Alternative Names /// Subject Alternative Names
SubjectAltName(Vec<(AltNameOption,String)>), SubjectAltName(Vec<(AltNameOption,String)>),
/// Issuer Alternative Names /// Issuer Alternative Names
IssuerAltName(Vec<(AltNameOption,String)>), IssuerAltName(Vec<(AltNameOption,String)>),
/// Arbitrary extensions by NID. See `man x509v3_config` for value syntax. /// Arbitrary extensions by NID. See `man x509v3_config` for value syntax.
/// ///
/// You must not use this to add extensions which this enum can express directly. /// You must not use this to add extensions which this enum can express directly.
/// ///
/// ``` /// ```
/// use openssl::x509::extension::Extension::*; /// use openssl::x509::extension::Extension::*;
/// use openssl::nid::Nid; /// use openssl::nid::Nid;
/// ///
/// # let generator = openssl::x509::X509Generator::new(); /// # let generator = openssl::x509::X509Generator::new();
/// generator.add_extension(OtherNid(Nid::BasicConstraints,"critical,CA:TRUE".to_owned())); /// generator.add_extension(OtherNid(Nid::BasicConstraints,"critical,CA:TRUE".to_owned()));
/// ``` /// ```
OtherNid(Nid,String), OtherNid(Nid,String),
/// Arbitrary extensions by OID string. See `man ASN1_generate_nconf` for value syntax. /// Arbitrary extensions by OID string. See `man ASN1_generate_nconf` for value syntax.
/// ///
/// You must not use this to add extensions which this enum can express directly. /// You must not use this to add extensions which this enum can express directly.
/// ///
/// ``` /// ```
/// use openssl::x509::extension::Extension::*; /// use openssl::x509::extension::Extension::*;
/// ///
/// # let generator = openssl::x509::X509Generator::new(); /// # let generator = openssl::x509::X509Generator::new();
/// generator.add_extension(OtherStr("2.999.2".to_owned(),"ASN1:UTF8:example value".to_owned())); /// generator.add_extension(OtherStr("2.999.2".to_owned(),"ASN1:UTF8:example value".to_owned()));
/// ``` /// ```
OtherStr(String,String), OtherStr(String,String),
} }
impl Extension { impl Extension {
pub fn get_type(&self) -> ExtensionType { pub fn get_type(&self) -> ExtensionType {
match self { match self {
&Extension::KeyUsage(_) => ExtensionType::KeyUsage, &Extension::KeyUsage(_) => ExtensionType::KeyUsage,
&Extension::ExtKeyUsage(_) => ExtensionType::ExtKeyUsage, &Extension::ExtKeyUsage(_) => ExtensionType::ExtKeyUsage,
&Extension::SubjectAltName(_) => ExtensionType::SubjectAltName, &Extension::SubjectAltName(_) => ExtensionType::SubjectAltName,
&Extension::IssuerAltName(_) => ExtensionType::IssuerAltName, &Extension::IssuerAltName(_) => ExtensionType::IssuerAltName,
&Extension::OtherNid(nid,_) => ExtensionType::OtherNid(nid), &Extension::OtherNid(nid,_) => ExtensionType::OtherNid(nid),
&Extension::OtherStr(ref s,_) => ExtensionType::OtherStr(s.clone()), &Extension::OtherStr(ref s,_) => ExtensionType::OtherStr(s.clone()),
} }
} }
} }
impl ExtensionType { impl ExtensionType {
pub fn get_nid(&self) -> Option<Nid> { pub fn get_nid(&self) -> Option<Nid> {
match self { match self {
&ExtensionType::KeyUsage => Some(Nid::KeyUsage), &ExtensionType::KeyUsage => Some(Nid::KeyUsage),
&ExtensionType::ExtKeyUsage => Some(Nid::ExtendedKeyUsage), &ExtensionType::ExtKeyUsage => Some(Nid::ExtendedKeyUsage),
&ExtensionType::SubjectAltName => Some(Nid::SubjectAltName), &ExtensionType::SubjectAltName => Some(Nid::SubjectAltName),
&ExtensionType::IssuerAltName => Some(Nid::IssuerAltName), &ExtensionType::IssuerAltName => Some(Nid::IssuerAltName),
&ExtensionType::OtherNid(nid) => Some(nid), &ExtensionType::OtherNid(nid) => Some(nid),
&ExtensionType::OtherStr(_) => None, &ExtensionType::OtherStr(_) => None,
} }
} }
pub fn get_name<'a>(&'a self) -> Option<&'a str> { pub fn get_name<'a>(&'a self) -> Option<&'a str> {
match self { match self {
&ExtensionType::OtherStr(ref s) => Some(s), &ExtensionType::OtherStr(ref s) => Some(s),
_ => None, _ => None,
} }
} }
} }
// FIXME: This would be nicer as a method on Iterator<Item=ToString>. This can // FIXME: This would be nicer as a method on Iterator<Item=ToString>. This can
@ -99,14 +99,14 @@ fn join<I: Iterator<Item=T>,T: ToString>(iter: I, sep: &str) -> String {
impl ToString for Extension { impl ToString for Extension {
fn to_string(&self) -> String { fn to_string(&self) -> String {
match self { match self {
&Extension::KeyUsage(ref purposes) => join(purposes.iter(),","), &Extension::KeyUsage(ref purposes) => join(purposes.iter(),","),
&Extension::ExtKeyUsage(ref purposes) => join(purposes.iter(),","), &Extension::ExtKeyUsage(ref purposes) => join(purposes.iter(),","),
&Extension::SubjectAltName(ref names) => join(names.iter().map(|&(ref opt,ref val)|opt.to_string()+":"+&val),","), &Extension::SubjectAltName(ref names) => join(names.iter().map(|&(ref opt,ref val)|opt.to_string()+":"+&val),","),
&Extension::IssuerAltName(ref names) => join(names.iter().map(|&(ref opt,ref val)|opt.to_string()+":"+&val),","), &Extension::IssuerAltName(ref names) => join(names.iter().map(|&(ref opt,ref val)|opt.to_string()+":"+&val),","),
&Extension::OtherNid(_,ref value) => value.clone(), &Extension::OtherNid(_,ref value) => value.clone(),
&Extension::OtherStr(_,ref value) => value.clone(), &Extension::OtherStr(_,ref value) => value.clone(),
} }
} }
} }
@ -178,7 +178,7 @@ impl fmt::Display for ExtKeyUsageOption {
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
pub enum AltNameOption { pub enum AltNameOption {
/// The value is specified as OID;content. See `man ASN1_generate_nconf` for more information on the content syntax. /// The value is specified as OID;content. See `man ASN1_generate_nconf` for more information on the content syntax.
/// ///
/// ``` /// ```
/// use openssl::x509::extension::Extension::*; /// use openssl::x509::extension::Extension::*;
/// use openssl::x509::extension::AltNameOption::Other as OtherName; /// use openssl::x509::extension::AltNameOption::Other as OtherName;
@ -186,27 +186,27 @@ pub enum AltNameOption {
/// # let generator = openssl::x509::X509Generator::new(); /// # let generator = openssl::x509::X509Generator::new();
/// generator.add_extension(SubjectAltName(vec![(OtherName,"2.999.3;ASN1:UTF8:some other name".to_owned())])); /// generator.add_extension(SubjectAltName(vec![(OtherName,"2.999.3;ASN1:UTF8:some other name".to_owned())]));
/// ``` /// ```
Other, Other,
Email, Email,
DNS, DNS,
//X400, // Not supported by OpenSSL //X400, // Not supported by OpenSSL
Directory, Directory,
//EDIParty, // Not supported by OpenSSL //EDIParty, // Not supported by OpenSSL
URI, URI,
IPAddress, IPAddress,
RegisteredID, RegisteredID,
} }
impl fmt::Display for AltNameOption { impl fmt::Display for AltNameOption {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
f.pad(match self { f.pad(match self {
&AltNameOption::Other => "otherName", &AltNameOption::Other => "otherName",
&AltNameOption::Email => "email", &AltNameOption::Email => "email",
&AltNameOption::DNS => "DNS", &AltNameOption::DNS => "DNS",
&AltNameOption::Directory => "dirName", &AltNameOption::Directory => "dirName",
&AltNameOption::URI => "URI", &AltNameOption::URI => "URI",
&AltNameOption::IPAddress => "IP", &AltNameOption::IPAddress => "IP",
&AltNameOption::RegisteredID => "RID", &AltNameOption::RegisteredID => "RID",
}) })
} }
} }