summaryrefslogtreecommitdiff
path: root/Lib/ssl.py
diff options
context:
space:
mode:
authorINADA Naoki <methane@users.noreply.github.com>2017-10-02 16:33:42 +0900
committerGitHub <noreply@github.com>2017-10-02 16:33:42 +0900
commitb75a228af8c0553aef44e4e03763af90fbc8737f (patch)
tree557656c9ed12012c74c98c457b5a672df5fa4a52 /Lib/ssl.py
parentedc05c5d88c1ce853b3d04b34679ed7d69c2142a (diff)
downloadcpython-git-b75a228af8c0553aef44e4e03763af90fbc8737f.tar.gz
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.
Diffstat (limited to 'Lib/ssl.py')
-rw-r--r--Lib/ssl.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/Lib/ssl.py b/Lib/ssl.py
index 24f24b17bf..75caae0c44 100644
--- a/Lib/ssl.py
+++ b/Lib/ssl.py
@@ -91,7 +91,6 @@ ALERT_DESCRIPTION_UNKNOWN_PSK_IDENTITY
"""
import ipaddress
-import textwrap
import re
import sys
import os
@@ -1201,9 +1200,10 @@ def DER_cert_to_PEM_cert(der_cert_bytes):
PEM version of it as a string."""
f = str(base64.standard_b64encode(der_cert_bytes), 'ASCII', 'strict')
- return (PEM_HEADER + '\n' +
- textwrap.fill(f, 64) + '\n' +
- PEM_FOOTER + '\n')
+ ss = [PEM_HEADER]
+ ss += [f[i:i+64] for i in range(0, len(f), 64)]
+ ss.append(PEM_FOOTER + '\n')
+ return '\n'.join(ss)
def PEM_cert_to_DER_cert(pem_cert_string):
"""Takes a certificate in ASCII PEM format and returns the