addTmrAccess method
Add a TMR access to this session for the given authentication factor.
recipients
- A TMR recipient with its associated rights.
Returns the ID of the created TMR access.
Implementation
String addTmrAccess(SealdTmrRecipientWithRights recipient) {
// Dart FFI forces us to copy the data from Uint8List to a newly allocated Pointer<Uint8>
final Pointer<Uint8> nativeOverEncryptionKey =
calloc<Uint8>(recipient.overEncryptionKey.length);
final pointerListOverEncryptionKey =
nativeOverEncryptionKey.asTypedList(recipient.overEncryptionKey.length);
pointerListOverEncryptionKey.setAll(0, recipient.overEncryptionKey);
final Pointer<Pointer<Utf8>> result = calloc<Pointer<Utf8>>();
final Pointer<Pointer<NativeSealdError>> err =
calloc<Pointer<NativeSealdError>>();
final Pointer<Utf8> nativeRecipientType = recipient.type.toNativeUtf8();
final Pointer<Utf8> nativeRecipientValue = recipient.value.toNativeUtf8();
final SealdRecipientRights currentRights =
recipient.rights ?? SealdRecipientRights();
final int resultCode = _bindings.SealdEncryptionSession_AddTmrAccess(
_ptr.pointer(),
nativeRecipientType,
nativeRecipientValue,
nativeOverEncryptionKey,
recipient.overEncryptionKey.length,
currentRights.read ? 1 : 0,
currentRights.forward ? 1 : 0,
currentRights.revoke ? 1 : 0,
result,
err);
calloc.free(nativeRecipientType);
calloc.free(nativeRecipientValue);
calloc.free(nativeOverEncryptionKey);
if (resultCode != 0) {
calloc.free(result);
throw SealdException._fromCPtr(err);
} else {
final String accessId = result.value.toDartString();
calloc.free(result.value);
calloc.free(result);
calloc.free(err);
return accessId;
}
}