From 6975920eedc2152c5bf0683d0ad84dd185763a3e Mon Sep 17 00:00:00 2001 From: someotherself Date: Fri, 20 Sep 2024 12:04:38 +0200 Subject: [PATCH 1/2] python stub file added --- .env/lib64 | 1 + .env/pyvenv.cfg | 3 + Cargo.lock | 2 +- rencrypt.pyi | 224 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 229 insertions(+), 1 deletion(-) create mode 120000 .env/lib64 create mode 100644 .env/pyvenv.cfg create mode 100644 rencrypt.pyi diff --git a/.env/lib64 b/.env/lib64 new file mode 120000 index 0000000..7951405 --- /dev/null +++ b/.env/lib64 @@ -0,0 +1 @@ +lib \ No newline at end of file diff --git a/.env/pyvenv.cfg b/.env/pyvenv.cfg new file mode 100644 index 0000000..0fbebd1 --- /dev/null +++ b/.env/pyvenv.cfg @@ -0,0 +1,3 @@ +home = /home/cristian/Rust/contributing/rencrypt_docs/rencrypt-python/.env/bin +include-system-site-packages = false +version = 3.10.12 diff --git a/Cargo.lock b/Cargo.lock index 4679531..def0843 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -978,7 +978,7 @@ checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" [[package]] name = "rencrypt" -version = "1.1.5" +version = "1.2.2" dependencies = [ "aead", "aes", diff --git a/rencrypt.pyi b/rencrypt.pyi new file mode 100644 index 0000000..d0f12dd --- /dev/null +++ b/rencrypt.pyi @@ -0,0 +1,224 @@ +from typing import Any, Union, Optional, Protocol + + +class Cipher: + """ + A cryptographic cipher object. + + This struct provides access to a variety of cryptographic algorithms, specified by the `CipherMeta` parameter, + and securely manages encryption keys. The `Cipher` supports encryption and decryption operations while ensuring + that sensitive key data is securely handled in memory. + """ + cipher: Any + cipher_meta: CipherMeta + + def __init__(self, cipher_meta: CipherMeta, key: Any) -> None: + """ + Create a new cipher object with the specified algorithm and key. + + Args: + cipher_meta (CipherMeta): Specifies the cryptographic algorithm and configuration for the cipher. + key (bytearray or numpy array): The encryption key, which must be provided as a mutable buffer. + + Returns: + Cipher: A new Cipher object ready for cryptographic operations. + + Raises: + ValueError: If there is an issue initializing the cipher, such as an invalid key or algorithm. + + Example: + ```python + from your_module import Cipher, CipherMeta + + cipher_meta = CipherMeta.Ring(alg="AES-256-GCM") + key = bytearray(b"your_secret_key_here") + cipher = Cipher(cipher_meta, key) + ``` + """ + + def seal_in_place( + self, + buf: bytearray, + plaintext_len: int, + block_index: Optional[int] = None, + aad: Optional[bytes] = None, + nonce: Optional[bytes] = None + ) -> int: + """ + Encrypts data in place, writing the resulting ciphertext to the provided buffer. + + Args: + buf (bytearray or numpy array): A mutable buffer where the encrypted data will be stored. + plaintext_len (int): The length of the plaintext data to encrypt. + block_index (Optional[int]): The block index to use for encryption (if applicable). + aad (Optional[bytes]): Additional authenticated data (optional). + nonce (Optional[bytes]): Nonce for encryption (optional). + + Returns: + int: The total length of the resulting ciphertext, including overhead. + + Raises: + ValueError: If encryption fails or parameters are invalid. + """ + + def seal_in_place_from( + self, + buf: Union[str, bytearray], + plaintext_len: int, + block_index: Optional[int] = None, + aad: Optional[bytes] = None, + nonce: Optional[bytes] = None + ) -> int: + """ + Encrypts the given plaintext and writes the result to the provided buffer. + + Args: + plaintext (bytearray or numpy array): The data to encrypt. + buf (bytearray or numpy array): The buffer to write the encrypted data into. + block_index (Optional[int]): The block index to use for encryption (if applicable). + aad (Optional[bytes]): Additional authenticated data (optional). + nonce (Optional[bytes]): Nonce for encryption (optional). + + Returns: + int: The total length of the resulting ciphertext, including overhead. + + Raises: + ValueError: If encryption fails or parameters are invalid. + """ + + @staticmethod + def copy_slice(src: int, buf: bytearray) -> None: + """ + Copies data from the source to the destination buffer. + + Args: + src (int): The source data to copy from. + buf (bytearray): A mutable buffer to copy the data into. + + Raises: + PyResult: If copying fails. + """ + + def open_in_place( + self, + buf: bytearray, + plaintext_and_tag_and_nonce_len: int, + block_index: Optional[int] = None, + aad: Optional[bytes] = None + ) -> int: + """ + Decrypts the data in place using the provided buffer. + + Args: + buf (bytearray or numpy array): A mutable buffer containing the ciphertext and associated data. + plaintext_and_tag_and_nonce_len (int): The length of the plaintext, tag, and nonce. + block_index (Optional[int]): An optional block index for additional processing. + aad (Optional[bytes]): Additional authenticated data (AAD). + + Returns: + int: The length of the decrypted plaintext. + + Raises: + PyResult: If decryption fails. + """ + + def open_in_place_from( + self, + ciphertext_and_tag_and_nonce: bytearray, + buf: bytearray, + block_index: Optional[int] = None, + aad: Optional[bytes] = None + ) -> int: + """ + Decrypts the provided ciphertext and tag, storing the result in the specified buffer. + + Args: + ciphertext_and_tag_and_nonce (bytearray): The buffer containing the ciphertext, tag, and nonce. + buf (bytearray): A mutable buffer where the decrypted plaintext will be stored. + block_index (Optional[int]): An optional block index for additional processing. + aad (Optional[bytes]): Additional authenticated data (AAD). + + Returns: + int: The length of the decrypted plaintext. + + Raises: + PyResult: If decryption fails. + """ + +class RingAlgorithm: + """ + Class containing supported algorithms in the Ring cryptography library. + + Variants: + - ChaCha20Poly1305 + - Aes128Gcm + - Aes256Gcm (default) + """ + + +class RustCryptoAlgorithm: + """ + Enum containing supported algorithms in the RustCrypto cryptography library. + + Variants: + - ChaCha20Poly1305 + - XChaCha20Poly1305 + - Aes128Gcm + - Aes256Gcm (default) + - Aes128GcmSiv + - Aes256GcmSiv + - Ascon128 + - Ascon128a + - Ascon80pq + - DeoxysI128 + - DeoxysI256 + - Aes128Eax + - Aes256Eax + """ + + +class SodiumoxideAlgorithm: + """ + Class containing supported algorithms in the Sodiumoxide cryptography library. + + Variants: + - ChaCha20Poly1305 + - ChaCha20Poly1305Ietf (default) + - XChaCha20Poly1305Ietf + """ + + +class OrionAlgorithm: + """ + Class containing supported algorithms in the Orion cryptography library. + + Variants: + - ChaCha20Poly1305 (default) + - XChaCha20Poly1305 + """ + + +class CipherMeta: + """ + Class containing different cryptography libraries and their associated algorithms. + + Variants: + - Ring: Uses the Ring cryptography library. + - RustCrypto: Uses the RustCrypto cryptography library. + - Sodiumoxide: Uses the Sodiumoxide cryptography library. + - Orion: Uses the Orion cryptography library. + """ + + def __init__(self, alg: Union[RingAlgorithm, RustCryptoAlgorithm, SodiumoxideAlgorithm, OrionAlgorithm]) -> None: + pass + + +class HPKEAlgorithm: + """ + Enum representing supported algorithms for HPKE (Hybrid Public Key Encryption). + + Variants: + - Aes128Gcm + - Aes256Gcm (default) + - ChaCha20Poly1305 + """ From 02fbaf4088bb8692a7de4e6968256bc772b23d50 Mon Sep 17 00:00:00 2001 From: someotherself Date: Fri, 20 Sep 2024 14:20:52 +0200 Subject: [PATCH 2/2] python stub file added --- .env/lib64 | 1 - .env/pyvenv.cfg | 3 --- 2 files changed, 4 deletions(-) delete mode 120000 .env/lib64 delete mode 100644 .env/pyvenv.cfg diff --git a/.env/lib64 b/.env/lib64 deleted file mode 120000 index 7951405..0000000 --- a/.env/lib64 +++ /dev/null @@ -1 +0,0 @@ -lib \ No newline at end of file diff --git a/.env/pyvenv.cfg b/.env/pyvenv.cfg deleted file mode 100644 index 0fbebd1..0000000 --- a/.env/pyvenv.cfg +++ /dev/null @@ -1,3 +0,0 @@ -home = /home/cristian/Rust/contributing/rencrypt_docs/rencrypt-python/.env/bin -include-system-site-packages = false -version = 3.10.12