Skip to content

Commit

Permalink
docs: update docs for General and Flattend JSON data
Browse files Browse the repository at this point in the history
  • Loading branch information
lepture committed Jul 18, 2023
1 parent 76912f6 commit 0e8845e
Show file tree
Hide file tree
Showing 5 changed files with 250 additions and 208 deletions.
13 changes: 6 additions & 7 deletions docs/guide/jwe.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ Encryption
~~~~~~~~~~

The structure for JSON JWE serialization is a little complex, developers
SHOULD create an object of :class:`jwe.JSONEncryption` at first:
SHOULD create an object of :class:`jwe.GeneralJSONEncryption` at first:

.. code-block:: python
from joserfc.jwk import OctKey, RSAKey
from joserfc.jwe import JSONEncryption, encrypt_json
from joserfc.jwe import GeneralJSONEncryption, encrypt_json
obj = JSONEncryption({"enc": "A128GCM"}, b"hello")
obj = GeneralJSONEncryption({"enc": "A128GCM"}, b"hello")
# add first recipient with alg of A128KW
key1 = OctKey.generate_key(128)
Expand Down Expand Up @@ -192,13 +192,12 @@ The syntax of a JWE using the flattened JWE JSON Serialization is as follows:
}
It is flattened, it moves all the members out of the ``recipients`` field. To
``encrypt_json`` into a flattened serialization, you can just mark the
``JSONEncryption.flattened = True``:
``encrypt_json`` into a flattened serialization, you can construct a
:class`jwe.FlattenedJSONEncryption` instead:

.. code-block:: python
obj = JSONEncryption(protected, plaintext)
obj.flattened = True
obj = FlattenedJSONEncryption(protected, plaintext)
And make sure only adding one recipient.

Expand Down
3 changes: 2 additions & 1 deletion docs/guide/jws.rst
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ a list of members to construct a general serialization:
# general
jws.serialize_json([member], payload, private_key)
The returned value from ``deserialize_json`` is an object of :class:`jws.JSONSignature`,
The returned value from ``deserialize_json`` is an object of
:class:`jws.GeneralJSONSignature` or :class:`jws.FlattenedJSONSignature`,
you can tell if the signature is flattened or general with ``obj.flattened``:

.. code-block:: python
Expand Down
Loading

0 comments on commit 0e8845e

Please sign in to comment.