askarKeyDeriveEcdh1pu function

AskarResult<LocalKeyHandle> askarKeyDeriveEcdh1pu(
  1. KeyAlgorithm algorithm,
  2. LocalKeyHandle ephemeralKey,
  3. LocalKeyHandle senderKey,
  4. LocalKeyHandle recipientKey,
  5. Uint8List algId,
  6. Uint8List apu,
  7. Uint8List apv, {
  8. Uint8List? ccTag,
  9. required bool receive,
})

Implementation

AskarResult<LocalKeyHandle> askarKeyDeriveEcdh1pu(
  KeyAlgorithm algorithm,
  LocalKeyHandle ephemeralKey,
  LocalKeyHandle senderKey,
  LocalKeyHandle recipientKey,
  Uint8List algId,
  Uint8List apu,
  Uint8List apv, {
  Uint8List? ccTag,
  required bool receive,
}) {
  Pointer<NativeLocalKeyHandle> outPtr = calloc<NativeLocalKeyHandle>();

  Pointer<Utf8> algPointer = nullptr;
  Pointer<NativeByteBuffer> algIdByteBufferPtr = nullptr;
  Pointer<NativeByteBuffer> apuByteBufferPtr = nullptr;
  Pointer<NativeByteBuffer> apvByteBufferPtr = nullptr;
  Pointer<NativeByteBuffer> ccTagByteBufferPtr = nullptr;

  try {
    algPointer = algorithm.value.toNativeUtf8();
    algIdByteBufferPtr = bytesListToByteBuffer(algId);
    apuByteBufferPtr = bytesListToByteBuffer(apu);
    apvByteBufferPtr = bytesListToByteBuffer(apv);
    ccTagByteBufferPtr = bytesListToByteBuffer(ccTag);

    final funcResult = nativeAskarKeyDeriveEcdh1pu(
      algPointer,
      ephemeralKey.toInt(),
      senderKey.toInt(),
      recipientKey.toInt(),
      algIdByteBufferPtr.ref,
      apuByteBufferPtr.ref,
      apvByteBufferPtr.ref,
      ccTagByteBufferPtr.ref,
      boolToInt(receive),
      outPtr,
    );

    final errorCode = ErrorCode.fromInt(funcResult);

    final value = LocalKeyHandle.fromPointer(errorCode, outPtr);

    return AskarResult<LocalKeyHandle>(errorCode, value);
  } finally {
    freePointer(outPtr);
    freePointer(algPointer);
    freeByteBufferPointer(algIdByteBufferPtr);
    freeByteBufferPointer(apuByteBufferPtr);
    freeByteBufferPointer(apvByteBufferPtr);
    freeByteBufferPointer(ccTagByteBufferPtr);
  }
}