mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Fix get_path_from_hash. Add required functions to crypto helper.
This commit is contained in:
parent
a6d37ee2ff
commit
6c20b8c534
@ -11,4 +11,41 @@ class CryptoHelper:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def bytes_to_b64(input_bytes: bytes) -> str:
|
def bytes_to_b64(input_bytes: bytes) -> str:
|
||||||
|
"""
|
||||||
|
Converts input bytes to base64 encoded string.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
input_bytes: Input bytes for conversion.
|
||||||
|
|
||||||
|
Returns: String of base64 encoded bytes.
|
||||||
|
|
||||||
|
"""
|
||||||
|
# base64.b64encode(input_bytes).decode("UTF-8") appends a trailing new line.
|
||||||
|
# That newline is getting pulled off of the string before returning it.
|
||||||
return base64.b64encode(input_bytes).decode("UTF-8").rstrip("\n")
|
return base64.b64encode(input_bytes).decode("UTF-8").rstrip("\n")
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def b64_to_bytes(input_str: str) -> bytes:
|
||||||
|
"""
|
||||||
|
Converts base64 encoded string to bytes.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
input_str: Base64 bytes encodes as a string.
|
||||||
|
|
||||||
|
Returns: Bytes from base64 encoded string.
|
||||||
|
|
||||||
|
"""
|
||||||
|
return base64.b64decode(input_str)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def bytes_to_hex(input_bytes: bytes) -> str:
|
||||||
|
"""
|
||||||
|
Converts input bytes to hex encoded string.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
input_bytes: Bytes to be encoded as hex string.
|
||||||
|
|
||||||
|
Returns: Bytes encoded as hex string.
|
||||||
|
|
||||||
|
"""
|
||||||
|
return input_bytes.hex()
|
||||||
|
@ -345,7 +345,6 @@ class BackupManager:
|
|||||||
Returns: None
|
Returns: None
|
||||||
|
|
||||||
"""
|
"""
|
||||||
print(manifest)
|
|
||||||
# Create file path for depends file
|
# Create file path for depends file
|
||||||
depends_file_path = (
|
depends_file_path = (
|
||||||
backup_repository / "manifest_files" / f"{backup_id}.depends"
|
backup_repository / "manifest_files" / f"{backup_id}.depends"
|
||||||
@ -408,4 +407,6 @@ class BackupManager:
|
|||||||
# Repo path: /path/to/backup/repo/
|
# Repo path: /path/to/backup/repo/
|
||||||
# Hash: 1234...890
|
# Hash: 1234...890
|
||||||
# Example: /path/to/backup/repo/data/12/34...890
|
# Example: /path/to/backup/repo/data/12/34...890
|
||||||
return repository / "data" / str(file_hash[:2]) / str(file_hash[-126:])
|
file_hash = helper.crypto_helper.b64_to_bytes(file_hash)
|
||||||
|
file_hash = helper.crypto_helper.bytes_to_hex(file_hash)
|
||||||
|
return repository / "data" / file_hash[:2] / str(file_hash[-126:])
|
||||||
|
Loading…
Reference in New Issue
Block a user