Skip to content

Commit

Permalink
Verify docstrings with interrogate.
Browse files Browse the repository at this point in the history
Signed-off-by: Alexis <[email protected]>
  • Loading branch information
DarkaMaul committed Dec 27, 2024
1 parent 2440760 commit 20e7923
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ lint: $(VENV)/pyvenv.cfg
ruff check
cargo fmt --check --manifest-path rust/Cargo.toml
cargo fmt --check --manifest-path rust/tsp-asn1/Cargo.toml

. $(VENV_BIN)/activate && \
interrogate -c pyproject.toml .

.PHONY: reformat
reformat:
Expand Down
13 changes: 12 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dependencies = ["cryptography>=43,<45"]
[project.optional-dependencies]
doc = []
test = ["pytest", "pytest-cov", "pretend", "coverage[toml]"]
lint = ["ruff >= 0.7,< 0.9"]
lint = ["ruff >= 0.7,< 0.9", "interrogate"]
dev = ["rfc3161-client[test,lint,doc]", "maturin>=1.7,<2.0"]

[project.urls]
Expand Down Expand Up @@ -52,3 +52,14 @@ select = ["E", "F", "I", "W", "UP", "TCH"]

[tool.coverage.report]
exclude_also = ["if TYPE_CHECKING:"]

[tool.interrogate]
# don't enforce documentation coverage for testing, the virtual
# environment, or the scripts.
exclude = [
".venv",
"test",
"scripts",
]
ignore-semiprivate = true
fail-under = 100
5 changes: 5 additions & 0 deletions src/rfc3161_client/errors.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
"""Errors."""


class VerificationError(Exception):
"""Verification errors are raised when the verification of a Timestamp fails."""

pass
14 changes: 14 additions & 0 deletions src/rfc3161_client/tsp.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Timestamp protocol objects."""

from __future__ import annotations

import abc
Expand Down Expand Up @@ -66,6 +68,8 @@ def as_bytes(self) -> bytes:


class PKIStatus(enum.IntEnum):
"""Response status."""

GRANTED = 0
GRANTED_WITH_MODS = 1
REJECTION = 2
Expand All @@ -75,6 +79,8 @@ class PKIStatus(enum.IntEnum):


class TimeStampResponse(metaclass=abc.ABCMeta):
"""Timestamp response (per RFC 3161)."""

@property
@abc.abstractmethod
def status(self) -> int:
Expand Down Expand Up @@ -108,6 +114,8 @@ def as_bytes(self) -> bytes:


class Accuracy(metaclass=abc.ABCMeta):
"""Accuracy of the timestamp response."""

@property
@abc.abstractmethod
def seconds(self) -> int:
Expand All @@ -128,6 +136,8 @@ def micros(self) -> int | None:


class TimeStampTokenInfo(metaclass=abc.ABCMeta):
"""Timestamp token info (per RFC 3161)."""

@property
@abc.abstractmethod
def version(self) -> int:
Expand Down Expand Up @@ -178,6 +188,8 @@ def name(self) -> cryptography.x509.GeneralName:


class SignedData(metaclass=abc.ABCMeta):
"""Signed data (CMS - RFC 2630)"""

@property
@abc.abstractmethod
def version(self) -> int:
Expand Down Expand Up @@ -205,6 +217,8 @@ def signer_infos(self) -> set[SignerInfo]:


class SignerInfo(metaclass=abc.ABCMeta):
"""Signer info (RFC 2634)."""

@property
@abc.abstractmethod
def version(self) -> int:
Expand Down
15 changes: 14 additions & 1 deletion src/rfc3161_client/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@


class VerifierBuilder:
"""Builder for a Verifier."""

def __init__(
self,
policy_id: cryptography.x509.ObjectIdentifier | None = None,
Expand Down Expand Up @@ -121,11 +123,22 @@ def from_request(cls, tsp_request: TimeStampRequest) -> VerifierBuilder:


class Verifier(metaclass=abc.ABCMeta):
"""Verifier.
This class should not be instantiated directly but through a VerifierBuilder.
"""

@abc.abstractmethod
def verify(self, timestamp_response: TimeStampResponse, hashed_message: bytes) -> bool: ...
def verify(self, timestamp_response: TimeStampResponse, hashed_message: bytes) -> bool:
"""Verify a timestamp response."""


class _Verifier(Verifier):
"""Inner implementation of the Verifier.
This pattern helps us ensure that the Verifier is never created directly.
"""

def __init__(
self,
policy_id: cryptography.x509.ObjectIdentifier | None,
Expand Down

0 comments on commit 20e7923

Please sign in to comment.