jsonhash 0.2.0

A command-line tool to generate hash values for files. SHA256 and MD5. Output and Error messages in JSON format.
Documentation
use sha2::{Digest as Sha2Digest, Sha256};
use crate::hashinterface::HashAlgorithm;

// Implementation for SHA-256
pub struct Sha256Hasher {
    hasher: Option<Sha256>,
}

impl HashAlgorithm for Sha256Hasher {
    fn new() -> Self {
        Self {
            hasher: Some(Sha256::new())
        }
    }
    
    fn update(&mut self, data: &[u8]) {
        if let Some(ref mut hasher) = self.hasher {
            hasher.update(data);
        }
    }
    
    fn finalize(&mut self) -> String {
        if let Some(hasher) = self.hasher.take() {
            format!("{:x}", hasher.finalize())
        } else {
            String::new() // Already finalized
        }
    }
}