MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / decode_32_byte_b64

Function decode_32_byte_b64

nodedb/src/control/security/keystore/vault.rs:215–232  ·  view source on GitHub ↗
(b64: &str)

Source from the content-addressed store, hash-verified

213}
214
215fn decode_32_byte_b64(b64: &str) -> Result<Zeroizing<[u8; 32]>> {
216 let bytes = base64::engine::general_purpose::STANDARD
217 .decode(b64)
218 .map_err(|e| crate::Error::Encryption {
219 detail: format!("Vault plaintext base64 decode failed: {e}"),
220 })?;
221 if bytes.len() != 32 {
222 return Err(crate::Error::Encryption {
223 detail: format!(
224 "Vault plaintext must be 32 bytes after base64 decode, got {}",
225 bytes.len()
226 ),
227 });
228 }
229 let mut key = Zeroizing::new([0u8; 32]);
230 key.copy_from_slice(&bytes);
231 Ok(key)
232}
233
234#[cfg(test)]
235mod tests {

Callers 1

decrypt_with_vaultMethod · 0.85

Calls 2

decodeMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected