From 403f54b78cecb155f7514d609ac09866f412b3a3 Mon Sep 17 00:00:00 2001 From: FabianLars Date: Tue, 14 Oct 2025 18:36:15 +0200 Subject: [PATCH] binary -> bytes --- plugins/secure-storage/guest-js/index.ts | 17 +++++++++++++++-- plugins/secure-storage/src/commands.rs | 8 ++++---- plugins/secure-storage/src/lib.rs | 13 +++++++++---- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/plugins/secure-storage/guest-js/index.ts b/plugins/secure-storage/guest-js/index.ts index 24ca858bd..38ed2d48a 100644 --- a/plugins/secure-storage/guest-js/index.ts +++ b/plugins/secure-storage/guest-js/index.ts @@ -5,22 +5,35 @@ import { invoke } from '@tauri-apps/api/core' // TODO: functions to delete entries? +// TODO: docs +/* + * Corresponds to [`set_password`](https://docs.rs/keyring-core/latest/keyring_core/struct.Entry.html#method.set_password) in keyring-rs. + */ export async function setString(key: string, value: string) { return await invoke('plugin:secure-storage|set_string', { key, value }) } +/* + * Corresponds to [`get_password`](https://docs.rs/keyring-core/latest/keyring_core/struct.Entry.html#method.get_password) in keyring-rs. + */ export async function getString(key: string): Promise { return await invoke('plugin:secure-storage|get_string', { key }) } -export async function setBinary( +/* + * Corresponds to [`set_secret`](https://docs.rs/keyring-core/latest/keyring_core/struct.Entry.html#method.set_secret) in keyring-rs. + */ +export async function setBytes( key: string, value: number[] | Uint8Array | ArrayBuffer ) { return await invoke('plugin:secure-storage|set_binary', { key, value }) } -export async function getBinary(key: string): Promise { +/* + * Corresponds to [`get_secret`](https://docs.rs/keyring-core/latest/keyring_core/struct.Entry.html#method.set_password) in keyring-rs. + */ +export async function getBytes(key: string): Promise { return await invoke('plugin:secure-storage|set_string', { key }) } diff --git a/plugins/secure-storage/src/commands.rs b/plugins/secure-storage/src/commands.rs index b8c373204..ed68c2ed4 100644 --- a/plugins/secure-storage/src/commands.rs +++ b/plugins/secure-storage/src/commands.rs @@ -17,11 +17,11 @@ pub(crate) fn get_string(app: AppHandle, key: &str) -> Result(app: AppHandle, key: &str, value: &[u8]) -> Result<()> { - app.secure_storage().set_binary(key, value) +pub(crate) fn set_bytes(app: AppHandle, key: &str, value: &[u8]) -> Result<()> { + app.secure_storage().set_bytes(key, value) } #[command] -pub(crate) fn get_binary(app: AppHandle, key: &str) -> Result> { - app.secure_storage().get_binary(key) +pub(crate) fn get_bytes(app: AppHandle, key: &str) -> Result> { + app.secure_storage().get_bytes(key) } diff --git a/plugins/secure-storage/src/lib.rs b/plugins/secure-storage/src/lib.rs index b032da0d7..50724a085 100644 --- a/plugins/secure-storage/src/lib.rs +++ b/plugins/secure-storage/src/lib.rs @@ -32,8 +32,8 @@ pub fn init() -> TauriPlugin { .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() -> TauriPlugin { /// Access to the secure-storage APIs. pub struct SecureStorage(AppHandle); +// TODO: docs impl SecureStorage { + /// 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 { 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> { + /// 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> { Ok(Entry::new(&self.0.config().identifier, key)?.get_secret()?) } }