arnaucube
arnaucube/miden-cryptoPublic Self-hosted repository
miden-crypto/src/utils/mod.rs
src/utils/mod.rsRaw
 1use super::{utils::string::String, Word};
 2use core::fmt::{self, Write};
 3
 4#[cfg(not(feature = "std"))]
 5pub use alloc::format;
 6
 7#[cfg(feature = "std")]
 8pub use std::format;
 9
10mod kv_map;
11
12// RE-EXPORTS
13// ================================================================================================
14pub use winter_utils::{
15    string, uninit_vector, Box, ByteReader, ByteWriter, Deserializable, DeserializationError,
16    Serializable, SliceReader,
17};
18
19pub mod collections {
20    pub use super::kv_map::*;
21    pub use winter_utils::collections::*;
22}
23
24// UTILITY FUNCTIONS
25// ================================================================================================
26
27/// Converts a [Word] into hex.
28pub fn word_to_hex(w: &Word) -> Result<String, fmt::Error> {
29    let mut s = String::new();
30
31    for byte in w.iter().flat_map(|e| e.to_bytes()) {
32        write!(s, "{byte:02x}")?;
33    }
34
35    Ok(s)
36}