Skip to content

Commit 5475921

Browse files
committed
Export hex module
1 parent 4aeb8f2 commit 5475921

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

negentropy/src/hex.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
// Copyright (c) 2022-2023 Yuki Kishimoto
22
// Distributed under the MIT software license
33

4+
//! Hex
5+
46
use alloc::string::String;
57
use alloc::vec::Vec;
68
use core::fmt;
79

10+
/// Hex error
811
#[derive(Debug, PartialEq, Eq)]
912
pub enum Error {
1013
/// An invalid character was found
11-
InvalidHexCharacter { c: char, index: usize },
14+
InvalidHexCharacter {
15+
/// Char
16+
c: char,
17+
/// Char index
18+
index: usize,
19+
},
1220
/// A hex string's length needs to be even, as two digits correspond to
1321
/// one byte.
1422
OddLength,
@@ -37,6 +45,7 @@ fn from_digit(num: u8) -> char {
3745
}
3846
}
3947

48+
/// Hex encode
4049
pub fn encode<T>(data: T) -> String
4150
where
4251
T: AsRef<[u8]>,
@@ -62,6 +71,7 @@ const fn val(c: u8, idx: usize) -> Result<u8, Error> {
6271
}
6372
}
6473

74+
/// Hex decode
6575
pub fn decode<T>(hex: T) -> Result<Vec<u8>, Error>
6676
where
6777
T: AsRef<[u8]>,

negentropy/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use core::fmt;
2828
use std::collections::HashSet;
2929

3030
mod bytes;
31-
mod hex;
31+
pub mod hex;
3232
mod sha256;
3333

3434
pub use self::bytes::Bytes;

0 commit comments

Comments
 (0)