askarSessionFetchAllKeys function

Future<AskarResult<KeyEntryListHandle>> askarSessionFetchAllKeys(
  1. SessionHandle handle, {
  2. required bool forUpdate,
  3. KeyAlgorithm? algorithm,
  4. String? thumbprint,
  5. Map? tagFilter,
  6. int? limit,
})

Implementation

Future<AskarResult<KeyEntryListHandle>> askarSessionFetchAllKeys(
  SessionHandle handle, {
  required bool forUpdate,
  KeyAlgorithm? algorithm,
  String? thumbprint,
  Map? tagFilter,
  int? limit,
}) async {
  Pointer<Utf8> algPointer = nullptr;
  Pointer<Utf8> thumbprintPointer = nullptr;
  Pointer<Utf8> tagFilterPointer = nullptr;

  final algorithmStr = (algorithm == null) ? "" : algorithm.value;

  try {
    algPointer = algorithmStr.toNativeUtf8();
    thumbprintPointer = (thumbprint ?? "").toNativeUtf8();
    tagFilterPointer = jsonEncode(tagFilter ?? {}).toNativeUtf8();

    final callback = newCallbackWithHandle();

    final initialResult = nativeAskarSessionFetchAllKeys(
      handle.toInt(),
      algPointer,
      thumbprintPointer,
      tagFilterPointer,
      (limit ?? 0),
      boolToInt(forUpdate),
      callback.nativeCallable.nativeFunction,
      callback.id,
    );

    final completedResult = await callback.handleResult(initialResult);

    return AskarResult(
      completedResult.errorCode,
      KeyEntryListHandle(completedResult.value),
    );
  } finally {
    freePointer(algPointer);
    freePointer(thumbprintPointer);
    freePointer(tagFilterPointer);
  }
}