Kaydet (Commit) b75a228a authored tarafından INADA Naoki's avatar INADA Naoki Kaydeden (comit) GitHub

bpo-31659: Use simple slicing to format PEM cert (GH-3849)

DER_cert_to_PEM_cert() used textwrap.fill() to format PEM.
But it's library to wrap lines on word boundary, while PEM is
base64 encoded string.

Additionally, importing textwrap is little slow.
üst edc05c5d
...@@ -91,7 +91,6 @@ ALERT_DESCRIPTION_UNKNOWN_PSK_IDENTITY ...@@ -91,7 +91,6 @@ ALERT_DESCRIPTION_UNKNOWN_PSK_IDENTITY
""" """
import ipaddress import ipaddress
import textwrap
import re import re
import sys import sys
import os import os
...@@ -1201,9 +1200,10 @@ def DER_cert_to_PEM_cert(der_cert_bytes): ...@@ -1201,9 +1200,10 @@ def DER_cert_to_PEM_cert(der_cert_bytes):
PEM version of it as a string.""" PEM version of it as a string."""
f = str(base64.standard_b64encode(der_cert_bytes), 'ASCII', 'strict') f = str(base64.standard_b64encode(der_cert_bytes), 'ASCII', 'strict')
return (PEM_HEADER + '\n' + ss = [PEM_HEADER]
textwrap.fill(f, 64) + '\n' + ss += [f[i:i+64] for i in range(0, len(f), 64)]
PEM_FOOTER + '\n') ss.append(PEM_FOOTER + '\n')
return '\n'.join(ss)
def PEM_cert_to_DER_cert(pem_cert_string): def PEM_cert_to_DER_cert(pem_cert_string):
"""Takes a certificate in ASCII PEM format and returns the """Takes a certificate in ASCII PEM format and returns the
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment