From 1aff5b9198ca510bbeed604a7c45c86c878a34ae Mon Sep 17 00:00:00 2001 From: Jacob Hoffman-Andrews Date: Sun, 31 May 2020 20:03:37 -0700 Subject: [PATCH] Fixes in response to review feedback. --- openssl/src/asn1.rs | 30 +++++++++++++++++------------- openssl/src/pkey.rs | 4 +--- openssl/src/x509/mod.rs | 20 +++++++++----------- openssl/src/x509/tests.rs | 2 +- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/openssl/src/asn1.rs b/openssl/src/asn1.rs index 43c92f1ff..2670ce779 100644 --- a/openssl/src/asn1.rs +++ b/openssl/src/asn1.rs @@ -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 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())), } } } diff --git a/openssl/src/pkey.rs b/openssl/src/pkey.rs index 7af13c090..c8be33ca9 100644 --- a/openssl/src/pkey.rs +++ b/openssl/src/pkey.rs @@ -301,9 +301,7 @@ impl fmt::Debug for PKey { 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 } } diff --git a/openssl/src/x509/mod.rs b/openssl/src/x509/mod.rs index 047102bd1..39190b7ab 100644 --- a/openssl/src/x509/mod.rs +++ b/openssl/src/x509/mod.rs @@ -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(()) } } diff --git a/openssl/src/x509/tests.rs b/openssl/src/x509/tests.rs index 8db82fa54..3e3650b90 100644 --- a/openssl/src/x509/tests.rs +++ b/openssl/src/x509/tests.rs @@ -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", }, }"#; -- GitLab