Skip to content

Commit

Permalink
RFC 7468 allows a larger character set in PEM label
Browse files Browse the repository at this point in the history
  • Loading branch information
space88man committed Mar 20, 2024
1 parent b763a75 commit 322f8cd
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions asn1crypto/pem.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import base64
import re
import sys
import string

from ._errors import unwrap
from ._types import type_name as _type_name, str_cls, byte_cls
Expand Down Expand Up @@ -144,14 +145,19 @@ def _unarmor(pem_bytes):
found_start = False
found_end = False

# RFC 7468#page-5
label_chars = '[!-,.-~]' # 0x21-0x2C, 0x2E-0x7E
label_re = rf'''^(?:---- |-----)BEGIN ({label_chars}(([- ]?{label_chars})*))?(?: ----|-----)'''.encode('ascii')

for line in pem_bytes.splitlines(False):
if line == b'':
continue

if state == "trash":
# Look for a starting line since some CA cert bundle show the cert
# into in a parsed format above each PEM block
type_name_match = re.match(b'^(?:---- |-----)BEGIN ([A-Z0-9 ]+)(?: ----|-----)', line)
# info in a parsed format above each PEM block

type_name_match = re.match(label_re, line)
if not type_name_match:
continue
object_type = type_name_match.group(1).decode('ascii')
Expand Down

0 comments on commit 322f8cd

Please sign in to comment.