Skip to content

Commit 34aebe8

Browse files
Define initial class for EAR claimset along with its unit test, setup tox for testing (#3)
* Initialize project python-ear * Define initial class for EAR claimset along with its unit test, setup tox for testing * Use dataclasses for definition of EARClaims class * Remove cache files --------- Signed-off-by: HarshvMahawar <[email protected]>
1 parent eef1b15 commit 34aebe8

File tree

9 files changed

+286
-0
lines changed

9 files changed

+286
-0
lines changed

.gitignore

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
# .python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# UV
98+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99+
# This is especially recommended for binary packages to ensure reproducibility, and is more
100+
# commonly ignored for libraries.
101+
#uv.lock
102+
103+
# poetry
104+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105+
# This is especially recommended for binary packages to ensure reproducibility, and is more
106+
# commonly ignored for libraries.
107+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108+
#poetry.lock
109+
110+
# pdm
111+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
112+
#pdm.lock
113+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
114+
# in version control.
115+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
116+
.pdm.toml
117+
.pdm-python
118+
.pdm-build/
119+
120+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
121+
__pypackages__/
122+
123+
# Celery stuff
124+
celerybeat-schedule
125+
celerybeat.pid
126+
127+
# SageMath parsed files
128+
*.sage.py
129+
130+
# Environments
131+
.env
132+
.venv
133+
env/
134+
venv/
135+
ENV/
136+
env.bak/
137+
venv.bak/
138+
139+
# Spyder project settings
140+
.spyderproject
141+
.spyproject
142+
143+
# Rope project settings
144+
.ropeproject
145+
146+
# mkdocs documentation
147+
/site
148+
149+
# mypy
150+
.mypy_cache/
151+
.dmypy.json
152+
dmypy.json
153+
154+
# Pyre type checker
155+
.pyre/
156+
157+
# pytype static type analyzer
158+
.pytype/
159+
160+
# Cython debug symbols
161+
cython_debug/
162+
163+
# PyCharm
164+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
165+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
166+
# and can be added to the global gitignore or merged into this file. For a more nuclear
167+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
168+
#.idea/
169+
170+
# Ruff stuff:
171+
.ruff_cache/
172+
173+
# PyPI configuration file
174+
.pypirc

.pylintrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[MESSAGES CONTROL]
2+
disable = C0114, C0115, C0116 ; Disable missing module/class/function docstring warnings
3+
4+
[FORMAT]
5+
max-line-length = 88 ; Match Black's default line length
6+
7+
[MASTER]
8+
ignore = venv ; Ignore virtual environment folder

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
11
# python-ear
22

33
A python implementation of [draft-fv-rats-ear](https://datatracker.ietf.org/doc/draft-fv-rats-ear/).
4+
5+
# Proposal
6+
7+
Following are the tools that will be used in the development of this library
8+
9+
## CWT and JWT creation
10+
11+
1. [python-cwt](https://python-cwt.readthedocs.io/en/stable/)
12+
2. [python-jwt](https://pypi.org/project/python-jose/)
13+
14+
## Code formatting and styling
15+
16+
1. [black](https://pypi.org/project/black/)
17+
2. [isort](https://pypi.org/project/isort/)
18+
19+
## Linting and static analysis
20+
21+
1. [flake8](https://pypi.org/project/flake8/)
22+
2. [mypy](https://pypi.org/project/mypy/)
23+
24+
## Testing
25+
26+
1. [pytest](https://pypi.org/project/pytest/)

requirements.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
python-jose==3.4.0
2+
cwt==2.8.0
3+
black==24.8.0
4+
isort==5.12.0
5+
flake8==6.0.0
6+
mypy==1.5.1
7+
pytest==7.4.2
8+
tox==4.24.1
9+
pyright==1.1.325
10+
pylint==2.17.5

src/__init__.py

Whitespace-only changes.

src/claims.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import json
2+
from dataclasses import dataclass, field
3+
from typing import Any, Dict
4+
5+
6+
@dataclass
7+
class EARClaims:
8+
profile: str
9+
issued_at: int
10+
verifier_id: Dict[str, str] = field(default_factory=dict)
11+
submods: Dict[str, Any] = field(default_factory=dict)
12+
13+
def to_dict(self) -> Dict[str, Any]:
14+
return {
15+
"eat_profile": self.profile,
16+
"iat": self.issued_at,
17+
"ear.verifier-id": self.verifier_id,
18+
"submods": self.submods,
19+
}
20+
21+
@classmethod
22+
def from_dict(cls, data: Dict[str, Any]):
23+
return cls(
24+
profile=data.get("eat_profile", ""),
25+
issued_at=data.get("iat", 0),
26+
verifier_id=data.get("ear.verifier-id", {}),
27+
submods=data.get("submods", {}),
28+
)
29+
30+
def to_json(self) -> str:
31+
return json.dumps(self.to_dict())
32+
33+
@classmethod
34+
def from_json(cls, json_str: str):
35+
return cls.from_dict(json.loads(json_str))

tests/__init__.py

Whitespace-only changes.

tests/test_claims.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from src.claims import EARClaims
2+
3+
4+
def test_ear_claims():
5+
claims = EARClaims(
6+
"test_profile",
7+
1234567890,
8+
{"build": "v1"},
9+
{"submods1": {"status": "affirming"}},
10+
)
11+
json_str = claims.to_json()
12+
parsed_claims = EARClaims.from_json(json_str)
13+
assert parsed_claims.to_dict() == claims.to_dict()

tox.ini

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[tox]
2+
envlist = lint, test
3+
4+
[testenv:lint]
5+
deps =
6+
isort==5.12.0
7+
black==24.8.0
8+
flake8==6.0.0
9+
mypy==1.5.1
10+
pylint==2.17.5
11+
pyright==1.1.325
12+
commands =
13+
isort . --check --diff
14+
black . --check --diff
15+
flake8 .
16+
mypy .
17+
pylint src tests
18+
pyright
19+
20+
[testenv:test]
21+
deps =
22+
pytest==7.4.2
23+
commands = pytest

0 commit comments

Comments
 (0)