binary -> bytes

This commit is contained in:
FabianLars
2025-10-14 18:36:15 +02:00
parent 28ea4dbadc
commit 403f54b78c
3 changed files with 28 additions and 10 deletions
+4 -4
View File
@@ -17,11 +17,11 @@ pub(crate) fn get_string<R: Runtime>(app: AppHandle<R>, key: &str) -> Result<Str
}
#[command]
pub(crate) fn set_binary<R: Runtime>(app: AppHandle<R>, key: &str, value: &[u8]) -> Result<()> {
app.secure_storage().set_binary(key, value)
pub(crate) fn set_bytes<R: Runtime>(app: AppHandle<R>, key: &str, value: &[u8]) -> Result<()> {
app.secure_storage().set_bytes(key, value)
}
#[command]
pub(crate) fn get_binary<R: Runtime>(app: AppHandle<R>, key: &str) -> Result<Vec<u8>> {
app.secure_storage().get_binary(key)
pub(crate) fn get_bytes<R: Runtime>(app: AppHandle<R>, key: &str) -> Result<Vec<u8>> {
app.secure_storage().get_bytes(key)
}
+9 -4
View File
@@ -32,8 +32,8 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
.invoke_handler(tauri::generate_handler![
commands::set_string,
commands::get_string,
commands::set_binary,
commands::get_binary
commands::set_bytes,
commands::get_bytes
])
.setup(|app, _api| {
#[cfg(target_os = "android")]
@@ -62,20 +62,25 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
/// Access to the secure-storage APIs.
pub struct SecureStorage<R: Runtime>(AppHandle<R>);
// TODO: docs
impl<R: Runtime> SecureStorage<R> {
/// Corresponds to [`set_password`](https://docs.rs/keyring-core/latest/keyring_core/struct.Entry.html#method.set_password) in keyring-rs.
pub fn set_string(&self, key: &str, value: &str) -> Result<()> {
Ok(Entry::new(&self.0.config().identifier, key)?.set_password(value)?)
}
/// Corresponds to [`get_password`](https://docs.rs/keyring-core/latest/keyring_core/struct.Entry.html#method.get_password) in keyring-rs.
pub fn get_string(&self, key: &str) -> Result<String> {
Ok(Entry::new(&self.0.config().identifier, key)?.get_password()?)
}
pub fn set_binary(&self, key: &str, value: &[u8]) -> Result<()> {
/// Corresponds to [`set_secret`](https://docs.rs/keyring-core/latest/keyring_core/struct.Entry.html#method.set_secret) in keyring-rs.
pub fn set_bytes(&self, key: &str, value: &[u8]) -> Result<()> {
Ok(Entry::new(&self.0.config().identifier, key)?.set_secret(value)?)
}
pub fn get_binary(&self, key: &str) -> Result<Vec<u8>> {
/// Corresponds to [`get_secret`](https://docs.rs/keyring-core/latest/keyring_core/struct.Entry.html#method.set_password) in keyring-rs.
pub fn get_bytes(&self, key: &str) -> Result<Vec<u8>> {
Ok(Entry::new(&self.0.config().identifier, key)?.get_secret()?)
}
}