@@ -19,7 +19,6 @@ use std::mem;
1919use std:: net:: IpAddr ;
2020use std:: path:: Path ;
2121use std:: ptr;
22- use std:: slice;
2322use std:: str;
2423use std:: sync:: { LazyLock , Once } ;
2524
@@ -1535,6 +1534,8 @@ impl X509VerifyError {
15351534 }
15361535
15371536 /// Return a human readable error string from the verification error.
1537+ ///
1538+ /// Returns empty string if the message was not UTF-8
15381539 #[ corresponds( X509_verify_cert_error_string ) ]
15391540 #[ allow( clippy:: trivially_copy_pass_by_ref) ]
15401541 #[ must_use]
@@ -1543,7 +1544,7 @@ impl X509VerifyError {
15431544
15441545 unsafe {
15451546 let s = ffi:: X509_verify_cert_error_string ( c_long:: from ( self . 0 ) ) ;
1546- str :: from_utf8 ( CStr :: from_ptr ( s) . to_bytes ( ) ) . unwrap ( )
1547+ CStr :: from_ptr ( s) . to_str ( ) . unwrap_or_default ( )
15471548 }
15481549 }
15491550}
@@ -1695,14 +1696,12 @@ impl GeneralNameRef {
16951696 return None ;
16961697 }
16971698
1698- let ptr = ASN1_STRING_get0_data ( ( * self . as_ptr ( ) ) . d . ia5 as * mut _ ) ;
1699- let len = ffi:: ASN1_STRING_length ( ( * self . as_ptr ( ) ) . d . ia5 as * mut _ ) ;
1699+ let asn = Asn1BitStringRef :: from_ptr ( ( * self . as_ptr ( ) ) . d . ia5 ) ;
17001700
1701- let slice = slice:: from_raw_parts ( ptr, len as usize ) ;
17021701 // IA5Strings are stated to be ASCII (specifically IA5). Hopefully
17031702 // OpenSSL checks that when loading a certificate but if not we'll
17041703 // use this instead of from_utf8_unchecked just in case.
1705- str :: from_utf8 ( slice ) . ok ( )
1704+ asn . to_str ( )
17061705 }
17071706 }
17081707
@@ -1732,10 +1731,7 @@ impl GeneralNameRef {
17321731 return None ;
17331732 }
17341733
1735- let ptr = ASN1_STRING_get0_data ( ( * self . as_ptr ( ) ) . d . ip as * mut _ ) ;
1736- let len = ffi:: ASN1_STRING_length ( ( * self . as_ptr ( ) ) . d . ip as * mut _ ) ;
1737-
1738- Some ( slice:: from_raw_parts ( ptr, len as usize ) )
1734+ Some ( Asn1BitStringRef :: from_ptr ( ( * self . as_ptr ( ) ) . d . ip ) . as_slice ( ) )
17391735 }
17401736 }
17411737}
@@ -1811,8 +1807,8 @@ impl Stackable for X509Object {
18111807use crate :: ffi:: { X509_get0_signature , X509_getm_notAfter , X509_getm_notBefore , X509_up_ref } ;
18121808
18131809use crate :: ffi:: {
1814- ASN1_STRING_get0_data , X509_ALGOR_get0 , X509_REQ_get_subject_name , X509_REQ_get_version ,
1815- X509_STORE_CTX_get0_chain , X509_set1_notAfter , X509_set1_notBefore ,
1810+ X509_ALGOR_get0 , X509_REQ_get_subject_name , X509_REQ_get_version , X509_STORE_CTX_get0_chain ,
1811+ X509_set1_notAfter , X509_set1_notBefore ,
18161812} ;
18171813
18181814use crate :: ffi:: X509_OBJECT_get0_X509 ;
0 commit comments