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 md5;
use crate::hashinterface::HashAlgorithm;

// Implementation for MD5
pub struct Md5Hasher {
    context: Option<md5::Context>,
}

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