Skip to content

Commit

Permalink
Documentation for key collection usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
dzoep committed Oct 9, 2024
1 parent dba84b4 commit d878674
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
27 changes: 27 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,30 @@ for block in crypt4gh.data_blocks:
else:
print("Cannot decrypt this block.")
```

If only deciphered blocks are to be processed, the clear_blocks
iterator can be used:

```python
for block in crypt4gh.clear_blocks:
print(block.cleartext)
```

### Multiple Crypt4GH Keys Support

The reader may try multiple reader keys when reading the container
header. To work with multiple keys, a key collection has to be created
and subsequently used:

```python
from oarepo_c4gh import KeyCollection

my_secret_key = C4GHKey.from_file("my_secret_key.c4gh", lambda: "password")
my_other_secret_key = C4GHKey.from_file(
"my_other_secret_key.c4gh",
lambda: "other_password"
)
my_keys = KeyCollection(my_secret_key, my_other_secret_key)
with open("hello.txt.c4gh") as f:
crypt4gh = Crypt4GH(my_keys, f)
```
4 changes: 2 additions & 2 deletions oarepo_c4gh/crypt4gh/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def __init__(
packet count. The header packets are loaded lazily when needed.
Parameters:
reader_key: the key used for trying to decrypt header packets
(must include the private part)
reader_key_or_collection: the key used for trying to decrypt header
packets (must include the private part) or collection of keys
istream: the container input stream
analyzer: analyzer for storing packet readability information
Expand Down

0 comments on commit d878674

Please sign in to comment.