cmdhash 1.0.0__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.
- cmdhash-1.0.0/PKG-INFO +6 -0
- cmdhash-1.0.0/pyproject.toml +21 -0
- cmdhash-1.0.0/setup.cfg +4 -0
- cmdhash-1.0.0/src/cmdhash.egg-info/PKG-INFO +6 -0
- cmdhash-1.0.0/src/cmdhash.egg-info/SOURCES.txt +8 -0
- cmdhash-1.0.0/src/cmdhash.egg-info/dependency_links.txt +1 -0
- cmdhash-1.0.0/src/cmdhash.egg-info/entry_points.txt +2 -0
- cmdhash-1.0.0/src/cmdhash.egg-info/top_level.txt +3 -0
- cmdhash-1.0.0/src/cmdhash_pingupeng2010/__init__.py +0 -0
- cmdhash-1.0.0/src/cmdhash_pingupeng2010/cmdhash.py +88 -0
cmdhash-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "cmdhash"
|
|
3
|
+
version = "1.0.0"
|
|
4
|
+
authors = [{name="PinguPeng2010"}]
|
|
5
|
+
description = "Command line hasher"
|
|
6
|
+
requires-python = ">=3.10"
|
|
7
|
+
|
|
8
|
+
[build-system]
|
|
9
|
+
requires = ["setuptools>=77.0.3"]
|
|
10
|
+
build-backend = "setuptools.build_meta"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
[project.scripts]
|
|
15
|
+
cmdhash = "cmdhash_pingupeng2010.cmdhash:main"
|
|
16
|
+
|
|
17
|
+
[tool.setuptools]
|
|
18
|
+
py-modules = ["cmdhash"]
|
|
19
|
+
|
|
20
|
+
[tool.setuptools.packages.find]
|
|
21
|
+
where = ["src"]
|
cmdhash-1.0.0/setup.cfg
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
pyproject.toml
|
|
2
|
+
src/cmdhash.egg-info/PKG-INFO
|
|
3
|
+
src/cmdhash.egg-info/SOURCES.txt
|
|
4
|
+
src/cmdhash.egg-info/dependency_links.txt
|
|
5
|
+
src/cmdhash.egg-info/entry_points.txt
|
|
6
|
+
src/cmdhash.egg-info/top_level.txt
|
|
7
|
+
src/cmdhash_pingupeng2010/__init__.py
|
|
8
|
+
src/cmdhash_pingupeng2010/cmdhash.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
File without changes
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import hashlib
|
|
2
|
+
import argparse
|
|
3
|
+
|
|
4
|
+
parser = argparse.ArgumentParser()
|
|
5
|
+
|
|
6
|
+
parser.add_argument(
|
|
7
|
+
"--text",
|
|
8
|
+
type=str,
|
|
9
|
+
metavar='STRING',
|
|
10
|
+
help='Hashes the text provided',
|
|
11
|
+
default=None
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
parser.add_argument(
|
|
15
|
+
"--file",
|
|
16
|
+
type=str,
|
|
17
|
+
metavar='FILENAME',
|
|
18
|
+
help='Reads the file, and hashes contents',
|
|
19
|
+
default=None
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
parser.add_argument(
|
|
23
|
+
'--write',
|
|
24
|
+
metavar='FILENAME',
|
|
25
|
+
help='Writes to a file of the provided name.',
|
|
26
|
+
default=None
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
def hash_hex(data: str) -> str:
|
|
30
|
+
return hashlib.sha256(data.encode()).hexdigest()
|
|
31
|
+
|
|
32
|
+
def hash_bytes(data: str) -> bytes:
|
|
33
|
+
return hashlib.sha256(data.encode()).digest()
|
|
34
|
+
|
|
35
|
+
def hash_hex_from_bytes(data: bytes) -> str:
|
|
36
|
+
return hashlib.sha256(data).hexdigest()
|
|
37
|
+
|
|
38
|
+
def hash_bytes_from_bytes(data: bytes) -> bytes:
|
|
39
|
+
return hashlib.sha256(data).digest()
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def main(text=None, file=None, write=None):
|
|
43
|
+
if text:
|
|
44
|
+
keybytes = (text).encode('utf-8')
|
|
45
|
+
|
|
46
|
+
elif file:
|
|
47
|
+
try:
|
|
48
|
+
with open(file, 'rb') as f:
|
|
49
|
+
keybytes = f.read()
|
|
50
|
+
except FileNotFoundError:
|
|
51
|
+
return f'File did not exist at path: {file}'
|
|
52
|
+
|
|
53
|
+
else:
|
|
54
|
+
return 'Nothing was provided, Use --help for help.'
|
|
55
|
+
|
|
56
|
+
keyhash = hashlib.sha256(keybytes).hexdigest() # type: ignore
|
|
57
|
+
keybin = hashlib.sha256(keybytes).digest() # type: ignore
|
|
58
|
+
|
|
59
|
+
if write:
|
|
60
|
+
filename = write + '.hash'
|
|
61
|
+
binary = write + '.bin.hash'
|
|
62
|
+
try:
|
|
63
|
+
with open(filename, 'x') as norm:
|
|
64
|
+
norm.write(keyhash)
|
|
65
|
+
except:
|
|
66
|
+
cont = input(f'The file: {filename}, already exists. Do you want to continue [y/N]: ').lower() == 'y'
|
|
67
|
+
if cont:
|
|
68
|
+
with open(filename, 'w') as norm:
|
|
69
|
+
norm.write(keyhash)
|
|
70
|
+
|
|
71
|
+
try:
|
|
72
|
+
with open(binary, 'xb') as b:
|
|
73
|
+
b.write(keybin)
|
|
74
|
+
except:
|
|
75
|
+
cont = input(f'The file: {binary}, already exists. Do you want to continue [y/N]: ').lower() == 'y'
|
|
76
|
+
if cont:
|
|
77
|
+
with open(binary, 'wb') as norm:
|
|
78
|
+
norm.write(keybin)
|
|
79
|
+
|
|
80
|
+
else:
|
|
81
|
+
return keyhash
|
|
82
|
+
|
|
83
|
+
if __name__ == '__main__':
|
|
84
|
+
args = parser.parse_args()
|
|
85
|
+
result = main(args.text, args.file, args.write)
|
|
86
|
+
if result is not None:
|
|
87
|
+
print(result)
|
|
88
|
+
|