askarKeyCryptoBox function
Implementation
AskarResult<Uint8List> askarKeyCryptoBox(
LocalKeyHandle recipKey,
LocalKeyHandle senderKey,
Uint8List message,
Uint8List nonce,
) {
Pointer<NativeSecretBuffer> secretBufferPtr = calloc<NativeSecretBuffer>();
Pointer<NativeByteBuffer> messageByteBufferPtr = nullptr;
Pointer<NativeByteBuffer> nonceByteBufferPtr = nullptr;
try {
messageByteBufferPtr = bytesListToByteBuffer(message);
nonceByteBufferPtr = bytesListToByteBuffer(nonce);
final funcResult = nativeAskarKeyCryptoBox(
recipKey.toInt(),
senderKey.toInt(),
messageByteBufferPtr.ref,
nonceByteBufferPtr.ref,
secretBufferPtr,
);
final errorCode = ErrorCode.fromInt(funcResult);
final Uint8List value =
(errorCode == ErrorCode.success)
? secretBufferToBytesList(secretBufferPtr.ref)
: Uint8List(0);
return AskarResult<Uint8List>(errorCode, value);
} finally {
freeSecretBufferPointer(secretBufferPtr);
freeByteBufferPointer(messageByteBufferPtr);
freeByteBufferPointer(nonceByteBufferPtr);
}
}