askarKeyAeadEncrypt function
Implementation
AskarResult<EncryptedBuffer> askarKeyAeadEncrypt(
LocalKeyHandle localKeyHandle,
Uint8List message, {
Uint8List? nonce,
Uint8List? aad,
}) {
Pointer<NativeEncryptedBuffer> outPtr = calloc<NativeEncryptedBuffer>();
Pointer<NativeByteBuffer> messagePtr = nullptr;
Pointer<NativeByteBuffer> noncePtr = nullptr;
Pointer<NativeByteBuffer> aadPtr = nullptr;
try {
messagePtr = bytesListToByteBuffer(message);
noncePtr = bytesListToByteBuffer(nonce);
aadPtr = bytesListToByteBuffer(aad);
final funcResult = nativeAskarKeyAeadEncrypt(
localKeyHandle.toInt(),
messagePtr.ref,
noncePtr.ref,
aadPtr.ref,
outPtr,
);
final errorCode = ErrorCode.fromInt(funcResult);
final value =
(errorCode == ErrorCode.success)
? readNativeEncryptedBuffer(outPtr.ref)
: EncryptedBuffer(Uint8List.fromList([]), 0, 0);
return AskarResult<EncryptedBuffer>(errorCode, value);
} finally {
freeEncryptedBufferPointer(outPtr);
freeByteBufferPointer(messagePtr);
freeByteBufferPointer(noncePtr);
freeByteBufferPointer(aadPtr);
}
}