Fixes in response to review feedback.

This commit is contained in:
Jacob Hoffman-Andrews 2020-05-31 20:03:37 -07:00
parent 6482f419b8
commit 1aff5b9198
4 changed files with 28 additions and 28 deletions

View File

@ -67,15 +67,17 @@ foreign_type_and_impl_send_sync! {
impl fmt::Display for Asn1GeneralizedTimeRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
unsafe {
match MemBio::new() {
let mem_bio = match MemBio::new() {
Err(_) => return f.write_str(""),
Ok(m) => m,
};
let print_result = cvt(ffi::ASN1_GENERALIZEDTIME_print(
mem_bio.as_ptr(),
self.as_ptr(),
));
match print_result {
Err(_) => f.write_str(""),
Ok(mem_bio) => match cvt(ffi::ASN1_GENERALIZEDTIME_print(
mem_bio.as_ptr(),
self.as_ptr(),
)) {
Err(_) => f.write_str(""),
Ok(_) => f.write_str(str::from_utf8_unchecked(mem_bio.get_buf())),
},
Ok(_) => f.write_str(str::from_utf8_unchecked(mem_bio.get_buf())),
}
}
}
@ -211,12 +213,14 @@ impl<'a> PartialOrd<Asn1Time> for &'a Asn1TimeRef {
impl fmt::Display for Asn1TimeRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
unsafe {
match MemBio::new() {
let mem_bio = match MemBio::new() {
Err(_) => return f.write_str("error"),
Ok(m) => m,
};
let print_result = cvt(ffi::ASN1_TIME_print(mem_bio.as_ptr(), self.as_ptr()));
match print_result {
Err(_) => f.write_str("error"),
Ok(mem_bio) => match cvt(ffi::ASN1_TIME_print(mem_bio.as_ptr(), self.as_ptr())) {
Err(_) => f.write_str("error"),
Ok(_) => f.write_str(str::from_utf8_unchecked(mem_bio.get_buf())),
},
Ok(_) => f.write_str(str::from_utf8_unchecked(mem_bio.get_buf())),
}
}
}

View File

@ -301,9 +301,7 @@ impl<T> fmt::Debug for PKey<T> {
Id::ED448 => "Ed448",
_ => "unknown",
};
fmt.debug_struct("public_key")
.field("algorithm", &alg)
.finish()
fmt.debug_struct("PKey").field("algorithm", &alg).finish()
// TODO: Print details for each specific type of key
}
}

View File

@ -1342,19 +1342,17 @@ impl GeneralNameRef {
impl fmt::Debug for GeneralNameRef {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
if let Some(email) = self.email() {
return formatter.write_str(email);
}
if let Some(dnsname) = self.dnsname() {
return formatter.write_str(dnsname);
}
if let Some(uri) = self.uri() {
return formatter.write_str(uri);
}
if let Some(ipaddress) = self.ipaddress() {
formatter.write_str(email)
} else if let Some(dnsname) = self.dnsname() {
formatter.write_str(dnsname)
} else if let Some(uri) = self.uri() {
formatter.write_str(uri)
} else if let Some(ipaddress) = self.ipaddress() {
let result = String::from_utf8_lossy(ipaddress);
return formatter.write_str(&result);
formatter.write_str(&result)
} else {
formatter.write_str("(empty)")
}
Ok(())
}
}

View File

@ -52,7 +52,7 @@ fn test_debug() {
],
not_before: Aug 14 17:00:03 2016 GMT,
not_after: Aug 12 17:00:03 2026 GMT,
public_key: public_key {
public_key: PKey {
algorithm: "RSA",
},
}"#;