retrieveIdentityFromPassword method

Uint8List retrieveIdentityFromPassword(
  1. String userId,
  2. String password
)

Retrieve the identity stored on the SSKS server for the given userId, and decrypt it with the given password.

If you use an incorrect password multiple times, the server may throttle your requests. In this case, you will receive an error Request throttled, retry after {N}s, with {N} the number of seconds during which you cannot try again.

userId - The ID of the user. password - The password to encrypt the key. identity - The identity to save.

Returns a Uint8List containing the retrieved identity.

Implementation

Uint8List retrieveIdentityFromPassword(String userId, String password) {
  final Pointer<Utf8> nativeUserId = userId.toNativeUtf8();
  final Pointer<Utf8> nativePassword = password.toNativeUtf8();
  final Pointer<Pointer<Uint8>> result = calloc<Pointer<Uint8>>();
  final Pointer<Int> resultLen = calloc<Int>();
  final Pointer<Pointer<NativeSealdError>> err =
      calloc<Pointer<NativeSealdError>>();

  final int resultCode =
      _bindings.SealdSsksPasswordPlugin_RetrieveIdentityFromPassword(
          _ptr.pointer(),
          nativeUserId,
          nativePassword,
          result,
          resultLen,
          err);

  calloc.free(nativeUserId);
  calloc.free(nativePassword);

  if (resultCode != 0) {
    calloc.free(result);
    calloc.free(resultLen);
    throw SealdException._fromCPtr(err);
  } else {
    final Uint8List cIdentityExport =
        result.value.asTypedList(resultLen.value);
    // Copying the data in a Dart-created Uint8List, to avoid having to free memory later
    final Uint8List res = Uint8List.fromList(cIdentityExport);
    calloc.free(result.value);
    calloc.free(result);
    calloc.free(resultLen);
    calloc.free(err);
    return res;
  }
}