mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-02 11:41:02 -06:00
py3: strip_header: support both bytes and unicode
Various method passed various bytes or unicode as parameter https://fedorahosted.org/freeipa/ticket/4985 Reviewed-By: Christian Heimes <cheimes@redhat.com>
This commit is contained in:
parent
47e76e16ef
commit
b8d6524d43
@ -85,12 +85,16 @@ def strip_header(pem):
|
||||
"""
|
||||
Remove the header and footer from a certificate.
|
||||
"""
|
||||
s = pem.find("-----BEGIN CERTIFICATE-----")
|
||||
if s >= 0:
|
||||
e = pem.find("-----END CERTIFICATE-----")
|
||||
pem = pem[s+27:e]
|
||||
|
||||
return pem
|
||||
regexp = (
|
||||
u"^-----BEGIN CERTIFICATE-----(.*?)-----END CERTIFICATE-----"
|
||||
)
|
||||
if isinstance(pem, bytes):
|
||||
regexp = regexp.encode('ascii')
|
||||
s = re.search(regexp, pem, re.MULTILINE | re.DOTALL)
|
||||
if s is not None:
|
||||
return s.group(1)
|
||||
else:
|
||||
return pem
|
||||
|
||||
|
||||
def load_certificate(data, datatype=PEM):
|
||||
|
Loading…
Reference in New Issue
Block a user