Skip to content

Commit 11dbee6

Browse files
committed
docs: update docstring for thumbprint and thumbprint_uri
1 parent 2c242f5 commit 11dbee6

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

src/joserfc/_rfc7638/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ def calculate_thumbprint(
99
value: t.Dict[str, t.Any],
1010
digest_method: t.Literal["sha256", "sha384", "sha512"] = "sha256",
1111
) -> str:
12+
"""Calculate the thumbprint value of a Key, per RFC 7638.
13+
14+
.. code-block:: python
15+
16+
from joserfc import jwk
17+
18+
jwk.thumbprint({
19+
'kty': 'oct',
20+
'k': 'sTBpI_oCHSyW-n0exSwhzNHwU9FGRioPauxWA84bnRU',
21+
})
22+
# 'DCdRGGDKvhAJgmVlCp6tosc2T9ELtd30S_15vn8bhrI'
23+
"""
1224
sorted_fields = sorted(value.keys())
1325
data = OrderedDict()
1426
for k in sorted_fields:

src/joserfc/_rfc9278/__init__.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,18 @@ def calculate_thumbprint_uri(
88
value: t.Dict[str, t.Any],
99
digest_method: t.Literal["sha256", "sha384", "sha512"] = "sha256",
1010
) -> str:
11-
"""Calculate JWK thumbprint URI, defined by RFC9278."""
11+
"""Calculate JWK thumbprint URI, defined by RFC9278.
12+
13+
.. code-block:: python
14+
15+
from joserfc import jwk
16+
17+
jwk.thumbprint({
18+
'kty': 'oct',
19+
'k': 'sTBpI_oCHSyW-n0exSwhzNHwU9FGRioPauxWA84bnRU',
20+
})
21+
# 'urn:ietf:params:oauth:jwk-thumbprint:sha-256:DCdRGGDKvhAJgmVlCp6tosc2T9ELtd30S_15vn8bhrI'
22+
"""
1223
thumbprint = calculate_thumbprint(value, digest_method=digest_method)
1324
return concat_thumbprint_uri(thumbprint, digest_method=digest_method)
1425

src/joserfc/jwk.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from ._rfc7518.ec_key import ECKey as ECKey
1313
from ._rfc8037.okp_key import OKPKey as OKPKey
1414
from ._rfc8812 import register_secp256k1
15+
from ._rfc7638 import calculate_thumbprint as thumbprint
1516
from ._rfc9278 import calculate_thumbprint_uri as thumbprint_uri
1617
from .registry import Header
1718

@@ -37,6 +38,7 @@
3738
"guess_key",
3839
"import_key",
3940
"generate_key",
41+
"thumbprint",
4042
"thumbprint_uri",
4143
]
4244

0 commit comments

Comments
 (0)