Minor doc, format, and clippy fixes.

This commit is contained in:
2025-12-29 11:26:18 -07:00
parent 014f6ea2d6
commit 65c4b220ae
6 changed files with 20 additions and 18 deletions

2
Cargo.lock generated
View File

@@ -4,4 +4,4 @@ version = 4
[[package]]
name = "emsha"
version = "1.0.2"
version = "1.0.3"

View File

@@ -5,7 +5,7 @@ repository = "https://git.wntrmute.dev/wntrmute/emsha-rs"
categories = ["cryptography", "no-std", "embedded"]
keywords = ["sha256", "hmac", "hash", "embedded", "no_std"]
license-file = "LICENSE"
version = "1.0.2"
version = "1.0.3"
edition = "2024"
publish = ["kellnr"]

View File

@@ -1,7 +1,7 @@
//! Demonstrator of SHA256 hashing.
use emsha::{self, sha256, Hash};
use emsha::hexstr::to_hex;
use emsha::{self, Hash, sha256};
use std::fs::File;
use std::io::Read;
use std::io::{self, BufReader};
@@ -11,10 +11,9 @@ const CHUNK_SIZE: usize = 512;
fn transmute_error(res: emsha::Result<()>) -> io::Result<()> {
match res {
Ok(_) => Ok(()),
Err(e) => return Err(
io::Error::new(
io::ErrorKind::Other,
format!("{:}", e), /* error */)),
Err(e) => {
Err(io::Error::other(format!("{:}", e) /* error */))
}
}
}
@@ -49,8 +48,8 @@ fn hash_file(path: &str) -> io::Result<()> {
fn main() -> io::Result<()> {
let args: Vec<String> = std::env::args().collect();
for i in 1..args.len() {
hash_file(args[i].as_str())?;
for arg in args.iter().skip(1) {
hash_file(arg.as_str())?;
}
Ok(())

View File

@@ -1,6 +1,6 @@
#[inline]
pub(crate) fn rotr32(x: u32, n: u8) -> u32 {
(x >> n) | (x << (32 - n))
x.rotate_right(n as u32)
}
#[allow(non_snake_case)] // the name is taken from the RFC

View File

@@ -1,4 +1,5 @@
//! Various utilities for encoding to and from hex strings.
const LUT: [&str; 256] = [
"00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "0a",
"0b", "0c", "0d", "0e", "0f", "10", "11", "12", "13", "14", "15",
@@ -26,7 +27,8 @@ const LUT: [&str; 256] = [
"fd", "fe", "ff",
];
/// Convert the binary array in `input` to a hex-encoded array in `output`.
/// Convert the binary array in `input` to a hex-encoded array in
/// `output`.
pub fn to_hex<const N: usize, const M: usize>(
input: &[u8; N],
output: &mut [u8; M],
@@ -44,7 +46,8 @@ pub fn to_hex<const N: usize, const M: usize>(
}
}
///
/// Convert a hex string array in `input` to a binary array in
/// `output`.
pub fn from_hex<const N: usize, const M: usize>(
input: &[u8; M],
output: &mut [u8; N],
@@ -55,7 +58,7 @@ pub fn from_hex<const N: usize, const M: usize>(
while i < input.len() {
let s = LUT[input[i] as usize].as_bytes();
output[o] = s[0] << 4 + s[1];
output[o] = (s[0] << 4) + s[1];
i += 2;
o += 1;

View File

@@ -116,6 +116,6 @@ pub trait Hash {
}
mod common;
pub mod hexstr;
pub mod hmac;
pub mod sha256;
pub mod hexstr;