fetchAllKeys method

Future<List<KeyEntryObject>> fetchAllKeys({
  1. bool forUpdate = false,
  2. KeyAlgorithm? algorithm,
  3. int? limit,
  4. Map<String, dynamic>? tagFilter,
  5. String? thumbprint,
})

Fetches a set of keys in the store.

Throws an AskarSessionException if the session is closed. Returns a list of KeyEntryObject containing the fetched keys.

Implementation

Future<List<KeyEntryObject>> fetchAllKeys({
  bool forUpdate = false,
  KeyAlgorithm? algorithm,
  int? limit,
  Map<String, dynamic>? tagFilter,
  String? thumbprint,
}) async {
  _throwOnNullHandle('Cannot fetch all keys with a closed session');

  KeyEntryListHandle? keyEntryListHandle;

  try {
    final fetchKeyResult = await askarSessionFetchAllKeys(
      handle!,
      forUpdate: forUpdate,
      algorithm: algorithm,
      limit: limit,
      tagFilter: tagFilter,
      thumbprint: thumbprint,
    );

    if (!fetchKeyResult.errorCode.isSuccess()) return [];

    keyEntryListHandle = fetchKeyResult.value;

    return KeyEntryList(handle: keyEntryListHandle).toArray();
  } catch (e) {
    throw AskarSessionException('Failed to fetch keys on session: $e');
  } finally {
    if (keyEntryListHandle != null) keyEntryListHandle.free();
  }
}