Skip to content

Commit 4629349

Browse files
committed
RFC 7468 allows a larger character set in PEM label
1 parent b763a75 commit 4629349

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

asn1crypto/pem.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ def armor(type_name, der_bytes, headers=None):
109109
return output.getvalue()
110110

111111

112+
# RFC 7468#page-5
113+
LABEL_CHARS = '[!-,.-~]' # 0x21-0x2C, 0x2E-0x7E
114+
LABEL_PAT = re.compile(f'^(?:---- |-----)BEGIN ({LABEL_CHARS}(([- ]?{LABEL_CHARS})*))?(?: ----|-----)'.encode('ascii'))
115+
116+
112117
def _unarmor(pem_bytes):
113118
"""
114119
Convert a PEM-encoded byte string into one or more DER-encoded byte strings
@@ -150,8 +155,9 @@ def _unarmor(pem_bytes):
150155

151156
if state == "trash":
152157
# Look for a starting line since some CA cert bundle show the cert
153-
# into in a parsed format above each PEM block
154-
type_name_match = re.match(b'^(?:---- |-----)BEGIN ([A-Z0-9 ]+)(?: ----|-----)', line)
158+
# info in a parsed format above each PEM block
159+
160+
type_name_match = LABEL_PAT.match(line)
155161
if not type_name_match:
156162
continue
157163
object_type = type_name_match.group(1).decode('ascii')

0 commit comments

Comments
 (0)