MCPcopy Create free account
hub / github.com/Moosync/Moosync / get_secure

Method get_secure

src-tauri/preferences/src/preferences.rs:214–241  ·  view source on GitHub ↗
(&self, key: String)

Source from the content-addressed store, hash-verified

212
213 #[tracing::instrument(level = "debug", skip(self, key))]
214 pub fn get_secure<T>(&self, key: String) -> Result<T>
215 where
216 T: DeserializeOwned,
217 {
218 #[cfg(not(any(target_os = "android", target_os = "ios")))]
219 {
220 let data: String = self.load_selective(key.clone())?;
221 let mut split = data.split(':');
222 let nonce = split.next().unwrap();
223 let nonce = GenericArray::clone_from_slice(&hex::decode(nonce).unwrap()[0..12]);
224 let ciphertext = hex::decode(split.next().unwrap()).unwrap();
225
226 let secret = self.secret.lock().unwrap();
227 let cipher = ChaCha20Poly1305::new(&secret);
228 let plaintext = String::from_utf8(
229 cipher
230 .decrypt(&nonce, ciphertext.as_slice())
231 .map_err(|e| MoosyncError::String(e.to_string()))?,
232 )?;
233
234 Ok(serde_json::from_str(&plaintext)?)
235 }
236
237 #[cfg(any(target_os = "android", target_os = "ios"))]
238 {
239 self.load_selective(key.clone())
240 }
241 }
242
243 #[tracing::instrument(level = "debug", skip(self, key, value))]
244 pub fn set_secure<T>(&self, key: String, value: Option<T>) -> Result<()>

Callers 1

test_secure_preferencesFunction · 0.45

Calls 2

load_selectiveMethod · 0.80
cloneMethod · 0.80

Tested by 1

test_secure_preferencesFunction · 0.36