From 7730ce476a9bfc587f032792b615c92d9780d817 Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Tue, 18 Oct 2022 17:58:48 +1100 Subject: [PATCH] Make PyCryptodome an optional dependency --- README.md | 1 + yli/io.py | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index cff830b..1873293 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ The mandatory dependencies of this library are: Optional dependencies are: * [mpmath](https://mpmath.org/), for *beta_ratio* and *beta_oddsratio* +* [PyCryptodome](https://www.pycryptodome.org/), for *pickle_write_encrypted* and *pickle_read_encrypted* * [rpy2](https://rpy2.github.io/), with R packages: * [BFpack](https://cran.r-project.org/web/packages/BFpack/index.html), for *bayesfactor_afbf* (*RegressionResult.bayesfactor_beta_zero*) * [logistf](https://cran.r-project.org/web/packages/logistf/index.html), for *PenalisedLogit* diff --git a/yli/io.py b/yli/io.py index a71a297..64d6ad7 100644 --- a/yli/io.py +++ b/yli/io.py @@ -14,10 +14,6 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from Crypto.Cipher import AES -from Crypto.Protocol.KDF import scrypt -from Crypto.Random import get_random_bytes - import getpass import io import lzma @@ -32,6 +28,10 @@ def pickle_write_encrypted(df, fname): Password is derived using scrypt KDF """ + from Crypto.Cipher import AES + from Crypto.Protocol.KDF import scrypt + from Crypto.Random import get_random_bytes + # Get random salt salt = get_random_bytes(16) @@ -69,6 +69,9 @@ def pickle_read_encrypted(fname): Read a DataFrame from an encrypted file """ + from Crypto.Cipher import AES + from Crypto.Protocol.KDF import scrypt + # Read ciphertext data with open(fname, 'rb') as f: salt, nonce, ct_bytes = pickle.load(f)