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<'_>)
| 290 | /// |
| 291 | /// Format: ((('CN', 'example.com'),), (('O', 'Example Org'),), ...) |
| 292 | fn 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 | /// |
no test coverage detected