askarKeyWrapKey function

AskarResult<EncryptedBuffer> askarKeyWrapKey(
  1. LocalKeyHandle handle,
  2. LocalKeyHandle other, {
  3. Uint8List? nonce,
})

Implementation

AskarResult<EncryptedBuffer> askarKeyWrapKey(
  LocalKeyHandle handle,
  LocalKeyHandle other, {
  Uint8List? nonce,
}) {
  Pointer<NativeEncryptedBuffer> encryptedBufferPtr = calloc<NativeEncryptedBuffer>();

  Pointer<NativeByteBuffer> byteBufferPointer = nullptr;

  try {
    byteBufferPointer = bytesListToByteBuffer(nonce);

    final errorCode = ErrorCode.fromInt(
      nativeAskarKeyWrapKey(
        handle.toInt(),
        other.toInt(),
        byteBufferPointer.ref,
        encryptedBufferPtr,
      ),
    );

    final value =
        (errorCode == ErrorCode.success)
            ? readNativeEncryptedBuffer(encryptedBufferPtr.ref)
            : EncryptedBuffer(Uint8List.fromList([]), 0, 0);

    return AskarResult<EncryptedBuffer>(errorCode, value);
  } finally {
    freeEncryptedBufferPointer(encryptedBufferPtr);
    freeByteBufferPointer(byteBufferPointer);
  }
}