Skip to content

Commit

Permalink
Move current filter implementation into separate subdirectory.
Browse files Browse the repository at this point in the history
- split filter header and filter4gh
- adjust tests for filter4gh in filter subdirectory (for now)
  • Loading branch information
dzoep committed Oct 29, 2024
1 parent c9469ea commit 9880bd5
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 49 deletions.
2 changes: 1 addition & 1 deletion oarepo_c4gh/crypt4gh/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .crypt4gh import Crypt4GH
from .writer import Crypt4GHWriter
from .filter import Crypt4GHFilter
from .filter.filter4gh import Crypt4GHFilter

__all__ = ["Crypt4GH", "Crypt4GHWriter", "Crypt4GHFilter"]
47 changes: 47 additions & 0 deletions oarepo_c4gh/crypt4gh/filter/filter4gh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""This module implements a filtered Crypt4GH container backed by
other Crypt4GH container but presenting filtered (added, changed
and/or removed) header packets.
"""

from ..common.proto4gh import Proto4GH
from ..common.header import Header
from typing import Generator
from ..common.data_block import DataBlock
from .header import FilterHeader


class Crypt4GHFilter(Proto4GH):
"""The whole container filter which actually filters only header
packets but for the writer the whole interface is needed.
"""

def __init__(self, original: Proto4GH) -> None:
"""Only prepares the filtered header and original container
with original blocks.
Parameters:
original: the original container to be filtered.
"""
self._original = original
self._header = FilterHeader(original.header)

def add_recipient(self, public_key: bytes) -> None:
"""Passes the public key to the header filter instance.
Parameters:
public_key: the reader key to add.
"""
self._header.add_recipient(public_key)

@property
def header(self) -> Header:
"""Returns the filtered header instance."""
return self._header

@property
def data_blocks(self) -> Generator[DataBlock, None, None]:
"""Returns the iterator for the original data blocks."""
return self._original.data_blocks
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
"""This module implements a filtered Crypt4GH container backed by
other Crypt4GH container but presenting filtered (added, changed
and/or removed) header packets.
"""This module implements filtered header on top of other Header
implementation.
"""

from .common.proto4gh import Proto4GH
from .common.header import Header
from typing import Generator
from .common.data_block import DataBlock
from ..key.software import SoftwareKey
from nacl.bindings import crypto_aead_chacha20poly1305_ietf_encrypt
from ..common.header import Header
from ...key.software import SoftwareKey
import io
import secrets
from .common.header_packet import HeaderPacket
from nacl.bindings import crypto_aead_chacha20poly1305_ietf_encrypt
from ..common.header_packet import HeaderPacket


class Crypt4GHHeaderFilter(Header):
class FilterHeader(Header):
"""As the header has its own interface, this class implements such
interface for filtered header.
Expand Down Expand Up @@ -94,37 +88,3 @@ def version(self) -> int:
return self._original.version


class Crypt4GHFilter(Proto4GH):
"""The whole container filter which actually filters only header
packets but for the writer the whole interface is needed.
"""

def __init__(self, original: Proto4GH) -> None:
"""Only prepares the filtered header and original container
with original blocks.
Parameters:
original: the original container to be filtered.
"""
self._original = original
self._header = Crypt4GHHeaderFilter(original.header)

def add_recipient(self, public_key: bytes) -> None:
"""Passes the public key to the header filter instance.
Parameters:
public_key: the reader key to add.
"""
self._header.add_recipient(public_key)

@property
def header(self) -> Header:
"""Returns the filtered header instance."""
return self._header

@property
def data_blocks(self) -> Generator[DataBlock, None, None]:
"""Returns the iterator for the original data blocks."""
return self._original.data_blocks
2 changes: 1 addition & 1 deletion tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from oarepo_c4gh.crypt4gh.crypt4gh import Crypt4GH
import io
from oarepo_c4gh.crypt4gh.writer import Crypt4GHWriter
from oarepo_c4gh.crypt4gh.filter import Crypt4GHFilter
from oarepo_c4gh.crypt4gh.filter.filter4gh import Crypt4GHFilter


class TestACrypt4GHHeader(unittest.TestCase):
Expand Down

0 comments on commit 9880bd5

Please sign in to comment.