Skip to content

Commit 322f8cd

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

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
@@ -14,6 +14,7 @@
1414
import base64
1515
import re
1616
import sys
17+
import string
1718

1819
from ._errors import unwrap
1920
from ._types import type_name as _type_name, str_cls, byte_cls
@@ -144,14 +145,19 @@ def _unarmor(pem_bytes):
144145
found_start = False
145146
found_end = False
146147

148+
# RFC 7468#page-5
149+
label_chars = '[!-,.-~]' # 0x21-0x2C, 0x2E-0x7E
150+
label_re = rf'''^(?:---- |-----)BEGIN ({label_chars}(([- ]?{label_chars})*))?(?: ----|-----)'''.encode('ascii')
151+
147152
for line in pem_bytes.splitlines(False):
148153
if line == b'':
149154
continue
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 = re.match(label_re, line)
155161
if not type_name_match:
156162
continue
157163
object_type = type_name_match.group(1).decode('ascii')

0 commit comments

Comments
 (0)