The SSH host key has changed on 8 April, 2022 to this one: SHA256:573uTBSeh74kvOo0HJXi5ijdzRm8me27suzNEDlGyrQ

Add the content_length field to the Document base class

main
Gergely Polonkai 3 months ago
parent b9d0221e95
commit e8bc0cfd38
No known key found for this signature in database
GPG Key ID: 2D2885533B869ED4
  1. 5
      earthsnake/document/__init__.py
  2. 4
      earthsnake/document/es4.py
  3. 8
      tests/test_document_es4.py

@ -19,6 +19,11 @@ class Document(ABC): # pragma: no cover pylint: disable=too-few-public-methods
signature: Optional[str]
@property
@abstractmethod
def content_length(self) -> int:
"""The length of the document"""
@abstractmethod
def sign(self, identity: Optional[Identity] = None) -> None:
"""Sign the document as identity

@ -221,6 +221,10 @@ class Es4Document(Document): # pylint: disable=too-many-instance-attributes
self._content = value
self._content_hash = self.hash_value(value)
@property
def content_length(self) -> int:
return len(self._content)
def generate_hash(self) -> str:
"""Calculate the hash of the document

@ -272,3 +272,11 @@ def test_validate_unsigned_document(identity: Identity) -> None:
document.validate_signature()
assert str(ctx.value) == 'document has no signature assigned'
def test_content_length() -> None:
"""Test the content_length property"""
document = Es4Document.from_json(VALID_DOCUMENT)
assert document.content_length == 4

Loading…
Cancel
Save