| 5098 | impl PySSLCertificate { |
| 5099 | #[pymethod] |
| 5100 | fn public_bytes( |
| 5101 | &self, |
| 5102 | format: OptionalArg<i32>, |
| 5103 | vm: &VirtualMachine, |
| 5104 | ) -> PyResult<PyObjectRef> { |
| 5105 | let format = format.unwrap_or(ENCODING_PEM); |
| 5106 | |
| 5107 | match format { |
| 5108 | x if x == ENCODING_DER => { |
| 5109 | // Return DER bytes directly |
| 5110 | Ok(vm.ctx.new_bytes(self.der_bytes.clone()).into()) |
| 5111 | } |
| 5112 | x if x == ENCODING_PEM => { |
| 5113 | // Convert DER to PEM using RFC 7468 compliant encoding |
| 5114 | let pem_str = encode_string("CERTIFICATE", LineEnding::LF, &self.der_bytes) |
| 5115 | .map_err(|e| vm.new_value_error(format!("PEM encoding failed: {e}")))?; |
| 5116 | Ok(vm.ctx.new_str(pem_str).into()) |
| 5117 | } |
| 5118 | _ => Err(vm.new_value_error("Unsupported format")), |
| 5119 | } |
| 5120 | } |
| 5121 | |
| 5122 | #[pymethod] |
| 5123 | fn get_info(&self, vm: &VirtualMachine) -> PyResult { |