encode_str

Function encode_str 

Source
pub fn encode_str<'o>(
    input: &[u8],
    output: &'o mut [u8],
) -> Result<&'o str, InvalidSize>
Expand description

Constant-Time Hex Encoding to a &str

§Arguments

  • input - A slice of bytes to be hex-encoded.
  • output - A mutable byte buffer where the encoded string will be written.

§Returns

The encoded string slice (&str).

§Errors

If the output buffer is less than the encoded length (input.len() * 2), this returns InvalidSize.

§Notes

This function is a convenience wrapper around encode_into, which handles the encoding process, this simply returns the str representation in a safe manner.

For full details on the underlying encoding and security/safety guarantees, see encode_into.

§Example

use wolf_crypto::{hex, ct_eq};

let mut output = [0u8; 22]; // 11 * 2
let str_repr = hex::encode_str(b"hello world", &mut output).unwrap();

assert!(ct_eq(str_repr, "68656c6c6f20776f726c64"));