This commit is contained in:
2025-12-05 13:13:03 -05:00
parent c9eff77dff
commit 63bd73e444
8 changed files with 46 additions and 226 deletions

View File

@@ -1,4 +1,5 @@
use base64::{Engine as _, engine::general_purpose};
use base64::engine::general_purpose;
use base64::Engine;
use egui_plot::{Line, PlotPoint, PlotPoints, Points};
use emath::Pos2;
use itertools::Itertools;
@@ -150,34 +151,14 @@ pub fn step_helper(max_i: usize, min_x: f64, step: f64) -> Vec<f64> {
.collect()
}
pub const HASH_LENGTH: usize = 8;
/// Represents bytes used to represent hash info
pub type HashBytes = [u8; HASH_LENGTH];
#[allow(dead_code)]
pub fn hashed_storage_create(hashbytes: HashBytes, data: &[u8]) -> String {
let combined_data = [hashbytes.to_vec(), data.to_vec()].concat();
general_purpose::STANDARD.encode(combined_data)
pub fn hashed_storage_create(data: &[u8]) -> String {
general_purpose::STANDARD.encode(data)
}
#[allow(dead_code)]
pub fn hashed_storage_read(data: &str) -> Option<(HashBytes, Vec<u8>)> {
// Decode base64 data
let decoded_bytes = general_purpose::STANDARD.decode(data).ok()?;
// Make sure data is long enough to decode
if HASH_LENGTH > decoded_bytes.len() {
return None;
}
// Split hash and data
let (hash_bytes, data_bytes) = decoded_bytes.split_at(HASH_LENGTH);
// Convert hash bytes to HashBytes
let hash: HashBytes = hash_bytes.try_into().ok()?;
Some((hash, data_bytes.to_vec()))
pub fn hashed_storage_read(data: &str) -> Option<Vec<u8>> {
general_purpose::STANDARD.decode(data).ok()
}
include!(concat!(env!("OUT_DIR"), "/valid_chars.rs"));