MCPcopy Create free account
hub / github.com/Recordscript/recordscript / symmetric_crypt

Function symmetric_crypt

libs/hbb_common/src/password_security.rs:174–188  ·  view source on GitHub ↗
(data: &[u8], encrypt: bool)

Source from the content-addressed store, hash-verified

172}
173
174pub fn symmetric_crypt(data: &[u8], encrypt: bool) -> Result<Vec<u8>, ()> {
175 use sodiumoxide::crypto::secretbox;
176 use std::convert::TryInto;
177
178 let mut keybuf = crate::get_uuid();
179 keybuf.resize(secretbox::KEYBYTES, 0);
180 let key = secretbox::Key(keybuf.try_into().map_err(|_| ())?);
181 let nonce = secretbox::Nonce([0; secretbox::NONCEBYTES]);
182
183 if encrypt {
184 Ok(secretbox::seal(data, &nonce, &key))
185 } else {
186 secretbox::open(data, &nonce, &key)
187 }
188}
189
190mod test {
191

Callers 4

storeMethod · 0.85
loadMethod · 0.85
encryptFunction · 0.85
decryptFunction · 0.85

Calls 1

get_uuidFunction · 0.85

Tested by

no test coverage detected