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

Function name_to_py

crates/stdlib/src/ssl/cert.rs:292–311  ·  view source on GitHub ↗

Convert an X509Name to Python nested tuple format for SSL certificate dicts Format: ((('CN', 'example.com'),), (('O', 'Example Org'),), ...)

(vm: &VirtualMachine, name: &x509_parser::x509::X509Name<'_>)

Source from the content-addressed store, hash-verified

290///
291/// Format: ((('CN', 'example.com'),), (('O', 'Example Org'),), ...)
292fn name_to_py(vm: &VirtualMachine, name: &x509_parser::x509::X509Name<'_>) -> PyResult {
293 let list: Vec<PyObjectRef> = name
294 .iter()
295 .flat_map(|rdn| {
296 // Each RDN can have multiple attributes
297 rdn.iter()
298 .map(|attr| {
299 let oid_str = attr.attr_type().to_id_string();
300 let value_str = attr.attr_value().as_str().unwrap_or("").to_string();
301 let key = oid_to_attribute_name(&oid_str);
302
303 vm.new_tuple((vm.new_tuple((vm.ctx.new_str(key), vm.ctx.new_str(value_str))),))
304 .into()
305 })
306 .collect::<Vec<_>>()
307 })
308 .collect();
309
310 Ok(vm.ctx.new_tuple(list).into())
311}
312
313/// Convert DER-encoded certificate to Python dict (for getpeercert with binary_form=False)
314///

Callers 1

cert_to_dictFunction · 0.70

Calls 8

oid_to_attribute_nameFunction · 0.85
collectMethod · 0.80
to_stringMethod · 0.80
iterMethod · 0.45
mapMethod · 0.45
as_strMethod · 0.45
new_tupleMethod · 0.45
new_strMethod · 0.45

Tested by

no test coverage detected