Skip to content

Add modules documentation #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions encryption_helper/common/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!-- markdownlint-disable MD033 MD041 -->
<p align="center">
<img src="https://www.hsbc.com/-/files/hsbc/header/hsbc-logo-200x25.svg" alt="HSBC Logo" width="200" title="HSBC Logo">
</p>

<h1 align="center">Encryption Helper Python</h1>

<p align="center">
<img src="../../assets/banner.jpg" alt="Encryption Helper Banner">
</p>

<h2 align="center">Strings Module</h2>

<p align="center">
<strong>Strings module for the encryption_helper package.</strong>
</p>

<p align="center">
<a href="#attributes">Attributes</a> •
<a href="#usage">Usage</a> •
<a href="#license">License</a>
</p>
<!-- markdownlint-enable MD033 MD041 -->

## 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.
72 changes: 72 additions & 0 deletions encryption_helper/context/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<!-- markdownlint-disable MD033 MD041 -->
<p align="center">
<img src="https://www.hsbc.com/-/files/hsbc/header/hsbc-logo-200x25.svg" alt="HSBC Logo" width="200" title="HSBC Logo">
</p>

<h1 align="center">Encryption Helper Python</h1>

<p align="center">
<img src="../../assets/banner.jpg" alt="Encryption Helper Banner">
</p>

<h2 align="center">Context Module</h2>

<p align="center">
<strong>Context module for the encryption_helper package.</strong>
</p>

<p align="center">
<a href="#classes">Classes</a> •
<a href="#usage">Usage</a> •
<a href="#license">License</a>
</p>
<!-- markdownlint-enable MD033 MD041 -->

## 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.
55 changes: 55 additions & 0 deletions encryption_helper/utils/checks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!-- markdownlint-disable MD033 MD041 -->
<p align="center">
<img src="https://www.hsbc.com/-/files/hsbc/header/hsbc-logo-200x25.svg" alt="HSBC Logo" width="200" title="HSBC Logo">
</p>

<h1 align="center">Encryption Helper Python</h1>

<p align="center">
<img src="../../../assets/banner.jpg" alt="Encryption Helper Banner">
</p>

<h2 align="center">Checks Module</h2>

<p align="center">
<strong>Checks module for the encryption_helper package.</strong>
</p>

<p align="center">
<a href="#functions">Functions</a> •
<a href="#usage">Usage</a> •
<a href="#license">License</a>
</p>
<!-- markdownlint-enable MD033 MD041 -->

## 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.
122 changes: 122 additions & 0 deletions encryption_helper/utils/io/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<!-- markdownlint-disable MD033 MD041 -->
<p align="center">
<img src="https://www.hsbc.com/-/files/hsbc/header/hsbc-logo-200x25.svg" alt="HSBC Logo" width="200" title="HSBC Logo">
</p>

<h1 align="center">Encryption Helper Python</h1>

<p align="center">
<img src="../../../assets/banner.jpg" alt="Encryption Helper Banner">
</p>

<h2 align="center">I/O Modules</h2>

<p align="center">
<strong>I/O modules for the encryption_helper package.</strong>
</p>

<p align="center">
<a href="#read-file-functions">Read File Functions</a> •
<a href="#write-file-functions">Write File Functions</a> •
<a href="#usage">Usage</a> •
<a href="#license">License</a>
</p>
<!-- markdownlint-enable MD033 MD041 -->

## 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.