Skip to content

Commit 289edfc

Browse files
author
Roland Hedberg
committed
Change soem usages of to_dict() to serialize() which makes sure no private information is divulged unless asked for.
1 parent b077247 commit 289edfc

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/jwkest/jwk.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ def __init__(self, kty="", alg="", use="", kid="", key=None, x5c=None,
222222
self.inactive_since = 0
223223

224224
def to_dict(self):
225+
"""
226+
A wrapper for to_dict the makes sure that all the private information
227+
as well as extra arguments are included. This method should *not* be
228+
used for exporting information about the key.
229+
"""
225230
res = self.serialize(private=True)
226231
res.update(self.extra_args)
227232
return res
@@ -249,7 +254,7 @@ def deserialize(self):
249254
def serialize(self, private=False):
250255
"""
251256
map key characteristics into attribute values that can be used
252-
to create an on-the-wire represntation of the key
257+
to create an on-the-wire representation of the key
253258
"""
254259
pass
255260

src/jwkest/jws.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,9 @@ def headers(self, extra=None):
308308
pass
309309

310310
if "jwk" in self:
311-
_header["jwk"] = self["jwk"].to_dict()
311+
_header["jwk"] = self["jwk"].serialize()
312312
elif "jwk" in _extra:
313-
_header["jwk"] = extra["jwk"].to_dict()
313+
_header["jwk"] = extra["jwk"].serialize()
314314

315315
if "kid" in self:
316316
try:

tests/test_3_jws.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ def test_a_1_3b():
287287
def test_jws_1():
288288
msg = {"iss": "joe", "exp": 1300819380, "http://example.com/is_root": True}
289289
key = SYMKey(key=jwkest.intarr2bin(HMAC_KEY))
290-
_jws = JWS(msg, cty="JWT", alg="HS256", jwk=key.to_dict())
290+
_jws = JWS(msg, cty="JWT", alg="HS256", jwk=key.serialize())
291291
res = _jws.sign_compact()
292292

293293
_jws2 = JWS(alg="HS256")

0 commit comments

Comments
 (0)