Skip to content

Commit

Permalink
chore: SimoSoce code review
Browse files Browse the repository at this point in the history
  • Loading branch information
peppelinux committed Nov 28, 2023
1 parent d2c4537 commit df21fa5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions jwcrypto/jwa.py
Original file line number Diff line number Diff line change
Expand Up @@ -870,10 +870,10 @@ def verify(self, key, payload, signature):

class _RawJWE:

def encrypt(self, k, ai, m):
def encrypt(self, k, aa, m):
raise NotImplementedError

def decrypt(self, k, ai, iv, e, t):
def decrypt(self, k, aa, iv, e, t):
raise NotImplementedError


Expand Down
10 changes: 5 additions & 5 deletions jwcrypto/jwk.py
Original file line number Diff line number Diff line change
Expand Up @@ -1028,26 +1028,26 @@ def export_to_pem(self, private_key=False, password=False):
:return: A serialized bytes buffer containing a PEM formatted key.
:rtype: `bytes`
"""
_e = serialization.Encoding.PEM
enc = serialization.Encoding.PEM
if private_key:
if not self.has_private:
raise InvalidJWKType("No private key available")
f = serialization.PrivateFormat.PKCS8
if password is None:
_a = serialization.NoEncryption()
enc_alg = serialization.NoEncryption()
elif isinstance(password, bytes):
_a = serialization.BestAvailableEncryption(password)
enc_alg = serialization.BestAvailableEncryption(password)
elif password is False:
raise ValueError("The password must be None or a bytes string")
else:
raise TypeError("The password string must be bytes")
return self._get_private_key().private_bytes(
encoding=_e, format=f, encryption_algorithm=_a)
encoding=enc, format=f, encryption_algorithm=enc_alg)
else:
if not self.has_public:
raise InvalidJWKType("No public key available")
f = serialization.PublicFormat.SubjectPublicKeyInfo
return self._get_public_key().public_bytes(encoding=_e, format=f)
return self._get_public_key().public_bytes(encoding=enc, format=f)

@classmethod
def from_pyca(cls, key):
Expand Down
8 changes: 4 additions & 4 deletions jwcrypto/jws.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,14 +283,14 @@ def _verify(self, alg, key, payload, signature, protected, header=None):
'"alg" mismatch, requested'
f''' "{alg}", found "{p['alg']}"'''
)
_alg = alg
resulting_alg = alg
else:
_alg = p['alg']
resulting_alg = p['alg']

# the following will verify the "alg" is supported and the signature
# verifies
if isinstance(key, JWK):
signer = JWSCore(_alg, key, protected, payload, self._allowed_algs)
signer = JWSCore(resulting_alg, key, protected, payload, self._allowed_algs)
signer.verify(signature)
self.verifylog.append("Success")
elif isinstance(key, JWKSet):
Expand All @@ -305,7 +305,7 @@ def _verify(self, alg, key, payload, signature, protected, header=None):
for k in keys:
try:
signer2 = JWSCore(
_alg, k, protected,
resulting_alg, k, protected,
payload, self._allowed_algs
)
signer2.verify(signature)
Expand Down
8 changes: 4 additions & 4 deletions jwcrypto/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,10 +681,10 @@ def test_pem_okp(self):
pubkey = jwk.JWK.from_pem(Ed25519PublicPEM)
self.assertTrue(pubkey.has_public)
self.assertFalse(pubkey.has_private)
_jws = jws.JWS()
_jws.deserialize(sig, pubkey, alg="EdDSA")
self.assertTrue(_jws.objects['valid'])
self.assertEqual(_jws.payload, payload)
jws_token = jws.JWS()
jws_token.deserialize(sig, pubkey, alg="EdDSA")
self.assertTrue(jws_token.objects['valid'])
self.assertEqual(jws_token.payload, payload)

def test_jwk_as_dict(self):
key = jwk.JWK(**PublicKeys['keys'][0])
Expand Down

0 comments on commit df21fa5

Please sign in to comment.