MCPcopy Index your code
hub / github.com/RustPython/RustPython / obj2txt

Function obj2txt

crates/stdlib/src/openssl/cert.rs:29–54  ·  view source on GitHub ↗
(obj: &Asn1ObjectRef, no_name: bool)

Source from the content-addressed store, hash-verified

27 use crate::openssl::_ssl::{ENCODING_DER, ENCODING_PEM, convert_openssl_error};
28
29 pub(crate) fn obj2txt(obj: &Asn1ObjectRef, no_name: bool) -> Option<String> {
30 let no_name = i32::from(no_name);
31 let ptr = obj.as_ptr();
32 let b = unsafe {
33 let buflen = sys::OBJ_obj2txt(std::ptr::null_mut(), 0, ptr, no_name);
34 assert!(buflen >= 0);
35 if buflen == 0 {
36 return None;
37 }
38 let buflen = buflen as usize;
39 let mut buf = Vec::<u8>::with_capacity(buflen + 1);
40 let ret = sys::OBJ_obj2txt(
41 buf.as_mut_ptr() as *mut libc::c_char,
42 buf.capacity() as _,
43 ptr,
44 no_name,
45 );
46 assert!(ret >= 0);
47 // SAFETY: OBJ_obj2txt initialized the buffer successfully
48 buf.set_len(buflen);
49 buf
50 };
51 let s = String::from_utf8(b)
52 .unwrap_or_else(|e| String::from_utf8_lossy(e.as_bytes()).into_owned());
53 Some(s)
54 }
55
56 #[pyattr]
57 #[pyclass(module = "ssl", name = "Certificate")]

Callers 4

obj2pyFunction · 0.85
repr_strMethod · 0.85
name_to_pyFunction · 0.85
cert_to_dictFunction · 0.85

Calls 7

as_mut_ptrMethod · 0.80
set_lenMethod · 0.80
into_ownedMethod · 0.80
SomeClass · 0.50
as_ptrMethod · 0.45
capacityMethod · 0.45
as_bytesMethod · 0.45

Tested by

no test coverage detected