Fixed warnings and migrated to TTP.

This commit is contained in:
Ben Markendorf 2026-03-19 21:02:47 +01:00
commit 7a331d4450
20 changed files with 107 additions and 55 deletions

View file

@ -8,6 +8,7 @@ use sha2::{Digest, Sha256};
use x448::{PublicKey, Secret, SharedSecret};
/// Errors for crypto operations
#[allow(dead_code)]
#[derive(Debug)]
pub enum CryptoError {
Base64Decode(base64::DecodeError),
@ -23,11 +24,13 @@ impl From<base64::DecodeError> for CryptoError {
}
}
#[allow(dead_code)]
pub struct KeyPair {
pub secret: Secret,
pub public: PublicKey,
}
#[allow(dead_code)]
pub fn generate_keypair() -> KeyPair {
let mut buf = [0u8; 56];
let mut rng = OsRng;
@ -64,6 +67,7 @@ fn derive_aes_key(shared: &SharedSecret) -> [u8; 32] {
key
}
#[allow(dead_code)]
pub fn encrypt_b64(
base64_secret: &str,
base64_peer_pub: &str,
@ -131,12 +135,14 @@ pub fn decrypt(
Ok(plaintext)
}
#[allow(dead_code)]
pub fn hash_it(input: &str) -> Vec<u8> {
let mut hasher = Sha256::new();
hasher.update(input.as_bytes());
hasher.finalize().to_vec()
}
#[allow(dead_code)]
pub fn hex_hash(input: &str) -> String {
let digest = hash_it(input);
digest.iter().map(|b| format!("{:02x}", b)).collect()

View file

@ -8,6 +8,7 @@ use sha2::{Digest, Sha256};
use x448::{PublicKey, Secret};
// --- Custom Errors ---
#[allow(dead_code)]
#[derive(Debug)]
pub enum SecurePayloadError {
InvalidBase64,
@ -18,6 +19,7 @@ pub enum SecurePayloadError {
}
// --- Data Format Enum ---
#[allow(dead_code)]
#[derive(Clone, Copy, Debug)]
pub enum DataFormat {
Raw,
@ -66,6 +68,7 @@ impl SecurePayload {
}
/// Helper to get the public key associated with this instance's private key.
#[allow(dead_code)]
pub fn get_public_key(&self) -> [u8; 56] {
*PublicKey::from(&self.private_key).as_bytes()
}
@ -80,11 +83,13 @@ impl SecurePayload {
}
/// Access raw bytes directly
#[allow(dead_code)]
pub fn get_bytes(&self) -> &[u8] {
&self.inner_data
}
/// Returns the SHA-256 Hash of the data in the requested format
#[allow(dead_code)]
pub fn get_hash(&self, format: DataFormat) -> String {
let mut hasher = Sha256::new();
hasher.update(&self.inner_data);
@ -134,6 +139,7 @@ impl SecurePayload {
}
/// Decrypts the held data providing the sender's public key manually.
#[allow(dead_code)]
pub fn decrypt_to_format(
&self,
peer_public_key_bytes: &[u8; 56],

View file

@ -37,6 +37,7 @@ pub fn delete_user_directory(user_id: i64) {
let _ = delete_dir_recursive(&user_dir);
}
#[allow(dead_code)]
pub fn load_file_buf(path: &str, name: &str) -> io::Result<BufReader<File>> {
let dir = Path::new(&get_directory()).join(path);
let file_path = dir.join(name);
@ -63,6 +64,7 @@ pub fn load_file_buf(path: &str, name: &str) -> io::Result<BufReader<File>> {
let file = File::open(&file_path)?;
Ok(BufReader::new(file))
}
#[allow(dead_code)]
pub fn has_file(path: &str, name: &str) -> bool {
let dir = Path::new(&get_directory()).join(path);
let file_path = dir.join(name);
@ -77,6 +79,7 @@ pub fn has_file(path: &str, name: &str) -> bool {
true
}
#[allow(dead_code)]
pub fn has_dir(path: &str) -> bool {
let dir = Path::new(&get_directory()).join(path);
@ -87,6 +90,7 @@ pub fn has_dir(path: &str) -> bool {
true
}
#[allow(dead_code)]
pub fn load_file(path: &str, name: &str) -> String {
let dir = Path::new(&get_directory()).join(path);
let file_path = dir.join(name);
@ -130,6 +134,7 @@ pub fn load_file_vec(path: &str, name: &str) -> Result<Vec<u8>, std::io::Error>
std::fs::read(file_path)
}
#[allow(dead_code)]
pub fn save_file(path: &str, name: &str, value: &str) {
let dir = Path::new(&get_directory()).join(path);
let file_path = dir.join(name);
@ -157,6 +162,7 @@ pub fn save_file(path: &str, name: &str, value: &str) {
}
}
#[allow(dead_code)]
pub fn get_children(path: &str) -> Vec<String> {
let dir = Path::new(&get_directory()).join(path);
let mut children = Vec::new();

View file

@ -9,10 +9,11 @@ use std::{
};
use ansi_term::Color;
use epsilon_core::{CommunicationValue, DataTypes, DataValue};
use ttp_core::{CommunicationValue, DataTypes, DataValue};
static LOGGER: OnceLock<mpsc::Sender<LogMessage>> = OnceLock::new();
#[allow(dead_code)]
#[derive(Clone, Copy)]
pub enum PrintType {
Call,