@@ -325,14 +325,11 @@ JWS (JSON Web Signature) to remain unencoded, without using base64 encoding.
325325To enable this option, you need to set the ``b64 `` header parameter to ``false ``
326326in the JWS header.
327327
328- To utilize the unencoded payload option in joserfc, you must import the
329- serialize and deserialize methods from ``joserfc.rfc7797 ``.
330-
331328Here are examples demonstrating the usage of the ``b64 `` option:
332329
333330.. code-block :: python
334331
335- from joserfc.rfc7797 import serialize_compact, deserialize_compact
332+ from joserfc.jws import serialize_compact, deserialize_compact
336333 from joserfc.jwk import OctKey
337334
338335 key = OctKey.import_key(" secret" )
@@ -351,7 +348,7 @@ characters, the compact serialization will detach the payload:
351348
352349.. code-block :: python
353350
354- from joserfc.rfc7797 import serialize_compact, deserialize_compact
351+ from joserfc.jws import serialize_compact, deserialize_compact
355352 from joserfc.jwk import OctKey
356353
357354 key = OctKey.import_key(" secret" )
@@ -362,5 +359,19 @@ characters, the compact serialization will detach the payload:
362359 # payload when calling deserialize_compact
363360 deserialize_compact(value, key, payload = " $.02" )
364361
365- There are also methods for JSON serialization: ``serialize_json `` and
362+ You can also use `` b64 `` header for JSON serialization: ``serialize_json `` and
366363``deserialize_json ``.
364+
365+ Guess Algorithms via Key
366+ ------------------------
367+
368+ If you are unsure which algorithm to use but already have a key, you can call the
369+ :meth: `jws.JWSRegistry.guess_alg ` method to determine a suitable algorithm:
370+
371+ .. code-block :: python
372+
373+ from joserfc.jws import JWSRegistry, serialize_compact
374+
375+ alg = JWSRegistry.guess_alg(key, JWSRegistry.Strategy.RECOMMENDED )
376+ protected = {" alg" : alg}
377+ serialize_compact(protected, b " payload" , key)
0 commit comments