mirror of https://github.com/nucypher/nucypher.git
Add header property
Remove setter The setter method is not needed because it turns out that caching doesn't happen and `Header.update_header` can be called anyway.pull/52/head
parent
df2908817e
commit
2e5ddc2480
|
@ -1,12 +1,11 @@
|
|||
import msgpack
|
||||
import os
|
||||
import io
|
||||
from nkms.storage import Header
|
||||
from nacl.utils import random
|
||||
from nkms.crypto import default_algorithm, symmetric_from_algorithm
|
||||
|
||||
|
||||
class EncryptedFile(object):
|
||||
def __init__(self, key, path, mode='rb'):
|
||||
def __init__(self, key, path, header_path=None):
|
||||
"""
|
||||
Creates an EncryptedFile object that allows the user to encrypt or
|
||||
decrypt data into a file defined at `path`.
|
||||
|
@ -16,11 +15,14 @@ class EncryptedFile(object):
|
|||
tells us how to decrypt it, or add more data.
|
||||
|
||||
:param bytes key: Symmetric key to use for encryption/decryption
|
||||
:param string/bytes path: Path of file to open
|
||||
:param string mode: Mode to use when opening file, default is 'rb'
|
||||
:param string/bytes path: Path of ciphertext file to open
|
||||
:param string/bytes header_path: Path of header file
|
||||
"""
|
||||
self.path = path
|
||||
self.mode = mode
|
||||
self.header_path = header_path
|
||||
|
||||
if header_path:
|
||||
self.header_obj = Header(header_path=self.header_path)
|
||||
|
||||
cipher = symmetric_from_algorithm(default_algorithm)
|
||||
self.cipher = cipher(key)
|
||||
|
@ -38,6 +40,10 @@ class EncryptedFile(object):
|
|||
ciphertext = self.file_obj.read(chunk_size)
|
||||
return self.cipher.decrypt(ciphertext, nonce=nonce)
|
||||
|
||||
@property
|
||||
def header(self):
|
||||
return self.header_obj.header
|
||||
|
||||
def open_new(self, keys, chunk_size=1000000, nonce=None):
|
||||
"""
|
||||
Opens a new EncryptedFile and creates a header for it ready for
|
||||
|
|
Loading…
Reference in New Issue