Skip to content

Commit 9b95636

Browse files
committed
Refine README and Remove usage example from ReadTheDocs.
1 parent 9fac18f commit 9b95636

4 files changed

Lines changed: 24 additions & 1477 deletions

File tree

README.md

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,35 @@ $ pip install cwt
2626

2727
And then, you can use it as follows:
2828

29-
```py
29+
**COSE API**
30+
31+
```pycon
32+
>>> from cwt import COSE, COSEKey
33+
>>> ctx = COSE.new()
34+
>>> mac_key = COSEKey.generate_symmetric_key(alg="HS256", kid="01")
35+
>>> encoded = ctx.encode_and_mac(b"Hello world!", mac_key, unprotected={"alg": "HS256"})
36+
>>> encoded.hex()
37+
'd18443a10105a1044230314c48656c6c6f20776f726c642158205d0b144add282ccaac32a02e0d5eec76928ccadf3623271eb48e9464e2ee03b2'
38+
>>> ctx.decode(encoded, mac_key)
39+
b'Hello world!'
40+
```
41+
42+
**CWT API**
43+
44+
```pycon
3045
>>> import cwt
3146
>>> from cwt import COSEKey
3247
>>> key = COSEKey.generate_symmetric_key(alg="HS256", kid="01")
33-
>>> token = cwt.{"iss": "coaps://as.example", "sub": "dajiaji", "cti": "123"}, key)
48+
>>> token = cwt.encode({"iss": "coaps://as.example", "sub": "dajiaji", "cti": "123"}, key)
3449
>>> token.hex()
3550
'd18443a10105a05835a60172636f6170733a2f2f61732e657861'...
3651
>>> cwt.decode(token, key)
3752
{1: 'coaps://as.example', 2: 'dajiaji', 7: b'123', 4: 1620088759, 5: 1620085159, 6: 1620085159}
3853
```
3954

40-
See [Documentation](https://python-cwt.readthedocs.io/en/stable/) for details.
55+
Various usage examples are shown in this README.
56+
57+
See [Documentation](https://python-cwt.readthedocs.io/en/stable/) for the details of API specification.
4158

4259
## Index
4360

@@ -89,10 +106,9 @@ pip install cwt
89106

90107
## COSE Usage Examples
91108

92-
Followings are typical and basic examples which create various types of COSE messages, verify and decode them.
109+
Followings are typical and basic examples which encode various types of COSE messages and decode them.
93110

94-
See [API Reference](https://python-cwt.readthedocs.io/en/stable/api.html#cwt.COSE) and
95-
[COSE Usage Examples on document](https://python-cwt.readthedocs.io/en/stable/cose_usage.html) for more details.
111+
See [API Reference](https://python-cwt.readthedocs.io/en/stable/api.html#cwt.COSE).
96112

97113
### COSE MAC0
98114

@@ -740,14 +756,12 @@ assert b"Hello world!" == recipient.decode(encoded, pub_key)
740756

741757
## CWT Usage Examples
742758

743-
Followings are typical and basic examples which create various types of CWTs, verify and decode them.
759+
Followings are typical and basic examples which encode various types of CWTs, verify and decode them.
744760

745761
[CWT API](https://python-cwt.readthedocs.io/en/stable/api.html) in the examples are built
746762
on top of [COSE API](https://python-cwt.readthedocs.io/en/stable/api.html#cwt.COSE).
747763

748-
See [API Reference](https://python-cwt.readthedocs.io/en/stable/api.html) and
749-
[CWT Usage Examples on document](https://python-cwt.readthedocs.io/en/stable/cwt_usage.html)
750-
for more details.
764+
See [API Reference](https://python-cwt.readthedocs.io/en/stable/api.html).
751765

752766
### MACed CWT
753767

0 commit comments

Comments
 (0)