Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmazan committed Aug 22, 2023
1 parent f66b5ed commit 4b7d4a0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
2 changes: 1 addition & 1 deletion python_anvil_encryption/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@click.command()
@click.argument("feet")
def main(feet: str):
def main():
log.init()


Expand Down
35 changes: 24 additions & 11 deletions python_anvil_encryption/encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives import padding as sym_padding
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric import padding
from cryptography.hazmat.primitives.asymmetric import padding, rsa
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes

IV_LENGTH = 16
Expand All @@ -29,7 +29,9 @@ def encrypt_rsa(raw_public_key: bytes, message: bytes, auto_padding=True) -> byt
which is '<rsaEncryptedAESKey:aesIV:aesEncryptedMessage>'
:rtype: bytes
"""
public_key = serialization.load_pem_public_key(raw_public_key)
public_key = serialization.load_pem_public_key(
raw_public_key
) # type: rsa.RSAPublicKey # type: ignore
aes_key = os.urandom(AES_KEY_LENGTH)
encrypted_aes_key = public_key.encrypt(
aes_key.hex().encode(),
Expand All @@ -46,22 +48,30 @@ def encrypt_rsa(raw_public_key: bytes, message: bytes, auto_padding=True) -> byt
return b":".join([b64_aes_key, enc_message])


def decrypt_rsa(raw_private_key: AnyStr, message: AnyStr):
def decrypt_rsa(_raw_private_key: AnyStr, _message: AnyStr):
"""
Decrypt with RSA.
:param raw_private_key:
:type raw_private_key: AnyStr
:param message:
:type message: AnyStr
:return:
:rtype:
"""
if isinstance(message, str):
message = bytes(message, DEFAULT_ENCODING)

if isinstance(raw_private_key, str):
raw_private_key = bytes(raw_private_key, DEFAULT_ENCODING)

private_key = serialization.load_pem_private_key(raw_private_key, password=None)
if isinstance(_message, str):
message = bytes(_message, DEFAULT_ENCODING)
else:
message = _message

if isinstance(_raw_private_key, str):
raw_private_key = bytes(_raw_private_key, DEFAULT_ENCODING)
else:
raw_private_key = _raw_private_key

private_key = serialization.load_pem_private_key(
raw_private_key, password=None
) # type: rsa.RSAPrivateKey # type: ignore
index = message.index(b":")
enc_aes_key = message[:index]
encrypted_message = message[index + 1 :]
Expand All @@ -80,7 +90,8 @@ def decrypt_rsa(raw_private_key: AnyStr, message: AnyStr):

def encrypt_aes(aes_key: bytes, message: bytes, auto_padding=True) -> bytes:
"""
Encrypt with AES
Encrypt with AES.
:param aes_key:
:type aes_key:
:param message:
Expand Down Expand Up @@ -108,6 +119,8 @@ def encrypt_aes(aes_key: bytes, message: bytes, auto_padding=True) -> bytes:

def decrypt_aes(aes_key: bytes, encrypted_message: bytes):
"""
Decrypt with AES.
:param aes_key:
:type aes_key:
:param encrypted_message:
Expand Down
1 change: 1 addition & 0 deletions python_anvil_encryption/tests/test_encryption.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for encryption module."""
# pylint: disable=redefined-outer-name,unused-variable,expression-not-assigned
import json

import pytest
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest
from click.testing import CliRunner

from python_anvil_encryption.cli import main
# from python_anvil_encryption.cli import main


@pytest.fixture
Expand Down

0 comments on commit 4b7d4a0

Please sign in to comment.