Skip to content

Commit

Permalink
base64 zeroization (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasoncolburne authored Mar 10, 2023
1 parent 3cf0a18 commit d0d1dd6
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/core/matter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,10 @@ pub trait Matter: Default {
buffer[szg.ls as usize..].clone_from_slice(&raw);
raw.zeroize();

let b64 = b64_engine::URL_SAFE.encode(&buffer);

let mut b64_vec = Zeroizing::new(vec![0u8; buffer.len() * 4 / 3]);
b64_engine::URL_SAFE.encode_slice(&buffer, &mut b64_vec)?;
// this does a transmute of pointers under the hood so zeroizing the vec should be enough
let b64 = std::str::from_utf8(&b64_vec)?;
Ok(format!("{both}{b64}"))
} else {
let both = code;
Expand All @@ -210,8 +212,9 @@ pub trait Matter: Default {
buffer[ps..].clone_from_slice(&raw);
raw.zeroize();

let b64 = b64_engine::URL_SAFE.encode(&buffer);

let mut b64_vec = Zeroizing::new(vec![0u8; buffer.len() * 4 / 3]);
b64_engine::URL_SAFE.encode_slice(&buffer, &mut b64_vec)?;
let b64 = std::str::from_utf8(&b64_vec)?;
Ok(format!("{both}{}", &b64[cs % 4..]))
}
}
Expand Down

0 comments on commit d0d1dd6

Please sign in to comment.