convertGroupTMRTemporaryKey method

void convertGroupTMRTemporaryKey(
  1. String groupId,
  2. String temporaryKeyId,
  3. String tmrJWT,
  4. Uint8List rawOverEncryptionKey, {
  5. bool deleteOnConvert = false,
})

Convert a group TMR temporary key to become a group member.

groupId The Id of the group for which to convert a TMR key. temporaryKeyId The Id of the temporary key to convert. tmrJWT TMR JWT to use. rawOverEncryptionKey The raw encryption key to use. This MUST be a cryptographically random buffer of 64 bytes. deleteOnConvert Should the key be deleted after conversion.

Implementation

void convertGroupTMRTemporaryKey(String groupId, String temporaryKeyId,
    String tmrJWT, Uint8List rawOverEncryptionKey,
    {bool deleteOnConvert = false}) {
  if (_closed) {
    throw SealdException(
        code: "INSTANCE_CLOSED",
        id: "FLUTTER_INSTANCE_CLOSED",
        description: "Instance already closed.");
  }
  final Pointer<Utf8> nativeGroupId = groupId.toNativeUtf8();
  final Pointer<Utf8> nativeTemporaryKeyId = temporaryKeyId.toNativeUtf8();
  final Pointer<Utf8> nativeTmrJWT = tmrJWT.toNativeUtf8();
  final int deleteOnConvertInt = deleteOnConvert ? 1 : 0;
  // Dart FFI forces us to copy the data from Uint8List to a newly allocated Pointer<Uint8>
  final Pointer<Uint8> nativeRawOverEncryptionKey =
      calloc<Uint8>(rawOverEncryptionKey.length);
  final pointerListRawOverEncryptionKey =
      nativeRawOverEncryptionKey.asTypedList(rawOverEncryptionKey.length);
  pointerListRawOverEncryptionKey.setAll(0, rawOverEncryptionKey);

  final Pointer<Pointer<NativeSealdError>> err =
      calloc<Pointer<NativeSealdError>>();

  final int resultCode = _bindings.SealdSdk_ConvertGroupTMRTemporaryKey(
      _ptr.pointer(),
      nativeGroupId,
      nativeTemporaryKeyId,
      nativeTmrJWT,
      nativeRawOverEncryptionKey,
      rawOverEncryptionKey.length,
      deleteOnConvertInt,
      err);

  calloc.free(nativeGroupId);
  calloc.free(nativeTemporaryKeyId);
  calloc.free(nativeTmrJWT);
  calloc.free(nativeRawOverEncryptionKey);

  if (resultCode != 0) {
    throw SealdException._fromCPtr(err);
  } else {
    calloc.free(err);
  }
}