# py-libtrust - Yet another docker/libtrust implement by python.
Libtrust is library for managing authentication and authorization using public key cryptography.
Works for Python 3.6+.
## Usage
### Install
You can install from PyPi.
```bash
❯ pip install py-libtrust
```
### Example
#### Sign/Verify a jose-json-web-signature
```python
import datetime
from libtrust.keys.ec_key import generate_private_key
from libtrust.jsonsign import JSONSignature
# Generate a EC P256 private key
ec_key = generate_private_key("P-256")
your_content = {
"author": "shabbywu(shabbywu@qq.com)"
}
# New a JSONSignature
js = JSONSignature.new(your_content)
# signature
js.sign(ec_key, dt=datetime.datetime.utcfromtimestamp(0))
jws = js.to_jws()
loaded_js = JSONSignature.from_jws(jws)
assert js == loaded_js
assert js.verify() == loaded_js.verify()
```
#### Serialize/Deserialize a self-signed JSON signature
```python
import json
import datetime
from libtrust.keys.ec_key import generate_private_key
from libtrust.jsonsign import JSONSignature
# Generate a EC P256 private key
ec_key = generate_private_key("P-256")
your_content = {
"author": "shabbywu(shabbywu@qq.com)"
}
# New a JSONSignature
js = JSONSignature.new(your_content)
# signature
js.sign(ec_key, dt=datetime.datetime.utcfromtimestamp(0))
pretty_signature = js.to_pretty_signature("signatures")
loaded_js = js.from_pretty_signature(pretty_signature)
assert js.verify() == loaded_js.verify()
assert json.loads(pretty_signature)["author"] == "shabbywu(shabbywu@qq.com)"
```
## Copyright and license
Code and documentation copyright 2021 shabbywu(shabbywu@qq.com).
Code released under the Apache 2.0 license.
## Reference
- [docker/libtrust](https://github.com/distribution/distribution/tree/main/vendor/github.com/docker/libtrust)
- [realityone/libtrust-py](https://github.com/realityone/libtrust-py)
Raw data
{
"_id": null,
"home_page": "https://github.com/shabbywu/py-libtrust",
"name": "py-libtrust",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": null,
"author": "shabbywu",
"author_email": "shabbywu@qq.com",
"download_url": "https://files.pythonhosted.org/packages/13/14/d40bc16e7c88ca9b56ae0b1c061bb81289c7a4158967e1432115e5836b31/py_libtrust-2.1.1.tar.gz",
"platform": null,
"description": "# py-libtrust - Yet another docker/libtrust implement by python.\n\nLibtrust is library for managing authentication and authorization using public key cryptography.\n\nWorks for Python 3.6+.\n\n## Usage\n\n### Install\nYou can install from PyPi.\n\n```bash\n\u276f pip install py-libtrust\n```\n\n### Example\n#### Sign/Verify a jose-json-web-signature\n```python\nimport datetime\nfrom libtrust.keys.ec_key import generate_private_key\nfrom libtrust.jsonsign import JSONSignature\n\n# Generate a EC P256 private key\nec_key = generate_private_key(\"P-256\")\n\nyour_content = {\n \"author\": \"shabbywu(shabbywu@qq.com)\"\n}\n\n# New a JSONSignature\njs = JSONSignature.new(your_content)\n\n# signature\njs.sign(ec_key, dt=datetime.datetime.utcfromtimestamp(0))\n\njws = js.to_jws()\n\nloaded_js = JSONSignature.from_jws(jws)\n\nassert js == loaded_js\nassert js.verify() == loaded_js.verify()\n```\n\n#### Serialize/Deserialize a self-signed JSON signature\n```python\nimport json\nimport datetime\nfrom libtrust.keys.ec_key import generate_private_key\nfrom libtrust.jsonsign import JSONSignature\n\n# Generate a EC P256 private key\nec_key = generate_private_key(\"P-256\")\n\nyour_content = {\n \"author\": \"shabbywu(shabbywu@qq.com)\"\n}\n\n# New a JSONSignature\njs = JSONSignature.new(your_content)\n\n# signature\njs.sign(ec_key, dt=datetime.datetime.utcfromtimestamp(0))\n\npretty_signature = js.to_pretty_signature(\"signatures\")\nloaded_js = js.from_pretty_signature(pretty_signature)\n\nassert js.verify() == loaded_js.verify()\nassert json.loads(pretty_signature)[\"author\"] == \"shabbywu(shabbywu@qq.com)\"\n```\n\n## Copyright and license\n\nCode and documentation copyright 2021 shabbywu(shabbywu@qq.com). \nCode released under the Apache 2.0 license.\n\n## Reference\n\n- [docker/libtrust](https://github.com/distribution/distribution/tree/main/vendor/github.com/docker/libtrust)\n- [realityone/libtrust-py](https://github.com/realityone/libtrust-py)\n\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "Yet another docker/libtrust implement by python.",
"version": "2.1.1",
"project_urls": {
"Homepage": "https://github.com/shabbywu/py-libtrust",
"Repository": "https://github.com/shabbywu/py-libtrust"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "674de27323e9e2dee4596803f1ea06161e3a1324dc17f18dbc44da99fa23bcd1",
"md5": "3f3167caf778f3e3cbd54d94d19f98c9",
"sha256": "4aa27e068fb3feb01bf344829a6d066ba74788d09146f761872506737f362624"
},
"downloads": -1,
"filename": "py_libtrust-2.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "3f3167caf778f3e3cbd54d94d19f98c9",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 16522,
"upload_time": "2024-04-07T07:25:31",
"upload_time_iso_8601": "2024-04-07T07:25:31.726664Z",
"url": "https://files.pythonhosted.org/packages/67/4d/e27323e9e2dee4596803f1ea06161e3a1324dc17f18dbc44da99fa23bcd1/py_libtrust-2.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "1314d40bc16e7c88ca9b56ae0b1c061bb81289c7a4158967e1432115e5836b31",
"md5": "e34e2a405246fbf7ac3577a985e4da96",
"sha256": "b1e29f332965a2fe095e9a650b595d88ec53171f32e8a1f9dd3b5c9fbce083e5"
},
"downloads": -1,
"filename": "py_libtrust-2.1.1.tar.gz",
"has_sig": false,
"md5_digest": "e34e2a405246fbf7ac3577a985e4da96",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 13199,
"upload_time": "2024-04-07T07:25:33",
"upload_time_iso_8601": "2024-04-07T07:25:33.372181Z",
"url": "https://files.pythonhosted.org/packages/13/14/d40bc16e7c88ca9b56ae0b1c061bb81289c7a4158967e1432115e5836b31/py_libtrust-2.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-04-07 07:25:33",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "shabbywu",
"github_project": "py-libtrust",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "py-libtrust"
}