Coverage for oarepo_c4gh/crypt4gh/dek.py: 100%

14 statements  

« prev     ^ index     » next       coverage.py v7.10.2, created at 2025-08-07 12:05 +0000

1""" 

2Module with Data Encryption Key wrapper. 

3""" 

4 

5from ..key import Key 

6from ..exceptions import Crypt4GHDEKException 

7 

8 

9class DEK: 

10 """Data Encryption Key with reference to the Key that unlocked 

11 it. 

12 

13 """ 

14 

15 def __init__(self, dek: bytes, key: bytes) -> None: 

16 """Initializes the wrapper. 

17 

18 Parameters: 

19 dek: the symmetric Data Encryption Key 

20 key: public key that unlocked this DEK 

21 """ 

22 if len(dek) != 32: 

23 raise Crypt4GHDEKException("DEK must be 32 bytes") 

24 self._dek = dek 

25 self._key = key 

26 

27 @property 

28 def dek(self) -> bytes: 

29 """The Data Encryption Key - directly usable by symmetric 

30 cryptography functions. 

31 

32 """ 

33 return self._dek 

34 

35 @property 

36 def key(self) -> Key: 

37 """Bytes representation of the public key that unlocked this 

38 DEK. 

39 

40 """ 

41 return self._key