mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-09-26 21:41:48 +02:00
binary -> bytes
This commit is contained in:
@@ -5,22 +5,35 @@
|
|||||||
import { invoke } from '@tauri-apps/api/core'
|
import { invoke } from '@tauri-apps/api/core'
|
||||||
|
|
||||||
// TODO: functions to delete entries?
|
// 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) {
|
export async function setString(key: string, value: string) {
|
||||||
return await invoke('plugin:secure-storage|set_string', { key, value })
|
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<string> {
|
export async function getString(key: string): Promise<string> {
|
||||||
return await invoke('plugin:secure-storage|get_string', { key })
|
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,
|
key: string,
|
||||||
value: number[] | Uint8Array | ArrayBuffer
|
value: number[] | Uint8Array | ArrayBuffer
|
||||||
) {
|
) {
|
||||||
return await invoke('plugin:secure-storage|set_binary', { key, value })
|
return await invoke('plugin:secure-storage|set_binary', { key, value })
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getBinary(key: string): Promise<number[]> {
|
/*
|
||||||
|
* 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<number[]> {
|
||||||
return await invoke('plugin:secure-storage|set_string', { key })
|
return await invoke('plugin:secure-storage|set_string', { key })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,11 +17,11 @@ pub(crate) fn get_string<R: Runtime>(app: AppHandle<R>, key: &str) -> Result<Str
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[command]
|
#[command]
|
||||||
pub(crate) fn set_binary<R: Runtime>(app: AppHandle<R>, key: &str, value: &[u8]) -> Result<()> {
|
pub(crate) fn set_bytes<R: Runtime>(app: AppHandle<R>, key: &str, value: &[u8]) -> Result<()> {
|
||||||
app.secure_storage().set_binary(key, value)
|
app.secure_storage().set_bytes(key, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[command]
|
#[command]
|
||||||
pub(crate) fn get_binary<R: Runtime>(app: AppHandle<R>, key: &str) -> Result<Vec<u8>> {
|
pub(crate) fn get_bytes<R: Runtime>(app: AppHandle<R>, key: &str) -> Result<Vec<u8>> {
|
||||||
app.secure_storage().get_binary(key)
|
app.secure_storage().get_bytes(key)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,8 +32,8 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
|||||||
.invoke_handler(tauri::generate_handler![
|
.invoke_handler(tauri::generate_handler![
|
||||||
commands::set_string,
|
commands::set_string,
|
||||||
commands::get_string,
|
commands::get_string,
|
||||||
commands::set_binary,
|
commands::set_bytes,
|
||||||
commands::get_binary
|
commands::get_bytes
|
||||||
])
|
])
|
||||||
.setup(|app, _api| {
|
.setup(|app, _api| {
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
@@ -62,20 +62,25 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
|||||||
/// Access to the secure-storage APIs.
|
/// Access to the secure-storage APIs.
|
||||||
pub struct SecureStorage<R: Runtime>(AppHandle<R>);
|
pub struct SecureStorage<R: Runtime>(AppHandle<R>);
|
||||||
|
|
||||||
|
// TODO: docs
|
||||||
impl<R: Runtime> SecureStorage<R> {
|
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<()> {
|
pub fn set_string(&self, key: &str, value: &str) -> Result<()> {
|
||||||
Ok(Entry::new(&self.0.config().identifier, key)?.set_password(value)?)
|
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> {
|
pub fn get_string(&self, key: &str) -> Result<String> {
|
||||||
Ok(Entry::new(&self.0.config().identifier, key)?.get_password()?)
|
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)?)
|
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()?)
|
Ok(Entry::new(&self.0.config().identifier, key)?.get_secret()?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user