This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: ssl module should not use textwrap for wrapping PEM format.
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: methane
Priority: normal Keywords: patch

Created on 2017-10-02 00:47 by methane, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 3849 merged methane, 2017-10-02 00:50
Messages (3)
msg303505 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2017-10-02 00:47
Current DER_cert_to_PEM_cert() uses textwrap like this:

    def DER_cert_to_PEM_cert(der_cert_bytes):
        """Takes a certificate in binary DER format and returns the
        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')

But textwrap is designed to break lines at word boundary.
So textwrap.fill for base64 text may be slow.

And `import textwrap` is little slow too.

We can use simple slicing instead of textwrap.
msg303506 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2017-10-02 00:53
For the record, this is part of `import requests`.
`import ssl` took 11 ms and `textwrap` weights 2.4 ms of it.

                    - ipaddress 2048 us (self 2048 us)
                    - textwrap 2402 us (self 2402 us)
                    - _ssl 2744 us (self 2744 us)
                        - _struct 232 us (self 232 us)
                      - struct 411 us (self 180 us)
                      - binascii 272 us (self 272 us)
                    - base64 997 us (self 315 us)
                  - ssl 11158 us (self 2969 us)
msg303512 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2017-10-02 07:33
New changeset b75a228af8c0553aef44e4e03763af90fbc8737f by INADA Naoki in branch 'master':
bpo-31659: Use simple slicing to format PEM cert (GH-3849)
https://github.com/python/cpython/commit/b75a228af8c0553aef44e4e03763af90fbc8737f
History
Date User Action Args
2022-04-11 14:58:53adminsetgithub: 75840
2019-02-21 11:07:19methanesetstatus: open -> closed
resolution: fixed
stage: needs patch -> resolved
2017-10-02 09:56:16christian.heimessetstatus: closed -> open
resolution: fixed -> (no value)
stage: resolved -> needs patch
2017-10-02 07:34:03methanesetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2017-10-02 07:33:47methanesetmessages: + msg303512
2017-10-02 00:53:20methanesetmessages: + msg303506
2017-10-02 00:50:39methanesetkeywords: + patch
stage: patch review
pull_requests: + pull_request3829
2017-10-02 00:47:49methanesetcomponents: + Library (Lib)
versions: + Python 3.7
2017-10-02 00:47:34methanecreate