コード例 #1
0
ファイル: test_crypto.py プロジェクト: robocorp/rpaframework
def test_encrypt_file_suffix():
    lib = Crypto()

    key = lib.generate_key()
    lib.use_encryption_key(key)

    text = "An example string\nWith some secret content"

    with temp_path(text.encode("utf-8")) as original:
        with temp_path(suffix=".bin") as encrypted:
            lib.encrypt_file(original, encrypted)
            result = lib.decrypt_file(encrypted)
            try:
                assert os.path.isfile(result)
                assert result.endswith(".dec.bin")
            finally:
                with contextlib.suppress(FileNotFoundError):
                    os.unlink(result)
コード例 #2
0
ファイル: test_crypto.py プロジェクト: robocorp/rpaframework
def test_encrypt_decrypt_file():
    lib = Crypto()

    key = lib.generate_key()
    lib.use_encryption_key(key)

    text = "An example string\nWith some secret content"

    with temp_path() as encrypted:
        with temp_path(text.encode("utf-8")) as original:
            result = lib.encrypt_file(original, encrypted)
            assert result == encrypted
            assert os.stat(result).st_size > 0

        with temp_path() as decrypted:
            result = lib.decrypt_file(encrypted, decrypted)
            assert result == decrypted
            with open(result) as resultfile:
                assert resultfile.read() == text
コード例 #3
0
ファイル: test_crypto.py プロジェクト: robocorp/rpaframework
def test_encrypt_file_default_paths():
    lib = Crypto()

    key = lib.generate_key()
    lib.use_encryption_key(key)

    text = "An example string\nWith some secret content"

    with temp_path(text.encode("utf-8")) as original:
        encrypted, decrypted = "", ""
        try:
            encrypted = lib.encrypt_file(original)
            assert encrypted == original + ".enc"

            decrypted = lib.decrypt_file(encrypted)
            assert decrypted == original
        finally:
            with contextlib.suppress(FileNotFoundError):
                os.unlink(encrypted)
                os.unlink(decrypted)