Skip to content

Commit 78b86d4

Browse files
author
Gasper Zejn
committed
Fix test issue on PyPy - turns out it was an issue with pycryptodome, which uses an incorrect marker to encode a RSA public key into PEM while using OID.
1 parent 4f16351 commit 78b86d4

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

jose/backends/pycrypto_backend.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,16 @@ def verify(self, msg, sig):
106106
return False
107107

108108
def public_key(self):
109-
if not self.prepared_key.key.has_private():
109+
if not self.prepared_key.has_private():
110110
return self
111111
return self.__class__(self.prepared_key.publickey(), self._algorithm)
112112

113113
def to_pem(self):
114-
return self.prepared_key.exportKey('PEM')
114+
pem = self.prepared_key.exportKey('PEM', pkcs=1)
115+
116+
# pycryptodome fix
117+
begin = b'-----BEGIN RSA PUBLIC KEY-----'
118+
end = b'-----END RSA PUBLIC KEY-----'
119+
if pem.startswith(begin) and pem.strip().endswith(end):
120+
pem = b'-----BEGIN PUBLIC KEY-----' + pem.strip()[len(begin):-len(end)] + b'-----END PUBLIC KEY-----\n'
121+
return pem

0 commit comments

Comments
 (0)