Skip to content

Commit

Permalink
Make PinId methods public
Browse files Browse the repository at this point in the history
  • Loading branch information
sosthene-nitrokey committed Aug 22, 2023
1 parent 203a90d commit e9caedb
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,19 @@ const BACKEND_DIR: &str = "backend-auth";
pub struct PinId(u8);

impl PinId {
fn path(&self) -> PathBuf {
/// Get the path to the PIN id.
///
/// Path are of the form `pin.XX` where `xx` is the hexadecimal representation of the PIN number.
pub fn path(&self) -> PathBuf {
let mut path = [0; 6];
path[0..4].copy_from_slice(b"pin.");
path[4..].copy_from_slice(&self.hex());

PathBuf::from(&path)
}

fn hex(&self) -> [u8; 2] {
/// Get the hex representation of the PIN id
pub fn hex(&self) -> [u8; 2] {
const CHARS: &[u8; 16] = b"0123456789abcdef";
[
CHARS[usize::from(self.0 >> 4)],
Expand Down

0 comments on commit e9caedb

Please sign in to comment.