pypomes-crypto 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pypomes_crypto-0.1.1/.gitignore +10 -0
- pypomes_crypto-0.1.1/LICENSE +21 -0
- pypomes_crypto-0.1.1/PKG-INFO +18 -0
- pypomes_crypto-0.1.1/README.md +0 -0
- pypomes_crypto-0.1.1/pyproject.toml +32 -0
- pypomes_crypto-0.1.1/src/pypomes_crypto/__init__.py +11 -0
- pypomes_crypto-0.1.1/src/pypomes_crypto/crypto_pomes.py +39 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 GT Nunes
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: pypomes_crypto
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: A collection of Python pomes, pennyeach (cryptography modules)
|
|
5
|
+
Project-URL: Homepage, https://github.com/TheWiseCoder/PyPomes-Crypto
|
|
6
|
+
Project-URL: Bug Tracker, https://github.com/TheWiseCoder/PyPomes-Crypto/issues
|
|
7
|
+
Author-email: GT Nunes <wisecoder01@gmail.com>
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Requires-Python: >=3.10
|
|
13
|
+
Requires-Dist: asn1crypto>=1.5.1
|
|
14
|
+
Requires-Dist: cryptography>=41.0.1
|
|
15
|
+
Requires-Dist: pip>=23.1.2
|
|
16
|
+
Requires-Dist: pypomes-core>=0.1.1
|
|
17
|
+
Requires-Dist: setuptools>=68.0.0
|
|
18
|
+
Requires-Dist: wheel>=0.40.0
|
|
File without changes
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = [
|
|
3
|
+
"hatchling"
|
|
4
|
+
]
|
|
5
|
+
build-backend = "hatchling.build"
|
|
6
|
+
|
|
7
|
+
[project]
|
|
8
|
+
name = "pypomes_crypto"
|
|
9
|
+
version = "0.1.1"
|
|
10
|
+
authors = [
|
|
11
|
+
{ name="GT Nunes", email="wisecoder01@gmail.com" },
|
|
12
|
+
]
|
|
13
|
+
description = "A collection of Python pomes, pennyeach (cryptography modules)"
|
|
14
|
+
readme = "README.md"
|
|
15
|
+
requires-python = ">=3.10"
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"License :: OSI Approved :: MIT License",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
]
|
|
21
|
+
dependencies = [
|
|
22
|
+
"asn1crypto>=1.5.1",
|
|
23
|
+
"cryptography>=41.0.1",
|
|
24
|
+
"pip>=23.1.2",
|
|
25
|
+
"pypomes_core>=0.1.1",
|
|
26
|
+
"setuptools>=68.0.0",
|
|
27
|
+
"wheel>=0.40.0"
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[project.urls]
|
|
31
|
+
"Homepage" = "https://github.com/TheWiseCoder/PyPomes-Crypto"
|
|
32
|
+
"Bug Tracker" = "https://github.com/TheWiseCoder/PyPomes-Crypto/issues"
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import hashlib
|
|
2
|
+
import os
|
|
3
|
+
from typing import Final
|
|
4
|
+
from pypomes_core.env_pomes import APP_PREFIX, env_get_str
|
|
5
|
+
|
|
6
|
+
CRYPTO_HASH_ALGORITHM: Final[str] = env_get_str(f"{APP_PREFIX}_DEFAULT_HASH_ALGORITHM", "sha256")
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def crypto_hash(msg: str | bytes, alg: str = CRYPTO_HASH_ALGORITHM) -> bytes:
|
|
10
|
+
"""
|
|
11
|
+
Compute the hash of *msg*, using the algorithm specified in *alg*.
|
|
12
|
+
Return *None* if computing the hash not possible.
|
|
13
|
+
|
|
14
|
+
Supported algorithms: md5, blake2b, blake2s, sha1, sha224, sha256, sha384 sha512,
|
|
15
|
+
sha3_224, sha3_256, sha3_384, sha3_512, shake_128, shake_256.
|
|
16
|
+
|
|
17
|
+
:param msg: The message to calculate the hash for, or a path to a file.
|
|
18
|
+
:param alg: The algorithm to use, or a default value (either 'sha256', or an environment-defined value).
|
|
19
|
+
:return: The hash value obtained, or None if the hash could not be computed.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
hasher = hashlib.new(alg.lower())
|
|
23
|
+
|
|
24
|
+
# what is the type of the argument ?
|
|
25
|
+
if isinstance(msg, bytes):
|
|
26
|
+
# argument is type 'bytes'
|
|
27
|
+
hasher.update(msg)
|
|
28
|
+
|
|
29
|
+
elif os.path.isfile(msg):
|
|
30
|
+
# argument is the path to a file
|
|
31
|
+
buf_size: int = 128 * 1024
|
|
32
|
+
with open(msg, "rb") as f:
|
|
33
|
+
while True:
|
|
34
|
+
file_bytes: bytes = f.read(buf_size)
|
|
35
|
+
if not file_bytes:
|
|
36
|
+
break
|
|
37
|
+
hasher.update(file_bytes)
|
|
38
|
+
|
|
39
|
+
return hasher.digest()
|