Skip to content

Commit

Permalink
new method is_empty for LoginsStore
Browse files Browse the repository at this point in the history
to check whether the database is empty
  • Loading branch information
jo committed Jan 9, 2025
1 parent 8c4aa95 commit ec4de55
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,16 @@ pub fn add(&self, entry: LoginEntry) -> ApiResult<Login>
pub fn add_or_update(&self, entry: LoginEntry) -> ApiResult<Login>
```

New LoginsStore methods:
```
// Checking whether the database contains logins (does not utilize the `EncryptorDecryptor`):
is_empty(&self) -> ApiResult<bool>
// Checking for the Existence of Logins for a given base domain (also does not utilize the `EncryptorDecryptor`):
has_logins_by_base_domain(&self, base_domain: &str) -> ApiResult<bool>
```

The crypto primitives `encrypt`, `decrypt`, `encrypt_struct` and `decrypt_struct` are not exposed anymore via UniFFI, as well as `EncryptedLogin` will not be exposed anymore. In addition we also do not expose the structs `RecordFields`, `LoginFields` and `SecureLoginFields` anymore.

Checking for the Existence of Logins for a given Base Domain In order to check for the existence of stored logins for a given base domain, we provide an additional store method, has_logins_by_base_domain(&self, base_domain: &str), which does not utilize the `EncryptorDecryptor`.

##### SyncEngine
The logins sync engine has been adapted for above EncryptorDecryptor trait and therefore does not support a `set_local_encryption_key` method anymore.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,27 @@ class DatabaseLoginsStorage(dbPath: String, keyManager: KeyManager) : AutoClosea
}
}

@Throws(LoginsApiException::class)
fun isEmpty(): Boolean {
return readQueryCounters.measure {
store.isEmpty()
}
}

@Throws(LoginsApiException::class)
fun list(): List<Login> {
return readQueryCounters.measure {
store.list()
}
}

@Throws(LoginsApiException::class)
fun hasLoginsByBaseDomain(baseDomain: String): Boolean {
return readQueryCounters.measure {
store.hasLoginsByBaseDomain(baseDomain)
}
}

@Throws(LoginsApiException::class)
fun getByBaseDomain(baseDomain: String): List<Login> {
return readQueryCounters.measure {
Expand Down
14 changes: 14 additions & 0 deletions components/logins/ios/Logins/LoginsStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,27 @@ open class LoginsStorage {
}
}

/// Check whether the database is empty.
open func isEmpty() throws -> Bool {
return try queue.sync {
try self.store.isEmpty()
}
}

/// Get the entire list of records.
open func list() throws -> [Login] {
return try queue.sync {
try self.store.list()
}
}

/// Check whether logins exist for some base domain.
open func hasLoginsByBaseDomain(baseDomain: String) throws -> Bool {
return try queue.sync {
try self.store.hasLoginsByBaseDomain(baseDomain: baseDomain)
}
}

/// Get the list of records for some base domain.
open func getByBaseDomain(baseDomain: String) throws -> [Login] {
return try queue.sync {
Expand Down
3 changes: 3 additions & 0 deletions components/logins/src/logins.udl
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ interface LoginStore {
[Throws=LoginsApiError]
void touch([ByRef] string id);

[Throws=LoginsApiError]
boolean is_empty();

[Throws=LoginsApiError]
sequence<Login> list();

Expand Down
5 changes: 5 additions & 0 deletions components/logins/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ impl LoginStore {
Ok(Self { db, encdec })
}

#[handle_error(Error)]
pub fn is_empty(&self) -> ApiResult<bool> {
self.db.lock().get_all().map(|logins| logins.is_empty())
}

#[handle_error(Error)]
pub fn list(&self) -> ApiResult<Vec<Login>> {
self.db.lock().get_all().and_then(|logins| {
Expand Down

0 comments on commit ec4de55

Please sign in to comment.