@@ -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
@@ -1542,6 +1541,8 @@ impl X509VerifyError {
15421541 }
15431542
15441543 /// Return a human readable error string from the verification error.
1544+ ///
1545+ /// Returns empty string if the message was not UTF-8
15451546 #[ corresponds( X509_verify_cert_error_string ) ]
15461547 #[ allow( clippy:: trivially_copy_pass_by_ref) ]
15471548 #[ must_use]
@@ -1550,7 +1551,7 @@ impl X509VerifyError {
15501551
15511552 unsafe {
15521553 let s = ffi:: X509_verify_cert_error_string ( c_long:: from ( self . 0 ) ) ;
1553- str :: from_utf8 ( CStr :: from_ptr ( s) . to_bytes ( ) ) . unwrap ( )
1554+ CStr :: from_ptr ( s) . to_str ( ) . unwrap_or_default ( )
15541555 }
15551556 }
15561557}
@@ -1702,14 +1703,12 @@ impl GeneralNameRef {
17021703 return None ;
17031704 }
17041705
1705- let ptr = ASN1_STRING_get0_data ( ( * self . as_ptr ( ) ) . d . ia5 as * mut _ ) ;
1706- let len = ffi:: ASN1_STRING_length ( ( * self . as_ptr ( ) ) . d . ia5 as * mut _ ) ;
1706+ let asn = Asn1BitStringRef :: from_ptr ( ( * self . as_ptr ( ) ) . d . ia5 ) ;
17071707
1708- let slice = slice:: from_raw_parts ( ptr, len as usize ) ;
17091708 // IA5Strings are stated to be ASCII (specifically IA5). Hopefully
17101709 // OpenSSL checks that when loading a certificate but if not we'll
17111710 // use this instead of from_utf8_unchecked just in case.
1712- str :: from_utf8 ( slice ) . ok ( )
1711+ asn . to_str ( )
17131712 }
17141713 }
17151714
@@ -1739,10 +1738,7 @@ impl GeneralNameRef {
17391738 return None ;
17401739 }
17411740
1742- let ptr = ASN1_STRING_get0_data ( ( * self . as_ptr ( ) ) . d . ip as * mut _ ) ;
1743- let len = ffi:: ASN1_STRING_length ( ( * self . as_ptr ( ) ) . d . ip as * mut _ ) ;
1744-
1745- Some ( slice:: from_raw_parts ( ptr, len as usize ) )
1741+ Some ( Asn1BitStringRef :: from_ptr ( ( * self . as_ptr ( ) ) . d . ip ) . as_slice ( ) )
17461742 }
17471743 }
17481744}
@@ -1818,8 +1814,8 @@ impl Stackable for X509Object {
18181814use crate :: ffi:: { X509_get0_signature , X509_getm_notAfter , X509_getm_notBefore , X509_up_ref } ;
18191815
18201816use crate :: ffi:: {
1821- ASN1_STRING_get0_data , X509_ALGOR_get0 , X509_REQ_get_subject_name , X509_REQ_get_version ,
1822- X509_STORE_CTX_get0_chain , X509_set1_notAfter , X509_set1_notBefore ,
1817+ X509_ALGOR_get0 , X509_REQ_get_subject_name , X509_REQ_get_version , X509_STORE_CTX_get0_chain ,
1818+ X509_set1_notAfter , X509_set1_notBefore ,
18231819} ;
18241820
18251821use crate :: ffi:: X509_OBJECT_get0_X509 ;
0 commit comments