mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2025-09-10 08:19:23 +00:00
Add checksum verification for portable backups
This commit is contained in:
@@ -14,8 +14,9 @@ import hashlib
|
||||
import logging
|
||||
import sys
|
||||
import os
|
||||
import json
|
||||
import traceback
|
||||
from typing import Optional
|
||||
from typing import Optional, Any
|
||||
|
||||
from termcolor import colored
|
||||
|
||||
@@ -25,6 +26,17 @@ from constants import APP_DIR, SCRIPT_CHECKSUM_FILE
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def canonical_json_dumps(data: Any) -> str:
|
||||
"""Serialize ``data`` into a canonical JSON string."""
|
||||
return json.dumps(data, sort_keys=True, separators=(",", ":"))
|
||||
|
||||
|
||||
def json_checksum(data: Any) -> str:
|
||||
"""Return SHA-256 checksum of canonical JSON serialization of ``data``."""
|
||||
canon = canonical_json_dumps(data)
|
||||
return hashlib.sha256(canon.encode("utf-8")).hexdigest()
|
||||
|
||||
|
||||
def calculate_checksum(file_path: str) -> Optional[str]:
|
||||
"""
|
||||
Calculates the SHA-256 checksum of the given file.
|
||||
|
Reference in New Issue
Block a user