From 5bfc25ff514662182b528a51eb0984f6bd12b958 Mon Sep 17 00:00:00 2001 From: Sebastien Rousseau Date: Sat, 27 Jul 2024 16:13:03 +0100 Subject: [PATCH 1/2] Add README.md for strings module --- encryption_helper/common/README.md | 45 ++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/encryption_helper/common/README.md b/encryption_helper/common/README.md index e69de29..d4f269b 100644 --- a/encryption_helper/common/README.md +++ b/encryption_helper/common/README.md @@ -0,0 +1,45 @@ +

+ HSBC Logo +

+ +

Encryption Helper Python - Strings Module

+ +

+ Encryption Helper Banner +

+ +

+ Strings module for the encryption_helper package. +

+ +

+ Attributes • + Usage • + License +

+ +## Attributes + +The `strings.py` module provides a collection of string constants used throughout the `encryption_helper` package. These constants include file suffixes for various key and encrypted file types. + +- **private_key_suffix**: The file suffix for private key files. +- **public_key_suffix**: The file suffix for public key files. +- **encrypted_file_suffix**: The file suffix for encrypted files. + +## Usage + +This module defines string constants for use in the `encryption_helper` package. These constants help standardize file naming conventions across the package. + +### Example + +```python +from encryption_helper.common.strings import private_key_suffix, public_key_suffix, encrypted_file_suffix + +print(private_key_suffix) # Output: private-key.pem +print(public_key_suffix) # Output: public_key.pem +print(encrypted_file_suffix) # Output: .bin +``` + +## License + +This project is licensed under the MIT License. See the [LICENSE](../LICENSE) file for details. From e79d852a4cea3a043401a2e33b8ff505447b3e03 Mon Sep 17 00:00:00 2001 From: Sebastien Rousseau Date: Sat, 27 Jul 2024 16:30:12 +0100 Subject: [PATCH 2/2] Add README.md for checks, io modules --- encryption_helper/common/README.md | 8 +- encryption_helper/context/README.md | 72 +++++++++++++ encryption_helper/utils/checks/README.md | 55 ++++++++++ encryption_helper/utils/io/README.md | 122 +++++++++++++++++++++++ 4 files changed, 255 insertions(+), 2 deletions(-) diff --git a/encryption_helper/common/README.md b/encryption_helper/common/README.md index d4f269b..45d9f90 100644 --- a/encryption_helper/common/README.md +++ b/encryption_helper/common/README.md @@ -1,13 +1,16 @@ +

HSBC Logo

-

Encryption Helper Python - Strings Module

+

Encryption Helper Python

Encryption Helper Banner

+

Strings Module

+

Strings module for the encryption_helper package.

@@ -17,6 +20,7 @@ UsageLicense

+ ## Attributes @@ -42,4 +46,4 @@ print(encrypted_file_suffix) # Output: .bin ## License -This project is licensed under the MIT License. See the [LICENSE](../LICENSE) file for details. +This project is licensed under the MIT License. See the [LICENSE](../../LICENSE) file for details. diff --git a/encryption_helper/context/README.md b/encryption_helper/context/README.md index e69de29..c5d6e2d 100644 --- a/encryption_helper/context/README.md +++ b/encryption_helper/context/README.md @@ -0,0 +1,72 @@ + +

+ HSBC Logo +

+ +

Encryption Helper Python

+ +

+ Encryption Helper Banner +

+ +

Context Module

+ +

+ Context module for the encryption_helper package. +

+ +

+ Classes • + Usage • + License +

+ + +## Classes + +The `context.py` module provides a `Context` class for managing application-wide settings and logging. It implements the Singleton pattern to ensure only one instance of the context exists. + +### Context + +A singleton class for managing application context and logging. + +#### Attributes + +- **_instance** (Optional[Context]): The singleton instance of the Context class. +- **name** (str): The name of the application context, used for logging. +- **log_level** (int): The current logging level. +- **logger** (Optional[logging.Logger]): The logger instance for the context. + +### Methods + +- `__new__(cls) -> Context`: Creates and returns the singleton instance of the Context class. +- `get_instance(cls) -> Context`: Gets the singleton instance of the Context class. +- `set_name(self, name: str) -> None`: Sets the name of the context. +- `set_log_level(self, log_level: Optional[str]) -> None`: Sets the logging level for the context. +- `init_logging(self) -> None`: Initializes the logger for the context. +- `get_logger(self) -> logging.Logger`: Gets the logger for the context, initializing it if necessary. + +## Usage + +This module defines a `Context` class for managing application-wide settings and logging. + +### Example + +```python +from encryption_helper.context.context import Context + +# Get the singleton instance of the Context class +context = Context.get_instance() + +# Set the name and logging level of the context +context.set_name('my_app') +context.set_log_level('DEBUG') + +# Get the logger instance and log a message +logger = context.get_logger() +logger.debug('This is a debug message') +``` + +## License + +This project is licensed under the MIT License. See the [LICENSE](../../LICENSE) file for details. \ No newline at end of file diff --git a/encryption_helper/utils/checks/README.md b/encryption_helper/utils/checks/README.md index e69de29..be5f2cc 100644 --- a/encryption_helper/utils/checks/README.md +++ b/encryption_helper/utils/checks/README.md @@ -0,0 +1,55 @@ + +

+ HSBC Logo +

+ +

Encryption Helper Python

+ +

+ Encryption Helper Banner +

+ +

Checks Module

+ +

+ Checks module for the encryption_helper package. +

+ +

+ Functions • + Usage • + License +

+ + +## Functions + +The `checks.py` module provides utility functions for input validation. + +### str_none_or_empty + +Check if one or more input strings are `None` or empty. + +#### Args + +- **argv (str)**: A variable number of string arguments to be checked. + +#### Returns + +- **bool**: `True` if any of the input strings is `None` or empty; otherwise `False`. + +#### Examples + +```python +from encryption_helper.utils.checks import str_none_or_empty + +print(str_none_or_empty('test', 'hello', 'world')) # Output: False +print(str_none_or_empty('test', None, 'world')) # Output: True +print(str_none_or_empty('test', '', 'world')) # Output: True +print(str_none_or_empty('test', ' ', 'world')) # Output: True +print(str_none_or_empty()) # Output: False +``` + +## License + +This project is licensed under the MIT License. See the [LICENSE](../../../LICENSE) file for details. diff --git a/encryption_helper/utils/io/README.md b/encryption_helper/utils/io/README.md index e69de29..808ab25 100644 --- a/encryption_helper/utils/io/README.md +++ b/encryption_helper/utils/io/README.md @@ -0,0 +1,122 @@ + +

+ HSBC Logo +

+ +

Encryption Helper Python

+ +

+ Encryption Helper Banner +

+ +

I/O Modules

+ +

+ I/O modules for the encryption_helper package. +

+ +

+ Read File Functions • + Write File Functions • + Usage • + License +

+ + +## Read File Functions + +The `read_file.py` module provides functions for reading text files in binary mode. + +### read_text_in_binary_mode + +Read text from a file in binary mode given a directory and file name. + +#### Args + +- **directory (str)**: The directory where the file is located. +- **file_name (str)**: The name of the file to be read. + +#### Returns + +- **bytes**: The content of the file read in binary mode. + +#### Raises + +- **Exception**: If one or more arguments are empty. +- **OSError**: If there is an error reading the file. + +### read_text_in_binary_mode_abs + +Read text from a file in binary mode given an absolute file path. + +#### Args + +- **absolute_file_path (str)**: The absolute path to the file to be read. + +#### Returns + +- **bytes**: The content of the file read in binary mode. + +#### Raises + +- **Exception**: If one or more arguments are empty. +- **OSError**: If there is an error reading the file. + +## Write File Functions + +The `write_file.py` module provides functions for writing text files in binary mode. + +### write_text_in_binary_mode + +Write text to a file in binary mode given a directory and file name. + +#### Args + +- **directory (str)**: The directory where the file will be written. +- **file_name (str)**: The name of the file to be written. +- **text (bytes)**: The text to be written to the file. + +#### Returns + +- **str**: The absolute file path of the written file. + +#### Raises + +- **Exception**: If one or more arguments are empty. +- **OSError**: If there is an error writing to the file. + +### write_text_in_binary_mode_abs + +Write text to a file in binary mode given an absolute file path. + +#### Args + +- **absolute_file_path (str)**: The absolute path to the file to be written. +- **text (bytes)**: The text to be written to the file. + +#### Returns + +- **str**: The absolute file path of the written file. + +#### Raises + +- **Exception**: If one or more arguments are empty. +- **OSError**: If there is an error writing to the file. + +## Usage + +```python +from encryption_helper.utils.io import read_file, write_file + +# Read file example +content = read_file.read_text_in_binary_mode('/path/to/directory', 'file.txt') +print(content) + +# Write file example +path = write_file.write_text_in_binary_mode('/path/to/directory', 'file.txt', b'test data') +print(path) +``` + +## License + +This project is licensed under the MIT License. See the [LICENSE](../../../LICENSE) file for details.