From 73ea4746097fd389100555d581214fb266d62d07 Mon Sep 17 00:00:00 2001 From: Tania Mathern Date: Wed, 13 Nov 2024 19:48:12 -0800 Subject: [PATCH 01/25] Makefile --- Makefile | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..33585bbf --- /dev/null +++ b/Makefile @@ -0,0 +1,22 @@ +# For Python bindings =========================================================== + +# Start from clean env: Delete `.venv`, then `python3 -m venv .venv` +# Pre-requisite: Python virtual environment is active (source .venv/bin/activate) +build-python: release + python3 -m venv .venv + python3 -m pip install -r requirements.txt + python3 -m pip install -r requirements-dev.txt + python3 -m pip install -U c2pa-python + cargo run --features=uniffi/cli --bin uniffi-bindgen generate src/adobe_api.udl -n --language python -o target/python + maturin develop + python3 ./tests/test_api.py + +# Pre-requisite: Python virtual environment is active (source .venv/bin/activate) +python-redeploy: release + maturin develop + +# Pre-requisite: Python virtual environment is active (source .venv/bin/activate) +python-test: + python3 -m pip install -r requirements-dev.txt + python3 -m pip install -U c2pa-python + python3 ./tests/test_api.py \ No newline at end of file From a51013e99068224fed730a2e3f82129321930299 Mon Sep 17 00:00:00 2001 From: Tania Mathern Date: Wed, 13 Nov 2024 20:45:41 -0800 Subject: [PATCH 02/25] WIP --- .gitignore | 2 +- c2pa/c2pa/__init__.py | 1 + c2pa/c2pa/c2pa.py | 1945 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1947 insertions(+), 1 deletion(-) create mode 100644 c2pa/c2pa/__init__.py create mode 100644 c2pa/c2pa/c2pa.py diff --git a/.gitignore b/.gitignore index c96c5aa5..79539b6c 100644 --- a/.gitignore +++ b/.gitignore @@ -22,7 +22,7 @@ __pycache__/ .pytest_cache/ dist -c2pa/c2pa/ +c2pa/c2pa/libuniffi_c2pa.* # Mac OS X files .DS_Store diff --git a/c2pa/c2pa/__init__.py b/c2pa/c2pa/__init__.py new file mode 100644 index 00000000..fb73f71e --- /dev/null +++ b/c2pa/c2pa/__init__.py @@ -0,0 +1 @@ +from .c2pa import * # NOQA diff --git a/c2pa/c2pa/c2pa.py b/c2pa/c2pa/c2pa.py new file mode 100644 index 00000000..8a71154c --- /dev/null +++ b/c2pa/c2pa/c2pa.py @@ -0,0 +1,1945 @@ +# This file was autogenerated by some hot garbage in the `uniffi` crate. +# Trust me, you don't want to mess with it! + +# Common helper code. +# +# Ideally this would live in a separate .py file where it can be unittested etc +# in isolation, and perhaps even published as a re-useable package. +# +# However, it's important that the details of how this helper code works (e.g. the +# way that different builtin types are passed across the FFI) exactly match what's +# expected by the rust code on the other side of the interface. In practice right +# now that means coming from the exact some version of `uniffi` that was used to +# compile the rust component. The easiest way to ensure this is to bundle the Python +# helpers directly inline like we're doing here. + +import os +import sys +import ctypes +import enum +import struct +import contextlib +import datetime +import typing +import platform + +# Used for default argument values +DEFAULT = object() + + +class RustBuffer(ctypes.Structure): + _fields_ = [ + ("capacity", ctypes.c_int32), + ("len", ctypes.c_int32), + ("data", ctypes.POINTER(ctypes.c_char)), + ] + + @staticmethod + def alloc(size): + return rust_call(_UniFFILib.ffi_c2pa_rustbuffer_alloc, size) + + @staticmethod + def reserve(rbuf, additional): + return rust_call(_UniFFILib.ffi_c2pa_rustbuffer_reserve, rbuf, additional) + + def free(self): + return rust_call(_UniFFILib.ffi_c2pa_rustbuffer_free, self) + + def __str__(self): + return "RustBuffer(capacity={}, len={}, data={})".format( + self.capacity, + self.len, + self.data[0:self.len] + ) + + @contextlib.contextmanager + def allocWithBuilder(*args): + """Context-manger to allocate a buffer using a RustBufferBuilder. + + The allocated buffer will be automatically freed if an error occurs, ensuring that + we don't accidentally leak it. + """ + builder = RustBufferBuilder() + try: + yield builder + except: + builder.discard() + raise + + @contextlib.contextmanager + def consumeWithStream(self): + """Context-manager to consume a buffer using a RustBufferStream. + + The RustBuffer will be freed once the context-manager exits, ensuring that we don't + leak it even if an error occurs. + """ + try: + s = RustBufferStream.from_rust_buffer(self) + yield s + if s.remaining() != 0: + raise RuntimeError("junk data left in buffer at end of consumeWithStream") + finally: + self.free() + + @contextlib.contextmanager + def readWithStream(self): + """Context-manager to read a buffer using a RustBufferStream. + + This is like consumeWithStream, but doesn't free the buffer afterwards. + It should only be used with borrowed `RustBuffer` data. + """ + s = RustBufferStream.from_rust_buffer(self) + yield s + if s.remaining() != 0: + raise RuntimeError("junk data left in buffer at end of readWithStream") + +class ForeignBytes(ctypes.Structure): + _fields_ = [ + ("len", ctypes.c_int32), + ("data", ctypes.POINTER(ctypes.c_char)), + ] + + def __str__(self): + return "ForeignBytes(len={}, data={})".format(self.len, self.data[0:self.len]) + + +class RustBufferStream: + """ + Helper for structured reading of bytes from a RustBuffer + """ + + def __init__(self, data, len): + self.data = data + self.len = len + self.offset = 0 + + @classmethod + def from_rust_buffer(cls, buf): + return cls(buf.data, buf.len) + + def remaining(self): + return self.len - self.offset + + def _unpack_from(self, size, format): + if self.offset + size > self.len: + raise InternalError("read past end of rust buffer") + value = struct.unpack(format, self.data[self.offset:self.offset+size])[0] + self.offset += size + return value + + def read(self, size): + if self.offset + size > self.len: + raise InternalError("read past end of rust buffer") + data = self.data[self.offset:self.offset+size] + self.offset += size + return data + + def readI8(self): + return self._unpack_from(1, ">b") + + def readU8(self): + return self._unpack_from(1, ">B") + + def readI16(self): + return self._unpack_from(2, ">h") + + def readU16(self): + return self._unpack_from(2, ">H") + + def readI32(self): + return self._unpack_from(4, ">i") + + def readU32(self): + return self._unpack_from(4, ">I") + + def readI64(self): + return self._unpack_from(8, ">q") + + def readU64(self): + return self._unpack_from(8, ">Q") + + def readFloat(self): + v = self._unpack_from(4, ">f") + return v + + def readDouble(self): + return self._unpack_from(8, ">d") + + def readCSizeT(self): + return self._unpack_from(ctypes.sizeof(ctypes.c_size_t) , "@N") + +class RustBufferBuilder: + """ + Helper for structured writing of bytes into a RustBuffer. + """ + + def __init__(self): + self.rbuf = RustBuffer.alloc(16) + self.rbuf.len = 0 + + def finalize(self): + rbuf = self.rbuf + self.rbuf = None + return rbuf + + def discard(self): + if self.rbuf is not None: + rbuf = self.finalize() + rbuf.free() + + @contextlib.contextmanager + def _reserve(self, numBytes): + if self.rbuf.len + numBytes > self.rbuf.capacity: + self.rbuf = RustBuffer.reserve(self.rbuf, numBytes) + yield None + self.rbuf.len += numBytes + + def _pack_into(self, size, format, value): + with self._reserve(size): + # XXX TODO: I feel like I should be able to use `struct.pack_into` here but can't figure it out. + for i, byte in enumerate(struct.pack(format, value)): + self.rbuf.data[self.rbuf.len + i] = byte + + def write(self, value): + with self._reserve(len(value)): + for i, byte in enumerate(value): + self.rbuf.data[self.rbuf.len + i] = byte + + def writeI8(self, v): + self._pack_into(1, ">b", v) + + def writeU8(self, v): + self._pack_into(1, ">B", v) + + def writeI16(self, v): + self._pack_into(2, ">h", v) + + def writeU16(self, v): + self._pack_into(2, ">H", v) + + def writeI32(self, v): + self._pack_into(4, ">i", v) + + def writeU32(self, v): + self._pack_into(4, ">I", v) + + def writeI64(self, v): + self._pack_into(8, ">q", v) + + def writeU64(self, v): + self._pack_into(8, ">Q", v) + + def writeFloat(self, v): + self._pack_into(4, ">f", v) + + def writeDouble(self, v): + self._pack_into(8, ">d", v) + + def writeCSizeT(self, v): + self._pack_into(ctypes.sizeof(ctypes.c_size_t) , "@N", v) +# A handful of classes and functions to support the generated data structures. +# This would be a good candidate for isolating in its own ffi-support lib. + +class InternalError(Exception): + pass + +class RustCallStatus(ctypes.Structure): + """ + Error runtime. + """ + _fields_ = [ + ("code", ctypes.c_int8), + ("error_buf", RustBuffer), + ] + + # These match the values from the uniffi::rustcalls module + CALL_SUCCESS = 0 + CALL_ERROR = 1 + CALL_PANIC = 2 + + def __str__(self): + if self.code == RustCallStatus.CALL_SUCCESS: + return "RustCallStatus(CALL_SUCCESS)" + elif self.code == RustCallStatus.CALL_ERROR: + return "RustCallStatus(CALL_ERROR)" + elif self.code == RustCallStatus.CALL_PANIC: + return "RustCallStatus(CALL_PANIC)" + else: + return "RustCallStatus()" + +def rust_call(fn, *args): + # Call a rust function + return rust_call_with_error(None, fn, *args) + +def rust_call_with_error(error_ffi_converter, fn, *args): + # Call a rust function and handle any errors + # + # This function is used for rust calls that return Result<> and therefore can set the CALL_ERROR status code. + # error_ffi_converter must be set to the FfiConverter for the error class that corresponds to the result. + call_status = RustCallStatus(code=RustCallStatus.CALL_SUCCESS, error_buf=RustBuffer(0, 0, None)) + + args_with_error = args + (ctypes.byref(call_status),) + result = fn(*args_with_error) + uniffi_check_call_status(error_ffi_converter, call_status) + return result + +def rust_call_async(scaffolding_fn, callback_fn, *args): + # Call the scaffolding function, passing it a callback handler for `AsyncTypes.py` and a pointer + # to a python Future object. The async function then awaits the Future. + uniffi_eventloop = asyncio.get_running_loop() + uniffi_py_future = uniffi_eventloop.create_future() + uniffi_call_status = RustCallStatus(code=RustCallStatus.CALL_SUCCESS, error_buf=RustBuffer(0, 0, None)) + scaffolding_fn(*args, + FfiConverterForeignExecutor._pointer_manager.new_pointer(uniffi_eventloop), + callback_fn, + # Note: It's tempting to skip the pointer manager and just use a `py_object` pointing to a + # local variable like we do in Swift. However, Python doesn't use cooperative cancellation + # -- asyncio can cancel a task at anytime. This means if we use a local variable, the Rust + # callback could fire with a dangling pointer. + UniFfiPyFuturePointerManager.new_pointer(uniffi_py_future), + ctypes.byref(uniffi_call_status), + ) + uniffi_check_call_status(None, uniffi_call_status) + return uniffi_py_future + +def uniffi_check_call_status(error_ffi_converter, call_status): + if call_status.code == RustCallStatus.CALL_SUCCESS: + pass + elif call_status.code == RustCallStatus.CALL_ERROR: + if error_ffi_converter is None: + call_status.error_buf.free() + raise InternalError("rust_call_with_error: CALL_ERROR, but error_ffi_converter is None") + else: + raise error_ffi_converter.lift(call_status.error_buf) + elif call_status.code == RustCallStatus.CALL_PANIC: + # When the rust code sees a panic, it tries to construct a RustBuffer + # with the message. But if that code panics, then it just sends back + # an empty buffer. + if call_status.error_buf.len > 0: + msg = FfiConverterString.lift(call_status.error_buf) + else: + msg = "Unknown rust panic" + raise InternalError(msg) + else: + raise InternalError("Invalid RustCallStatus code: {}".format( + call_status.code)) + +# A function pointer for a callback as defined by UniFFI. +# Rust definition `fn(handle: u64, method: u32, args: RustBuffer, buf_ptr: *mut RustBuffer) -> int` +FOREIGN_CALLBACK_T = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_ulonglong, ctypes.c_ulong, ctypes.POINTER(ctypes.c_char), ctypes.c_int, ctypes.POINTER(RustBuffer)) +class UniFfiPointerManagerCPython: + """ + Manage giving out pointers to Python objects on CPython + + This class is used to generate opaque pointers that reference Python objects to pass to Rust. + It assumes a CPython platform. See UniFfiPointerManagerGeneral for the alternative. + """ + + def new_pointer(self, obj): + """ + Get a pointer for an object as a ctypes.c_size_t instance + + Each call to new_pointer() must be balanced with exactly one call to release_pointer() + + This returns a ctypes.c_size_t. This is always the same size as a pointer and can be + interchanged with pointers for FFI function arguments and return values. + """ + # IncRef the object since we're going to pass a pointer to Rust + ctypes.pythonapi.Py_IncRef(ctypes.py_object(obj)) + # id() is the object address on CPython + # (https://docs.python.org/3/library/functions.html#id) + return id(obj) + + def release_pointer(self, address): + py_obj = ctypes.cast(address, ctypes.py_object) + obj = py_obj.value + ctypes.pythonapi.Py_DecRef(py_obj) + return obj + + def lookup(self, address): + return ctypes.cast(address, ctypes.py_object).value + +class UniFfiPointerManagerGeneral: + """ + Manage giving out pointers to Python objects on non-CPython platforms + + This has the same API as UniFfiPointerManagerCPython, but doesn't assume we're running on + CPython and is slightly slower. + + Instead of using real pointers, it maps integer values to objects and returns the keys as + c_size_t values. + """ + + def __init__(self): + self._map = {} + self._lock = threading.Lock() + self._current_handle = 0 + + def new_pointer(self, obj): + with self._lock: + handle = self._current_handle + self._current_handle += 1 + self._map[handle] = obj + return handle + + def release_pointer(self, handle): + with self._lock: + return self._map.pop(handle) + + def lookup(self, handle): + with self._lock: + return self._map[handle] + +# Pick an pointer manager implementation based on the platform +if platform.python_implementation() == 'CPython': + UniFfiPointerManager = UniFfiPointerManagerCPython # type: ignore +else: + UniFfiPointerManager = UniFfiPointerManagerGeneral # type: ignore +# Types conforming to `FfiConverterPrimitive` pass themselves directly over the FFI. +class FfiConverterPrimitive: + @classmethod + def check(cls, value): + return value + + @classmethod + def lift(cls, value): + return value + + @classmethod + def lower(cls, value): + return cls.lowerUnchecked(cls.check(value)) + + @classmethod + def lowerUnchecked(cls, value): + return value + + @classmethod + def write(cls, value, buf): + cls.writeUnchecked(cls.check(value), buf) + +class FfiConverterPrimitiveInt(FfiConverterPrimitive): + @classmethod + def check(cls, value): + try: + value = value.__index__() + except Exception: + raise TypeError("'{}' object cannot be interpreted as an integer".format(type(value).__name__)) + if not isinstance(value, int): + raise TypeError("__index__ returned non-int (type {})".format(type(value).__name__)) + if not cls.VALUE_MIN <= value < cls.VALUE_MAX: + raise ValueError("{} requires {} <= value < {}".format(cls.CLASS_NAME, cls.VALUE_MIN, cls.VALUE_MAX)) + return super().check(value) + +class FfiConverterPrimitiveFloat(FfiConverterPrimitive): + @classmethod + def check(cls, value): + try: + value = value.__float__() + except Exception: + raise TypeError("must be real number, not {}".format(type(value).__name__)) + if not isinstance(value, float): + raise TypeError("__float__ returned non-float (type {})".format(type(value).__name__)) + return super().check(value) + +# Helper class for wrapper types that will always go through a RustBuffer. +# Classes should inherit from this and implement the `read` and `write` static methods. +class FfiConverterRustBuffer: + @classmethod + def lift(cls, rbuf): + with rbuf.consumeWithStream() as stream: + return cls.read(stream) + + @classmethod + def lower(cls, value): + with RustBuffer.allocWithBuilder() as builder: + cls.write(value, builder) + return builder.finalize() + +# Contains loading, initialization code, +# and the FFI Function declarations in a com.sun.jna.Library. +# Define some ctypes FFI types that we use in the library + +""" +ctypes type for the foreign executor callback. This is a built-in interface for scheduling +tasks + +Args: + executor: opaque c_size_t value representing the eventloop + delay: delay in ms + task: function pointer to the task callback + task_data: void pointer to the task callback data + +Normally we should call task(task_data) after the detail. +However, when task is NULL this indicates that Rust has dropped the ForeignExecutor and we should +decrease the EventLoop refcount. +""" +UNIFFI_FOREIGN_EXECUTOR_CALLBACK_T = ctypes.CFUNCTYPE(None, ctypes.c_size_t, ctypes.c_uint32, ctypes.c_void_p, ctypes.c_void_p) + +""" +Function pointer for a Rust task, which a callback function that takes a opaque pointer +""" +UNIFFI_RUST_TASK = ctypes.CFUNCTYPE(None, ctypes.c_void_p) + +def uniffi_future_callback_t(return_type): + """ + Factory function to create callback function types for async functions + """ + return ctypes.CFUNCTYPE(None, ctypes.c_size_t, return_type, RustCallStatus) + +from pathlib import Path + +def loadIndirect(): + """ + This is how we find and load the dynamic library provided by the component. + For now we just look it up by name. + """ + if sys.platform == "darwin": + libname = "lib{}.dylib" + elif sys.platform.startswith("win"): + # As of python3.8, ctypes does not seem to search $PATH when loading DLLs. + # We could use `os.add_dll_directory` to configure the search path, but + # it doesn't feel right to mess with application-wide settings. Let's + # assume that the `.dll` is next to the `.py` file and load by full path. + libname = os.path.join( + os.path.dirname(__file__), + "{}.dll", + ) + else: + # Anything else must be an ELF platform - Linux, *BSD, Solaris/illumos + libname = "lib{}.so" + + libname = libname.format("uniffi_c2pa") + path = str(Path(__file__).parent / libname) + lib = ctypes.cdll.LoadLibrary(path) + return lib + +def uniffi_check_contract_api_version(lib): + # Get the bindings contract version from our ComponentInterface + bindings_contract_version = 22 + # Get the scaffolding contract version by calling the into the dylib + scaffolding_contract_version = lib.ffi_c2pa_uniffi_contract_version() + if bindings_contract_version != scaffolding_contract_version: + raise InternalError("UniFFI contract version mismatch: try cleaning and rebuilding your project") + +def uniffi_check_api_checksums(lib): + if lib.uniffi_c2pa_checksum_func_version() != 31632: + raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + if lib.uniffi_c2pa_checksum_func_sdk_version() != 32199: + raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + if lib.uniffi_c2pa_checksum_method_reader_from_stream() != 50669: + raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + if lib.uniffi_c2pa_checksum_method_reader_from_manifest_data_and_stream() != 30428: + raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + if lib.uniffi_c2pa_checksum_method_reader_json() != 18261: + raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + if lib.uniffi_c2pa_checksum_method_reader_resource_to_stream() != 29142: + raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + if lib.uniffi_c2pa_checksum_method_builder_with_json() != 29835: + raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + if lib.uniffi_c2pa_checksum_method_builder_set_no_embed() != 46988: + raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + if lib.uniffi_c2pa_checksum_method_builder_set_remote_url() != 25667: + raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + if lib.uniffi_c2pa_checksum_method_builder_add_resource() != 29891: + raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + if lib.uniffi_c2pa_checksum_method_builder_add_ingredient() != 50859: + raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + if lib.uniffi_c2pa_checksum_method_builder_to_archive() != 6987: + raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + if lib.uniffi_c2pa_checksum_method_builder_from_archive() != 56644: + raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + if lib.uniffi_c2pa_checksum_method_builder_sign() != 9859: + raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + if lib.uniffi_c2pa_checksum_method_builder_sign_file() != 64222: + raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + if lib.uniffi_c2pa_checksum_constructor_reader_new() != 39952: + raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + if lib.uniffi_c2pa_checksum_constructor_callbacksigner_new() != 15795: + raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + if lib.uniffi_c2pa_checksum_constructor_callbacksigner_new_from_signer() != 25848: + raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + if lib.uniffi_c2pa_checksum_constructor_builder_new() != 6168: + raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + +# A ctypes library to expose the extern-C FFI definitions. +# This is an implementation detail which will be called internally by the public API. + +_UniFFILib = loadIndirect() +_UniFFILib.uniffi_c2pa_fn_free_reader.argtypes = ( + ctypes.c_void_p, + ctypes.POINTER(RustCallStatus), +) +_UniFFILib.uniffi_c2pa_fn_free_reader.restype = None +_UniFFILib.uniffi_c2pa_fn_constructor_reader_new.argtypes = ( + ctypes.POINTER(RustCallStatus), +) +_UniFFILib.uniffi_c2pa_fn_constructor_reader_new.restype = ctypes.c_void_p +_UniFFILib.uniffi_c2pa_fn_method_reader_from_stream.argtypes = ( + ctypes.c_void_p, + RustBuffer, + ctypes.c_uint64, + ctypes.POINTER(RustCallStatus), +) +_UniFFILib.uniffi_c2pa_fn_method_reader_from_stream.restype = RustBuffer +_UniFFILib.uniffi_c2pa_fn_method_reader_from_manifest_data_and_stream.argtypes = ( + ctypes.c_void_p, + RustBuffer, + RustBuffer, + ctypes.c_uint64, + ctypes.POINTER(RustCallStatus), +) +_UniFFILib.uniffi_c2pa_fn_method_reader_from_manifest_data_and_stream.restype = RustBuffer +_UniFFILib.uniffi_c2pa_fn_method_reader_json.argtypes = ( + ctypes.c_void_p, + ctypes.POINTER(RustCallStatus), +) +_UniFFILib.uniffi_c2pa_fn_method_reader_json.restype = RustBuffer +_UniFFILib.uniffi_c2pa_fn_method_reader_resource_to_stream.argtypes = ( + ctypes.c_void_p, + RustBuffer, + ctypes.c_uint64, + ctypes.POINTER(RustCallStatus), +) +_UniFFILib.uniffi_c2pa_fn_method_reader_resource_to_stream.restype = ctypes.c_uint64 +_UniFFILib.uniffi_c2pa_fn_free_callbacksigner.argtypes = ( + ctypes.c_void_p, + ctypes.POINTER(RustCallStatus), +) +_UniFFILib.uniffi_c2pa_fn_free_callbacksigner.restype = None +_UniFFILib.uniffi_c2pa_fn_constructor_callbacksigner_new.argtypes = ( + ctypes.c_uint64, + RustBuffer, + RustBuffer, + RustBuffer, + ctypes.POINTER(RustCallStatus), +) +_UniFFILib.uniffi_c2pa_fn_constructor_callbacksigner_new.restype = ctypes.c_void_p +_UniFFILib.uniffi_c2pa_fn_constructor_callbacksigner_new_from_signer.argtypes = ( + ctypes.c_uint64, + RustBuffer, + ctypes.c_uint32, + ctypes.POINTER(RustCallStatus), +) +_UniFFILib.uniffi_c2pa_fn_constructor_callbacksigner_new_from_signer.restype = ctypes.c_void_p +_UniFFILib.uniffi_c2pa_fn_free_builder.argtypes = ( + ctypes.c_void_p, + ctypes.POINTER(RustCallStatus), +) +_UniFFILib.uniffi_c2pa_fn_free_builder.restype = None +_UniFFILib.uniffi_c2pa_fn_constructor_builder_new.argtypes = ( + ctypes.POINTER(RustCallStatus), +) +_UniFFILib.uniffi_c2pa_fn_constructor_builder_new.restype = ctypes.c_void_p +_UniFFILib.uniffi_c2pa_fn_method_builder_with_json.argtypes = ( + ctypes.c_void_p, + RustBuffer, + ctypes.POINTER(RustCallStatus), +) +_UniFFILib.uniffi_c2pa_fn_method_builder_with_json.restype = None +_UniFFILib.uniffi_c2pa_fn_method_builder_set_no_embed.argtypes = ( + ctypes.c_void_p, + ctypes.POINTER(RustCallStatus), +) +_UniFFILib.uniffi_c2pa_fn_method_builder_set_no_embed.restype = None +_UniFFILib.uniffi_c2pa_fn_method_builder_set_remote_url.argtypes = ( + ctypes.c_void_p, + RustBuffer, + ctypes.POINTER(RustCallStatus), +) +_UniFFILib.uniffi_c2pa_fn_method_builder_set_remote_url.restype = None +_UniFFILib.uniffi_c2pa_fn_method_builder_add_resource.argtypes = ( + ctypes.c_void_p, + RustBuffer, + ctypes.c_uint64, + ctypes.POINTER(RustCallStatus), +) +_UniFFILib.uniffi_c2pa_fn_method_builder_add_resource.restype = None +_UniFFILib.uniffi_c2pa_fn_method_builder_add_ingredient.argtypes = ( + ctypes.c_void_p, + RustBuffer, + RustBuffer, + ctypes.c_uint64, + ctypes.POINTER(RustCallStatus), +) +_UniFFILib.uniffi_c2pa_fn_method_builder_add_ingredient.restype = None +_UniFFILib.uniffi_c2pa_fn_method_builder_to_archive.argtypes = ( + ctypes.c_void_p, + ctypes.c_uint64, + ctypes.POINTER(RustCallStatus), +) +_UniFFILib.uniffi_c2pa_fn_method_builder_to_archive.restype = None +_UniFFILib.uniffi_c2pa_fn_method_builder_from_archive.argtypes = ( + ctypes.c_void_p, + ctypes.c_uint64, + ctypes.POINTER(RustCallStatus), +) +_UniFFILib.uniffi_c2pa_fn_method_builder_from_archive.restype = None +_UniFFILib.uniffi_c2pa_fn_method_builder_sign.argtypes = ( + ctypes.c_void_p, + ctypes.c_void_p, + RustBuffer, + ctypes.c_uint64, + ctypes.c_uint64, + ctypes.POINTER(RustCallStatus), +) +_UniFFILib.uniffi_c2pa_fn_method_builder_sign.restype = RustBuffer +_UniFFILib.uniffi_c2pa_fn_method_builder_sign_file.argtypes = ( + ctypes.c_void_p, + ctypes.c_void_p, + RustBuffer, + RustBuffer, + ctypes.POINTER(RustCallStatus), +) +_UniFFILib.uniffi_c2pa_fn_method_builder_sign_file.restype = RustBuffer +_UniFFILib.uniffi_c2pa_fn_init_callback_stream.argtypes = ( + FOREIGN_CALLBACK_T, + ctypes.POINTER(RustCallStatus), +) +_UniFFILib.uniffi_c2pa_fn_init_callback_stream.restype = None +_UniFFILib.uniffi_c2pa_fn_init_callback_signercallback.argtypes = ( + FOREIGN_CALLBACK_T, + ctypes.POINTER(RustCallStatus), +) +_UniFFILib.uniffi_c2pa_fn_init_callback_signercallback.restype = None +_UniFFILib.uniffi_c2pa_fn_func_version.argtypes = ( + ctypes.POINTER(RustCallStatus), +) +_UniFFILib.uniffi_c2pa_fn_func_version.restype = RustBuffer +_UniFFILib.uniffi_c2pa_fn_func_sdk_version.argtypes = ( + ctypes.POINTER(RustCallStatus), +) +_UniFFILib.uniffi_c2pa_fn_func_sdk_version.restype = RustBuffer +_UniFFILib.ffi_c2pa_rustbuffer_alloc.argtypes = ( + ctypes.c_int32, + ctypes.POINTER(RustCallStatus), +) +_UniFFILib.ffi_c2pa_rustbuffer_alloc.restype = RustBuffer +_UniFFILib.ffi_c2pa_rustbuffer_from_bytes.argtypes = ( + ForeignBytes, + ctypes.POINTER(RustCallStatus), +) +_UniFFILib.ffi_c2pa_rustbuffer_from_bytes.restype = RustBuffer +_UniFFILib.ffi_c2pa_rustbuffer_free.argtypes = ( + RustBuffer, + ctypes.POINTER(RustCallStatus), +) +_UniFFILib.ffi_c2pa_rustbuffer_free.restype = None +_UniFFILib.ffi_c2pa_rustbuffer_reserve.argtypes = ( + RustBuffer, + ctypes.c_int32, + ctypes.POINTER(RustCallStatus), +) +_UniFFILib.ffi_c2pa_rustbuffer_reserve.restype = RustBuffer +_UniFFILib.uniffi_c2pa_checksum_func_version.argtypes = ( +) +_UniFFILib.uniffi_c2pa_checksum_func_version.restype = ctypes.c_uint16 +_UniFFILib.uniffi_c2pa_checksum_func_sdk_version.argtypes = ( +) +_UniFFILib.uniffi_c2pa_checksum_func_sdk_version.restype = ctypes.c_uint16 +_UniFFILib.uniffi_c2pa_checksum_method_reader_from_stream.argtypes = ( +) +_UniFFILib.uniffi_c2pa_checksum_method_reader_from_stream.restype = ctypes.c_uint16 +_UniFFILib.uniffi_c2pa_checksum_method_reader_from_manifest_data_and_stream.argtypes = ( +) +_UniFFILib.uniffi_c2pa_checksum_method_reader_from_manifest_data_and_stream.restype = ctypes.c_uint16 +_UniFFILib.uniffi_c2pa_checksum_method_reader_json.argtypes = ( +) +_UniFFILib.uniffi_c2pa_checksum_method_reader_json.restype = ctypes.c_uint16 +_UniFFILib.uniffi_c2pa_checksum_method_reader_resource_to_stream.argtypes = ( +) +_UniFFILib.uniffi_c2pa_checksum_method_reader_resource_to_stream.restype = ctypes.c_uint16 +_UniFFILib.uniffi_c2pa_checksum_method_builder_with_json.argtypes = ( +) +_UniFFILib.uniffi_c2pa_checksum_method_builder_with_json.restype = ctypes.c_uint16 +_UniFFILib.uniffi_c2pa_checksum_method_builder_set_no_embed.argtypes = ( +) +_UniFFILib.uniffi_c2pa_checksum_method_builder_set_no_embed.restype = ctypes.c_uint16 +_UniFFILib.uniffi_c2pa_checksum_method_builder_set_remote_url.argtypes = ( +) +_UniFFILib.uniffi_c2pa_checksum_method_builder_set_remote_url.restype = ctypes.c_uint16 +_UniFFILib.uniffi_c2pa_checksum_method_builder_add_resource.argtypes = ( +) +_UniFFILib.uniffi_c2pa_checksum_method_builder_add_resource.restype = ctypes.c_uint16 +_UniFFILib.uniffi_c2pa_checksum_method_builder_add_ingredient.argtypes = ( +) +_UniFFILib.uniffi_c2pa_checksum_method_builder_add_ingredient.restype = ctypes.c_uint16 +_UniFFILib.uniffi_c2pa_checksum_method_builder_to_archive.argtypes = ( +) +_UniFFILib.uniffi_c2pa_checksum_method_builder_to_archive.restype = ctypes.c_uint16 +_UniFFILib.uniffi_c2pa_checksum_method_builder_from_archive.argtypes = ( +) +_UniFFILib.uniffi_c2pa_checksum_method_builder_from_archive.restype = ctypes.c_uint16 +_UniFFILib.uniffi_c2pa_checksum_method_builder_sign.argtypes = ( +) +_UniFFILib.uniffi_c2pa_checksum_method_builder_sign.restype = ctypes.c_uint16 +_UniFFILib.uniffi_c2pa_checksum_method_builder_sign_file.argtypes = ( +) +_UniFFILib.uniffi_c2pa_checksum_method_builder_sign_file.restype = ctypes.c_uint16 +_UniFFILib.uniffi_c2pa_checksum_constructor_reader_new.argtypes = ( +) +_UniFFILib.uniffi_c2pa_checksum_constructor_reader_new.restype = ctypes.c_uint16 +_UniFFILib.uniffi_c2pa_checksum_constructor_callbacksigner_new.argtypes = ( +) +_UniFFILib.uniffi_c2pa_checksum_constructor_callbacksigner_new.restype = ctypes.c_uint16 +_UniFFILib.uniffi_c2pa_checksum_constructor_callbacksigner_new_from_signer.argtypes = ( +) +_UniFFILib.uniffi_c2pa_checksum_constructor_callbacksigner_new_from_signer.restype = ctypes.c_uint16 +_UniFFILib.uniffi_c2pa_checksum_constructor_builder_new.argtypes = ( +) +_UniFFILib.uniffi_c2pa_checksum_constructor_builder_new.restype = ctypes.c_uint16 +_UniFFILib.ffi_c2pa_uniffi_contract_version.argtypes = ( +) +_UniFFILib.ffi_c2pa_uniffi_contract_version.restype = ctypes.c_uint32 +uniffi_check_contract_api_version(_UniFFILib) +uniffi_check_api_checksums(_UniFFILib) + +# Public interface members begin here. + + +class FfiConverterUInt32(FfiConverterPrimitiveInt): + CLASS_NAME = "u32" + VALUE_MIN = 0 + VALUE_MAX = 2**32 + + @staticmethod + def read(buf): + return buf.readU32() + + @staticmethod + def writeUnchecked(value, buf): + buf.writeU32(value) + +class FfiConverterUInt64(FfiConverterPrimitiveInt): + CLASS_NAME = "u64" + VALUE_MIN = 0 + VALUE_MAX = 2**64 + + @staticmethod + def read(buf): + return buf.readU64() + + @staticmethod + def writeUnchecked(value, buf): + buf.writeU64(value) + +class FfiConverterInt64(FfiConverterPrimitiveInt): + CLASS_NAME = "i64" + VALUE_MIN = -2**63 + VALUE_MAX = 2**63 + + @staticmethod + def read(buf): + return buf.readI64() + + @staticmethod + def writeUnchecked(value, buf): + buf.writeI64(value) + +class FfiConverterString: + @staticmethod + def check(value): + if not isinstance(value, str): + raise TypeError("argument must be str, not {}".format(type(value).__name__)) + return value + + @staticmethod + def read(buf): + size = buf.readI32() + if size < 0: + raise InternalError("Unexpected negative string length") + utf8Bytes = buf.read(size) + return utf8Bytes.decode("utf-8") + + @staticmethod + def write(value, buf): + value = FfiConverterString.check(value) + utf8Bytes = value.encode("utf-8") + buf.writeI32(len(utf8Bytes)) + buf.write(utf8Bytes) + + @staticmethod + def lift(buf): + with buf.consumeWithStream() as stream: + return stream.read(stream.remaining()).decode("utf-8") + + @staticmethod + def lower(value): + value = FfiConverterString.check(value) + with RustBuffer.allocWithBuilder() as builder: + builder.write(value.encode("utf-8")) + return builder.finalize() + +class FfiConverterBytes(FfiConverterRustBuffer): + @staticmethod + def read(buf): + size = buf.readI32() + if size < 0: + raise InternalError("Unexpected negative byte string length") + return buf.read(size) + + @staticmethod + def write(value, buf): + try: + memoryview(value) + except TypeError: + raise TypeError("a bytes-like object is required, not {!r}".format(type(value).__name__)) + buf.writeI32(len(value)) + buf.write(value) + + + +class Builder: + _pointer: ctypes.c_void_p + def __init__(self, ): + self._pointer = rust_call(_UniFFILib.uniffi_c2pa_fn_constructor_builder_new,) + + def __del__(self): + # In case of partial initialization of instances. + pointer = getattr(self, "_pointer", None) + if pointer is not None: + rust_call(_UniFFILib.uniffi_c2pa_fn_free_builder, pointer) + + # Used by alternative constructors or any methods which return this type. + @classmethod + def _make_instance_(cls, pointer): + # Lightly yucky way to bypass the usual __init__ logic + # and just create a new instance with the required pointer. + inst = cls.__new__(cls) + inst._pointer = pointer + return inst + + + def with_json(self, json: "str"): + + rust_call_with_error( + FfiConverterTypeError,_UniFFILib.uniffi_c2pa_fn_method_builder_with_json,self._pointer, + FfiConverterString.lower(json)) + + + + + + + + def set_no_embed(self, ): + rust_call_with_error( + FfiConverterTypeError,_UniFFILib.uniffi_c2pa_fn_method_builder_set_no_embed,self._pointer,) + + + + + + + + def set_remote_url(self, url: "str"): + + rust_call_with_error( + FfiConverterTypeError,_UniFFILib.uniffi_c2pa_fn_method_builder_set_remote_url,self._pointer, + FfiConverterString.lower(url)) + + + + + + + + def add_resource(self, uri: "str",stream: "Stream"): + + + rust_call_with_error( + FfiConverterTypeError,_UniFFILib.uniffi_c2pa_fn_method_builder_add_resource,self._pointer, + FfiConverterString.lower(uri), + FfiConverterCallbackInterfaceStream.lower(stream)) + + + + + + + + def add_ingredient(self, ingredient_json: "str",format: "str",stream: "Stream"): + + + + rust_call_with_error( + FfiConverterTypeError,_UniFFILib.uniffi_c2pa_fn_method_builder_add_ingredient,self._pointer, + FfiConverterString.lower(ingredient_json), + FfiConverterString.lower(format), + FfiConverterCallbackInterfaceStream.lower(stream)) + + + + + + + + def to_archive(self, stream: "Stream"): + + rust_call_with_error( + FfiConverterTypeError,_UniFFILib.uniffi_c2pa_fn_method_builder_to_archive,self._pointer, + FfiConverterCallbackInterfaceStream.lower(stream)) + + + + + + + + def from_archive(self, stream: "Stream"): + + rust_call_with_error( + FfiConverterTypeError,_UniFFILib.uniffi_c2pa_fn_method_builder_from_archive,self._pointer, + FfiConverterCallbackInterfaceStream.lower(stream)) + + + + + + + + def sign(self, signer: "CallbackSigner",format: "str",input: "Stream",output: "Stream") -> "bytes": + + + + + return FfiConverterBytes.lift( + rust_call_with_error( + FfiConverterTypeError,_UniFFILib.uniffi_c2pa_fn_method_builder_sign,self._pointer, + FfiConverterTypeCallbackSigner.lower(signer), + FfiConverterString.lower(format), + FfiConverterCallbackInterfaceStream.lower(input), + FfiConverterCallbackInterfaceStream.lower(output)) + ) + + + + + + + def sign_file(self, signer: "CallbackSigner",input: "str",output: "str") -> "bytes": + + + + return FfiConverterBytes.lift( + rust_call_with_error( + FfiConverterTypeError,_UniFFILib.uniffi_c2pa_fn_method_builder_sign_file,self._pointer, + FfiConverterTypeCallbackSigner.lower(signer), + FfiConverterString.lower(input), + FfiConverterString.lower(output)) + ) + + + + + + +class FfiConverterTypeBuilder: + @classmethod + def read(cls, buf): + ptr = buf.readU64() + if ptr == 0: + raise InternalError("Raw pointer value was null") + return cls.lift(ptr) + + @classmethod + def write(cls, value, buf): + if not isinstance(value, Builder): + raise TypeError("Expected Builder instance, {} found".format(value.__class__.__name__)) + buf.writeU64(cls.lower(value)) + + @staticmethod + def lift(value): + return Builder._make_instance_(value) + + @staticmethod + def lower(value): + return value._pointer + + + +class CallbackSigner: + _pointer: ctypes.c_void_p + def __init__(self, callback: "SignerCallback",alg: "SigningAlg",certs: "bytes",ta_url: "typing.Optional[str]"): + + + + + self._pointer = rust_call(_UniFFILib.uniffi_c2pa_fn_constructor_callbacksigner_new, + FfiConverterCallbackInterfaceSignerCallback.lower(callback), + FfiConverterTypeSigningAlg.lower(alg), + FfiConverterBytes.lower(certs), + FfiConverterOptionalString.lower(ta_url)) + + def __del__(self): + # In case of partial initialization of instances. + pointer = getattr(self, "_pointer", None) + if pointer is not None: + rust_call(_UniFFILib.uniffi_c2pa_fn_free_callbacksigner, pointer) + + # Used by alternative constructors or any methods which return this type. + @classmethod + def _make_instance_(cls, pointer): + # Lightly yucky way to bypass the usual __init__ logic + # and just create a new instance with the required pointer. + inst = cls.__new__(cls) + inst._pointer = pointer + return inst + + @classmethod + def new_from_signer(cls, callback: "SignerCallback",alg: "SigningAlg",reserve_size: "int"): + + + + # Call the (fallible) function before creating any half-baked object instances. + pointer = rust_call(_UniFFILib.uniffi_c2pa_fn_constructor_callbacksigner_new_from_signer, + FfiConverterCallbackInterfaceSignerCallback.lower(callback), + FfiConverterTypeSigningAlg.lower(alg), + FfiConverterUInt32.lower(reserve_size)) + return cls._make_instance_(pointer) + + + +class FfiConverterTypeCallbackSigner: + @classmethod + def read(cls, buf): + ptr = buf.readU64() + if ptr == 0: + raise InternalError("Raw pointer value was null") + return cls.lift(ptr) + + @classmethod + def write(cls, value, buf): + if not isinstance(value, CallbackSigner): + raise TypeError("Expected CallbackSigner instance, {} found".format(value.__class__.__name__)) + buf.writeU64(cls.lower(value)) + + @staticmethod + def lift(value): + return CallbackSigner._make_instance_(value) + + @staticmethod + def lower(value): + return value._pointer + + + +class Reader: + _pointer: ctypes.c_void_p + def __init__(self, ): + self._pointer = rust_call(_UniFFILib.uniffi_c2pa_fn_constructor_reader_new,) + + def __del__(self): + # In case of partial initialization of instances. + pointer = getattr(self, "_pointer", None) + if pointer is not None: + rust_call(_UniFFILib.uniffi_c2pa_fn_free_reader, pointer) + + # Used by alternative constructors or any methods which return this type. + @classmethod + def _make_instance_(cls, pointer): + # Lightly yucky way to bypass the usual __init__ logic + # and just create a new instance with the required pointer. + inst = cls.__new__(cls) + inst._pointer = pointer + return inst + + + def from_stream(self, format: "str",reader: "Stream") -> "str": + + + return FfiConverterString.lift( + rust_call_with_error( + FfiConverterTypeError,_UniFFILib.uniffi_c2pa_fn_method_reader_from_stream,self._pointer, + FfiConverterString.lower(format), + FfiConverterCallbackInterfaceStream.lower(reader)) + ) + + + + + + + def from_manifest_data_and_stream(self, manifest_data: "bytes",format: "str",reader: "Stream") -> "str": + + + + return FfiConverterString.lift( + rust_call_with_error( + FfiConverterTypeError,_UniFFILib.uniffi_c2pa_fn_method_reader_from_manifest_data_and_stream,self._pointer, + FfiConverterBytes.lower(manifest_data), + FfiConverterString.lower(format), + FfiConverterCallbackInterfaceStream.lower(reader)) + ) + + + + + + + def json(self, ) -> "str": + return FfiConverterString.lift( + rust_call_with_error( + FfiConverterTypeError,_UniFFILib.uniffi_c2pa_fn_method_reader_json,self._pointer,) + ) + + + + + + + def resource_to_stream(self, uri: "str",stream: "Stream") -> "int": + + + return FfiConverterUInt64.lift( + rust_call_with_error( + FfiConverterTypeError,_UniFFILib.uniffi_c2pa_fn_method_reader_resource_to_stream,self._pointer, + FfiConverterString.lower(uri), + FfiConverterCallbackInterfaceStream.lower(stream)) + ) + + + + + + +class FfiConverterTypeReader: + @classmethod + def read(cls, buf): + ptr = buf.readU64() + if ptr == 0: + raise InternalError("Raw pointer value was null") + return cls.lift(ptr) + + @classmethod + def write(cls, value, buf): + if not isinstance(value, Reader): + raise TypeError("Expected Reader instance, {} found".format(value.__class__.__name__)) + buf.writeU64(cls.lower(value)) + + @staticmethod + def lift(value): + return Reader._make_instance_(value) + + @staticmethod + def lower(value): + return value._pointer + + +# Error +# We want to define each variant as a nested class that's also a subclass, +# which is tricky in Python. To accomplish this we're going to create each +# class separately, then manually add the child classes to the base class's +# __dict__. All of this happens in dummy class to avoid polluting the module +# namespace. +class Error(Exception): + pass + +UniFFITempError = Error + +class Error: # type: ignore + class Assertion(UniFFITempError): + def __init__(self, reason): + super().__init__(", ".join([ + "reason={!r}".format(reason), + ])) + self.reason = reason + def __repr__(self): + return "Error.Assertion({})".format(str(self)) + UniFFITempError.Assertion = Assertion # type: ignore + class AssertionNotFound(UniFFITempError): + def __init__(self, reason): + super().__init__(", ".join([ + "reason={!r}".format(reason), + ])) + self.reason = reason + def __repr__(self): + return "Error.AssertionNotFound({})".format(str(self)) + UniFFITempError.AssertionNotFound = AssertionNotFound # type: ignore + class Decoding(UniFFITempError): + def __init__(self, reason): + super().__init__(", ".join([ + "reason={!r}".format(reason), + ])) + self.reason = reason + def __repr__(self): + return "Error.Decoding({})".format(str(self)) + UniFFITempError.Decoding = Decoding # type: ignore + class Encoding(UniFFITempError): + def __init__(self, reason): + super().__init__(", ".join([ + "reason={!r}".format(reason), + ])) + self.reason = reason + def __repr__(self): + return "Error.Encoding({})".format(str(self)) + UniFFITempError.Encoding = Encoding # type: ignore + class FileNotFound(UniFFITempError): + def __init__(self, reason): + super().__init__(", ".join([ + "reason={!r}".format(reason), + ])) + self.reason = reason + def __repr__(self): + return "Error.FileNotFound({})".format(str(self)) + UniFFITempError.FileNotFound = FileNotFound # type: ignore + class Io(UniFFITempError): + def __init__(self, reason): + super().__init__(", ".join([ + "reason={!r}".format(reason), + ])) + self.reason = reason + def __repr__(self): + return "Error.Io({})".format(str(self)) + UniFFITempError.Io = Io # type: ignore + class Json(UniFFITempError): + def __init__(self, reason): + super().__init__(", ".join([ + "reason={!r}".format(reason), + ])) + self.reason = reason + def __repr__(self): + return "Error.Json({})".format(str(self)) + UniFFITempError.Json = Json # type: ignore + class Manifest(UniFFITempError): + def __init__(self, reason): + super().__init__(", ".join([ + "reason={!r}".format(reason), + ])) + self.reason = reason + def __repr__(self): + return "Error.Manifest({})".format(str(self)) + UniFFITempError.Manifest = Manifest # type: ignore + class ManifestNotFound(UniFFITempError): + def __init__(self, reason): + super().__init__(", ".join([ + "reason={!r}".format(reason), + ])) + self.reason = reason + def __repr__(self): + return "Error.ManifestNotFound({})".format(str(self)) + UniFFITempError.ManifestNotFound = ManifestNotFound # type: ignore + class NotSupported(UniFFITempError): + def __init__(self, reason): + super().__init__(", ".join([ + "reason={!r}".format(reason), + ])) + self.reason = reason + def __repr__(self): + return "Error.NotSupported({})".format(str(self)) + UniFFITempError.NotSupported = NotSupported # type: ignore + class Other(UniFFITempError): + def __init__(self, reason): + super().__init__(", ".join([ + "reason={!r}".format(reason), + ])) + self.reason = reason + def __repr__(self): + return "Error.Other({})".format(str(self)) + UniFFITempError.Other = Other # type: ignore + class RemoteManifest(UniFFITempError): + def __init__(self, reason): + super().__init__(", ".join([ + "reason={!r}".format(reason), + ])) + self.reason = reason + def __repr__(self): + return "Error.RemoteManifest({})".format(str(self)) + UniFFITempError.RemoteManifest = RemoteManifest # type: ignore + class ResourceNotFound(UniFFITempError): + def __init__(self, reason): + super().__init__(", ".join([ + "reason={!r}".format(reason), + ])) + self.reason = reason + def __repr__(self): + return "Error.ResourceNotFound({})".format(str(self)) + UniFFITempError.ResourceNotFound = ResourceNotFound # type: ignore + class RwLock(UniFFITempError): + def __init__(self): + pass + def __repr__(self): + return "Error.RwLock({})".format(str(self)) + UniFFITempError.RwLock = RwLock # type: ignore + class Signature(UniFFITempError): + def __init__(self, reason): + super().__init__(", ".join([ + "reason={!r}".format(reason), + ])) + self.reason = reason + def __repr__(self): + return "Error.Signature({})".format(str(self)) + UniFFITempError.Signature = Signature # type: ignore + class Verify(UniFFITempError): + def __init__(self, reason): + super().__init__(", ".join([ + "reason={!r}".format(reason), + ])) + self.reason = reason + def __repr__(self): + return "Error.Verify({})".format(str(self)) + UniFFITempError.Verify = Verify # type: ignore + +Error = UniFFITempError # type: ignore +del UniFFITempError + + +class FfiConverterTypeError(FfiConverterRustBuffer): + @staticmethod + def read(buf): + variant = buf.readI32() + if variant == 1: + return Error.Assertion( + reason=FfiConverterString.read(buf), + ) + if variant == 2: + return Error.AssertionNotFound( + reason=FfiConverterString.read(buf), + ) + if variant == 3: + return Error.Decoding( + reason=FfiConverterString.read(buf), + ) + if variant == 4: + return Error.Encoding( + reason=FfiConverterString.read(buf), + ) + if variant == 5: + return Error.FileNotFound( + reason=FfiConverterString.read(buf), + ) + if variant == 6: + return Error.Io( + reason=FfiConverterString.read(buf), + ) + if variant == 7: + return Error.Json( + reason=FfiConverterString.read(buf), + ) + if variant == 8: + return Error.Manifest( + reason=FfiConverterString.read(buf), + ) + if variant == 9: + return Error.ManifestNotFound( + reason=FfiConverterString.read(buf), + ) + if variant == 10: + return Error.NotSupported( + reason=FfiConverterString.read(buf), + ) + if variant == 11: + return Error.Other( + reason=FfiConverterString.read(buf), + ) + if variant == 12: + return Error.RemoteManifest( + reason=FfiConverterString.read(buf), + ) + if variant == 13: + return Error.ResourceNotFound( + reason=FfiConverterString.read(buf), + ) + if variant == 14: + return Error.RwLock( + ) + if variant == 15: + return Error.Signature( + reason=FfiConverterString.read(buf), + ) + if variant == 16: + return Error.Verify( + reason=FfiConverterString.read(buf), + ) + raise InternalError("Raw enum value doesn't match any cases") + + @staticmethod + def write(value, buf): + if isinstance(value, Error.Assertion): + buf.writeI32(1) + FfiConverterString.write(value.reason, buf) + if isinstance(value, Error.AssertionNotFound): + buf.writeI32(2) + FfiConverterString.write(value.reason, buf) + if isinstance(value, Error.Decoding): + buf.writeI32(3) + FfiConverterString.write(value.reason, buf) + if isinstance(value, Error.Encoding): + buf.writeI32(4) + FfiConverterString.write(value.reason, buf) + if isinstance(value, Error.FileNotFound): + buf.writeI32(5) + FfiConverterString.write(value.reason, buf) + if isinstance(value, Error.Io): + buf.writeI32(6) + FfiConverterString.write(value.reason, buf) + if isinstance(value, Error.Json): + buf.writeI32(7) + FfiConverterString.write(value.reason, buf) + if isinstance(value, Error.Manifest): + buf.writeI32(8) + FfiConverterString.write(value.reason, buf) + if isinstance(value, Error.ManifestNotFound): + buf.writeI32(9) + FfiConverterString.write(value.reason, buf) + if isinstance(value, Error.NotSupported): + buf.writeI32(10) + FfiConverterString.write(value.reason, buf) + if isinstance(value, Error.Other): + buf.writeI32(11) + FfiConverterString.write(value.reason, buf) + if isinstance(value, Error.RemoteManifest): + buf.writeI32(12) + FfiConverterString.write(value.reason, buf) + if isinstance(value, Error.ResourceNotFound): + buf.writeI32(13) + FfiConverterString.write(value.reason, buf) + if isinstance(value, Error.RwLock): + buf.writeI32(14) + if isinstance(value, Error.Signature): + buf.writeI32(15) + FfiConverterString.write(value.reason, buf) + if isinstance(value, Error.Verify): + buf.writeI32(16) + FfiConverterString.write(value.reason, buf) + + + + + +class SeekMode(enum.Enum): + START = 1 + END = 2 + CURRENT = 3 + + + +class FfiConverterTypeSeekMode(FfiConverterRustBuffer): + @staticmethod + def read(buf): + variant = buf.readI32() + if variant == 1: + return SeekMode.START + if variant == 2: + return SeekMode.END + if variant == 3: + return SeekMode.CURRENT + raise InternalError("Raw enum value doesn't match any cases") + + def write(value, buf): + if value == SeekMode.START: + buf.writeI32(1) + if value == SeekMode.END: + buf.writeI32(2) + if value == SeekMode.CURRENT: + buf.writeI32(3) + + + + + + +class SigningAlg(enum.Enum): + ES256 = 1 + ES384 = 2 + ES512 = 3 + PS256 = 4 + PS384 = 5 + PS512 = 6 + ED25519 = 7 + + + +class FfiConverterTypeSigningAlg(FfiConverterRustBuffer): + @staticmethod + def read(buf): + variant = buf.readI32() + if variant == 1: + return SigningAlg.ES256 + if variant == 2: + return SigningAlg.ES384 + if variant == 3: + return SigningAlg.ES512 + if variant == 4: + return SigningAlg.PS256 + if variant == 5: + return SigningAlg.PS384 + if variant == 6: + return SigningAlg.PS512 + if variant == 7: + return SigningAlg.ED25519 + raise InternalError("Raw enum value doesn't match any cases") + + def write(value, buf): + if value == SigningAlg.ES256: + buf.writeI32(1) + if value == SigningAlg.ES384: + buf.writeI32(2) + if value == SigningAlg.ES512: + buf.writeI32(3) + if value == SigningAlg.PS256: + buf.writeI32(4) + if value == SigningAlg.PS384: + buf.writeI32(5) + if value == SigningAlg.PS512: + buf.writeI32(6) + if value == SigningAlg.ED25519: + buf.writeI32(7) + + + + +import threading + +class ConcurrentHandleMap: + """ + A map where inserting, getting and removing data is synchronized with a lock. + """ + + def __init__(self): + # type Handle = int + self._left_map = {} # type: Dict[Handle, Any] + self._right_map = {} # type: Dict[Any, Handle] + + self._lock = threading.Lock() + self._current_handle = 0 + self._stride = 1 + + + def insert(self, obj): + with self._lock: + if obj in self._right_map: + return self._right_map[obj] + else: + handle = self._current_handle + self._current_handle += self._stride + self._left_map[handle] = obj + self._right_map[obj] = handle + return handle + + def get(self, handle): + with self._lock: + return self._left_map.get(handle) + + def remove(self, handle): + with self._lock: + if handle in self._left_map: + obj = self._left_map.pop(handle) + del self._right_map[obj] + return obj + +# Magic number for the Rust proxy to call using the same mechanism as every other method, +# to free the callback once it's dropped by Rust. +IDX_CALLBACK_FREE = 0 +# Return codes for callback calls +UNIFFI_CALLBACK_SUCCESS = 0 +UNIFFI_CALLBACK_ERROR = 1 +UNIFFI_CALLBACK_UNEXPECTED_ERROR = 2 + +class FfiConverterCallbackInterface: + _handle_map = ConcurrentHandleMap() + + def __init__(self, cb): + self._foreign_callback = cb + + def drop(self, handle): + self.__class__._handle_map.remove(handle) + + @classmethod + def lift(cls, handle): + obj = cls._handle_map.get(handle) + if not obj: + raise InternalError("The object in the handle map has been dropped already") + + return obj + + @classmethod + def read(cls, buf): + handle = buf.readU64() + cls.lift(handle) + + @classmethod + def lower(cls, cb): + handle = cls._handle_map.insert(cb) + return handle + + @classmethod + def write(cls, cb, buf): + buf.writeU64(cls.lower(cb)) + +# Declaration and FfiConverters for SignerCallback Callback Interface + +class SignerCallback: + def sign(self, data: "bytes"): + raise NotImplementedError + + + +def py_foreignCallbackCallbackInterfaceSignerCallback(handle, method, args_data, args_len, buf_ptr): + + def invoke_sign(python_callback, args_stream, buf_ptr): + def makeCall():return python_callback.sign( + FfiConverterBytes.read(args_stream) + ) + + def makeCallAndHandleReturn(): + rval = makeCall() + with RustBuffer.allocWithBuilder() as builder: + FfiConverterBytes.write(rval, builder) + buf_ptr[0] = builder.finalize() + return UNIFFI_CALLBACK_SUCCESS + try: + return makeCallAndHandleReturn() + except Error as e: + # Catch errors declared in the UDL file + with RustBuffer.allocWithBuilder() as builder: + FfiConverterTypeError.write(e, builder) + buf_ptr[0] = builder.finalize() + return UNIFFI_CALLBACK_ERROR + + + + cb = FfiConverterCallbackInterfaceSignerCallback.lift(handle) + if not cb: + raise InternalError("No callback in handlemap; this is a Uniffi bug") + + if method == IDX_CALLBACK_FREE: + FfiConverterCallbackInterfaceSignerCallback.drop(handle) + # Successfull return + # See docs of ForeignCallback in `uniffi_core/src/ffi/foreigncallbacks.rs` + return UNIFFI_CALLBACK_SUCCESS + + if method == 1: + # Call the method and handle any errors + # See docs of ForeignCallback in `uniffi_core/src/ffi/foreigncallbacks.rs` for details + try: + return invoke_sign(cb, RustBufferStream(args_data, args_len), buf_ptr) + except BaseException as e: + # Catch unexpected errors + try: + # Try to serialize the exception into a String + buf_ptr[0] = FfiConverterString.lower(repr(e)) + except: + # If that fails, just give up + pass + return UNIFFI_CALLBACK_UNEXPECTED_ERROR + + + # This should never happen, because an out of bounds method index won't + # ever be used. Once we can catch errors, we should return an InternalException. + # https://github.com/mozilla/uniffi-rs/issues/351 + + # An unexpected error happened. + # See docs of ForeignCallback in `uniffi_core/src/ffi/foreigncallbacks.rs` + return UNIFFI_CALLBACK_UNEXPECTED_ERROR + +# We need to keep this function reference alive: +# if they get GC'd while in use then UniFFI internals could attempt to call a function +# that is in freed memory. +# That would be...uh...bad. Yeah, that's the word. Bad. +foreignCallbackCallbackInterfaceSignerCallback = FOREIGN_CALLBACK_T(py_foreignCallbackCallbackInterfaceSignerCallback) +rust_call(lambda err: _UniFFILib.uniffi_c2pa_fn_init_callback_signercallback(foreignCallbackCallbackInterfaceSignerCallback, err)) + +# The FfiConverter which transforms the Callbacks in to Handles to pass to Rust. +FfiConverterCallbackInterfaceSignerCallback = FfiConverterCallbackInterface(foreignCallbackCallbackInterfaceSignerCallback) + + + + + +# Declaration and FfiConverters for Stream Callback Interface + +class Stream: + def read_stream(self, length: "int"): + raise NotImplementedError + + def seek_stream(self, pos: "int",mode: "SeekMode"): + raise NotImplementedError + + def write_stream(self, data: "bytes"): + raise NotImplementedError + + + +def py_foreignCallbackCallbackInterfaceStream(handle, method, args_data, args_len, buf_ptr): + + def invoke_read_stream(python_callback, args_stream, buf_ptr): + def makeCall():return python_callback.read_stream( + FfiConverterUInt64.read(args_stream) + ) + + def makeCallAndHandleReturn(): + rval = makeCall() + with RustBuffer.allocWithBuilder() as builder: + FfiConverterBytes.write(rval, builder) + buf_ptr[0] = builder.finalize() + return UNIFFI_CALLBACK_SUCCESS + try: + return makeCallAndHandleReturn() + except Error as e: + # Catch errors declared in the UDL file + with RustBuffer.allocWithBuilder() as builder: + FfiConverterTypeError.write(e, builder) + buf_ptr[0] = builder.finalize() + return UNIFFI_CALLBACK_ERROR + + + def invoke_seek_stream(python_callback, args_stream, buf_ptr): + def makeCall():return python_callback.seek_stream( + FfiConverterInt64.read(args_stream), + FfiConverterTypeSeekMode.read(args_stream) + ) + + def makeCallAndHandleReturn(): + rval = makeCall() + with RustBuffer.allocWithBuilder() as builder: + FfiConverterUInt64.write(rval, builder) + buf_ptr[0] = builder.finalize() + return UNIFFI_CALLBACK_SUCCESS + try: + return makeCallAndHandleReturn() + except Error as e: + # Catch errors declared in the UDL file + with RustBuffer.allocWithBuilder() as builder: + FfiConverterTypeError.write(e, builder) + buf_ptr[0] = builder.finalize() + return UNIFFI_CALLBACK_ERROR + + + def invoke_write_stream(python_callback, args_stream, buf_ptr): + def makeCall():return python_callback.write_stream( + FfiConverterBytes.read(args_stream) + ) + + def makeCallAndHandleReturn(): + rval = makeCall() + with RustBuffer.allocWithBuilder() as builder: + FfiConverterUInt64.write(rval, builder) + buf_ptr[0] = builder.finalize() + return UNIFFI_CALLBACK_SUCCESS + try: + return makeCallAndHandleReturn() + except Error as e: + # Catch errors declared in the UDL file + with RustBuffer.allocWithBuilder() as builder: + FfiConverterTypeError.write(e, builder) + buf_ptr[0] = builder.finalize() + return UNIFFI_CALLBACK_ERROR + + + + cb = FfiConverterCallbackInterfaceStream.lift(handle) + if not cb: + raise InternalError("No callback in handlemap; this is a Uniffi bug") + + if method == IDX_CALLBACK_FREE: + FfiConverterCallbackInterfaceStream.drop(handle) + # Successfull return + # See docs of ForeignCallback in `uniffi_core/src/ffi/foreigncallbacks.rs` + return UNIFFI_CALLBACK_SUCCESS + + if method == 1: + # Call the method and handle any errors + # See docs of ForeignCallback in `uniffi_core/src/ffi/foreigncallbacks.rs` for details + try: + return invoke_read_stream(cb, RustBufferStream(args_data, args_len), buf_ptr) + except BaseException as e: + # Catch unexpected errors + try: + # Try to serialize the exception into a String + buf_ptr[0] = FfiConverterString.lower(repr(e)) + except: + # If that fails, just give up + pass + return UNIFFI_CALLBACK_UNEXPECTED_ERROR + if method == 2: + # Call the method and handle any errors + # See docs of ForeignCallback in `uniffi_core/src/ffi/foreigncallbacks.rs` for details + try: + return invoke_seek_stream(cb, RustBufferStream(args_data, args_len), buf_ptr) + except BaseException as e: + # Catch unexpected errors + try: + # Try to serialize the exception into a String + buf_ptr[0] = FfiConverterString.lower(repr(e)) + except: + # If that fails, just give up + pass + return UNIFFI_CALLBACK_UNEXPECTED_ERROR + if method == 3: + # Call the method and handle any errors + # See docs of ForeignCallback in `uniffi_core/src/ffi/foreigncallbacks.rs` for details + try: + return invoke_write_stream(cb, RustBufferStream(args_data, args_len), buf_ptr) + except BaseException as e: + # Catch unexpected errors + try: + # Try to serialize the exception into a String + buf_ptr[0] = FfiConverterString.lower(repr(e)) + except: + # If that fails, just give up + pass + return UNIFFI_CALLBACK_UNEXPECTED_ERROR + + + # This should never happen, because an out of bounds method index won't + # ever be used. Once we can catch errors, we should return an InternalException. + # https://github.com/mozilla/uniffi-rs/issues/351 + + # An unexpected error happened. + # See docs of ForeignCallback in `uniffi_core/src/ffi/foreigncallbacks.rs` + return UNIFFI_CALLBACK_UNEXPECTED_ERROR + +# We need to keep this function reference alive: +# if they get GC'd while in use then UniFFI internals could attempt to call a function +# that is in freed memory. +# That would be...uh...bad. Yeah, that's the word. Bad. +foreignCallbackCallbackInterfaceStream = FOREIGN_CALLBACK_T(py_foreignCallbackCallbackInterfaceStream) +rust_call(lambda err: _UniFFILib.uniffi_c2pa_fn_init_callback_stream(foreignCallbackCallbackInterfaceStream, err)) + +# The FfiConverter which transforms the Callbacks in to Handles to pass to Rust. +FfiConverterCallbackInterfaceStream = FfiConverterCallbackInterface(foreignCallbackCallbackInterfaceStream) + + + +class FfiConverterOptionalString(FfiConverterRustBuffer): + @classmethod + def write(cls, value, buf): + if value is None: + buf.writeU8(0) + return + + buf.writeU8(1) + FfiConverterString.write(value, buf) + + @classmethod + def read(cls, buf): + flag = buf.readU8() + if flag == 0: + return None + elif flag == 1: + return FfiConverterString.read(buf) + else: + raise InternalError("Unexpected flag byte for optional type") + +def version(): + return FfiConverterString.lift(rust_call(_UniFFILib.uniffi_c2pa_fn_func_version,)) + + +def sdk_version(): + return FfiConverterString.lift(rust_call(_UniFFILib.uniffi_c2pa_fn_func_sdk_version,)) + + +__all__ = [ + "InternalError", + "Error", + "SeekMode", + "SigningAlg", + "version", + "sdk_version", + "Reader", + "CallbackSigner", + "Builder", + "Stream", + "SignerCallback", +] + From e73608b0623ae2eb08564ca93f5a5c1e212be6a2 Mon Sep 17 00:00:00 2001 From: Tania Mathern Date: Wed, 13 Nov 2024 21:01:21 -0800 Subject: [PATCH 03/25] Up maturin --- Makefile | 2 +- pyproject.toml | 2 +- requirements.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 33585bbf..fad5ba9d 100644 --- a/Makefile +++ b/Makefile @@ -4,9 +4,9 @@ # Pre-requisite: Python virtual environment is active (source .venv/bin/activate) build-python: release python3 -m venv .venv + source .venv/bin/activate python3 -m pip install -r requirements.txt python3 -m pip install -r requirements-dev.txt - python3 -m pip install -U c2pa-python cargo run --features=uniffi/cli --bin uniffi-bindgen generate src/adobe_api.udl -n --language python -o target/python maturin develop python3 ./tests/test_api.py diff --git a/pyproject.toml b/pyproject.toml index e2c32872..2d57e7bd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["maturin>=1.2,<2.0","uniffi_bindgen>=0.24,<0.25"] +requires = ["maturin>=1.7.4,<2.0","uniffi_bindgen>=0.24,<0.25"] build-backend = "maturin" [project] diff --git a/requirements.txt b/requirements.txt index 98fba72e..f21244b1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -maturin==1.2.0 +maturin==1.7.4 uniffi-bindgen==0.24.1 cryptography==43.0.1 \ No newline at end of file From 16d188fb2fa4ab11a19bbebaf37cba8d346df118 Mon Sep 17 00:00:00 2001 From: Tania Mathern Date: Wed, 13 Nov 2024 21:01:34 -0800 Subject: [PATCH 04/25] Up maturin --- Makefile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Makefile b/Makefile index fad5ba9d..ad116932 100644 --- a/Makefile +++ b/Makefile @@ -7,9 +7,7 @@ build-python: release source .venv/bin/activate python3 -m pip install -r requirements.txt python3 -m pip install -r requirements-dev.txt - cargo run --features=uniffi/cli --bin uniffi-bindgen generate src/adobe_api.udl -n --language python -o target/python maturin develop - python3 ./tests/test_api.py # Pre-requisite: Python virtual environment is active (source .venv/bin/activate) python-redeploy: release From 1c878d689645559ab6cf1326d1e6df4b56f58a2e Mon Sep 17 00:00:00 2001 From: Tania Mathern Date: Wed, 13 Nov 2024 21:14:24 -0800 Subject: [PATCH 05/25] WIP --- c2pa/c2pa/c2pa.py | 2301 ++++++++++++++++++++++++++------------------- requirements.txt | 2 +- 2 files changed, 1353 insertions(+), 950 deletions(-) diff --git a/c2pa/c2pa/c2pa.py b/c2pa/c2pa/c2pa.py index 8a71154c..44d755b0 100644 --- a/c2pa/c2pa/c2pa.py +++ b/c2pa/c2pa/c2pa.py @@ -1,3 +1,5 @@ + + # This file was autogenerated by some hot garbage in the `uniffi` crate. # Trust me, you don't want to mess with it! @@ -13,6 +15,7 @@ # compile the rust component. The easiest way to ensure this is to bundle the Python # helpers directly inline like we're doing here. +from __future__ import annotations import os import sys import ctypes @@ -20,46 +23,53 @@ import struct import contextlib import datetime +import threading +import itertools +import traceback import typing import platform # Used for default argument values -DEFAULT = object() +_DEFAULT = object() # type: typing.Any -class RustBuffer(ctypes.Structure): +class _UniffiRustBuffer(ctypes.Structure): _fields_ = [ - ("capacity", ctypes.c_int32), - ("len", ctypes.c_int32), + ("capacity", ctypes.c_uint64), + ("len", ctypes.c_uint64), ("data", ctypes.POINTER(ctypes.c_char)), ] + @staticmethod + def default(): + return _UniffiRustBuffer(0, 0, None) + @staticmethod def alloc(size): - return rust_call(_UniFFILib.ffi_c2pa_rustbuffer_alloc, size) + return _uniffi_rust_call(_UniffiLib.ffi_c2pa_rustbuffer_alloc, size) @staticmethod def reserve(rbuf, additional): - return rust_call(_UniFFILib.ffi_c2pa_rustbuffer_reserve, rbuf, additional) + return _uniffi_rust_call(_UniffiLib.ffi_c2pa_rustbuffer_reserve, rbuf, additional) def free(self): - return rust_call(_UniFFILib.ffi_c2pa_rustbuffer_free, self) + return _uniffi_rust_call(_UniffiLib.ffi_c2pa_rustbuffer_free, self) def __str__(self): - return "RustBuffer(capacity={}, len={}, data={})".format( + return "_UniffiRustBuffer(capacity={}, len={}, data={})".format( self.capacity, self.len, self.data[0:self.len] ) @contextlib.contextmanager - def allocWithBuilder(*args): - """Context-manger to allocate a buffer using a RustBufferBuilder. + def alloc_with_builder(*args): + """Context-manger to allocate a buffer using a _UniffiRustBufferBuilder. The allocated buffer will be automatically freed if an error occurs, ensuring that we don't accidentally leak it. """ - builder = RustBufferBuilder() + builder = _UniffiRustBufferBuilder() try: yield builder except: @@ -67,45 +77,45 @@ def allocWithBuilder(*args): raise @contextlib.contextmanager - def consumeWithStream(self): - """Context-manager to consume a buffer using a RustBufferStream. + def consume_with_stream(self): + """Context-manager to consume a buffer using a _UniffiRustBufferStream. - The RustBuffer will be freed once the context-manager exits, ensuring that we don't + The _UniffiRustBuffer will be freed once the context-manager exits, ensuring that we don't leak it even if an error occurs. """ try: - s = RustBufferStream.from_rust_buffer(self) + s = _UniffiRustBufferStream.from_rust_buffer(self) yield s if s.remaining() != 0: - raise RuntimeError("junk data left in buffer at end of consumeWithStream") + raise RuntimeError("junk data left in buffer at end of consume_with_stream") finally: self.free() @contextlib.contextmanager - def readWithStream(self): - """Context-manager to read a buffer using a RustBufferStream. + def read_with_stream(self): + """Context-manager to read a buffer using a _UniffiRustBufferStream. - This is like consumeWithStream, but doesn't free the buffer afterwards. - It should only be used with borrowed `RustBuffer` data. + This is like consume_with_stream, but doesn't free the buffer afterwards. + It should only be used with borrowed `_UniffiRustBuffer` data. """ - s = RustBufferStream.from_rust_buffer(self) + s = _UniffiRustBufferStream.from_rust_buffer(self) yield s if s.remaining() != 0: - raise RuntimeError("junk data left in buffer at end of readWithStream") + raise RuntimeError("junk data left in buffer at end of read_with_stream") -class ForeignBytes(ctypes.Structure): +class _UniffiForeignBytes(ctypes.Structure): _fields_ = [ ("len", ctypes.c_int32), ("data", ctypes.POINTER(ctypes.c_char)), ] def __str__(self): - return "ForeignBytes(len={}, data={})".format(self.len, self.data[0:self.len]) + return "_UniffiForeignBytes(len={}, data={})".format(self.len, self.data[0:self.len]) -class RustBufferStream: +class _UniffiRustBufferStream: """ - Helper for structured reading of bytes from a RustBuffer + Helper for structured reading of bytes from a _UniffiRustBuffer """ def __init__(self, data, len): @@ -134,47 +144,44 @@ def read(self, size): self.offset += size return data - def readI8(self): + def read_i8(self): return self._unpack_from(1, ">b") - def readU8(self): + def read_u8(self): return self._unpack_from(1, ">B") - def readI16(self): + def read_i16(self): return self._unpack_from(2, ">h") - def readU16(self): + def read_u16(self): return self._unpack_from(2, ">H") - def readI32(self): + def read_i32(self): return self._unpack_from(4, ">i") - def readU32(self): + def read_u32(self): return self._unpack_from(4, ">I") - def readI64(self): + def read_i64(self): return self._unpack_from(8, ">q") - def readU64(self): + def read_u64(self): return self._unpack_from(8, ">Q") - def readFloat(self): + def read_float(self): v = self._unpack_from(4, ">f") return v - def readDouble(self): + def read_double(self): return self._unpack_from(8, ">d") - def readCSizeT(self): - return self._unpack_from(ctypes.sizeof(ctypes.c_size_t) , "@N") - -class RustBufferBuilder: +class _UniffiRustBufferBuilder: """ - Helper for structured writing of bytes into a RustBuffer. + Helper for structured writing of bytes into a _UniffiRustBuffer. """ def __init__(self): - self.rbuf = RustBuffer.alloc(16) + self.rbuf = _UniffiRustBuffer.alloc(16) self.rbuf.len = 0 def finalize(self): @@ -188,11 +195,11 @@ def discard(self): rbuf.free() @contextlib.contextmanager - def _reserve(self, numBytes): - if self.rbuf.len + numBytes > self.rbuf.capacity: - self.rbuf = RustBuffer.reserve(self.rbuf, numBytes) + def _reserve(self, num_bytes): + if self.rbuf.len + num_bytes > self.rbuf.capacity: + self.rbuf = _UniffiRustBuffer.reserve(self.rbuf, num_bytes) yield None - self.rbuf.len += numBytes + self.rbuf.len += num_bytes def _pack_into(self, size, format, value): with self._reserve(size): @@ -205,37 +212,37 @@ def write(self, value): for i, byte in enumerate(value): self.rbuf.data[self.rbuf.len + i] = byte - def writeI8(self, v): + def write_i8(self, v): self._pack_into(1, ">b", v) - def writeU8(self, v): + def write_u8(self, v): self._pack_into(1, ">B", v) - def writeI16(self, v): + def write_i16(self, v): self._pack_into(2, ">h", v) - def writeU16(self, v): + def write_u16(self, v): self._pack_into(2, ">H", v) - def writeI32(self, v): + def write_i32(self, v): self._pack_into(4, ">i", v) - def writeU32(self, v): + def write_u32(self, v): self._pack_into(4, ">I", v) - def writeI64(self, v): + def write_i64(self, v): self._pack_into(8, ">q", v) - def writeU64(self, v): + def write_u64(self, v): self._pack_into(8, ">Q", v) - def writeFloat(self, v): + def write_float(self, v): self._pack_into(4, ">f", v) - def writeDouble(self, v): + def write_double(self, v): self._pack_into(8, ">d", v) - def writeCSizeT(self, v): + def write_c_size_t(self, v): self._pack_into(ctypes.sizeof(ctypes.c_size_t) , "@N", v) # A handful of classes and functions to support the generated data structures. # This would be a good candidate for isolating in its own ffi-support lib. @@ -243,183 +250,135 @@ def writeCSizeT(self, v): class InternalError(Exception): pass -class RustCallStatus(ctypes.Structure): +class _UniffiRustCallStatus(ctypes.Structure): """ Error runtime. """ _fields_ = [ ("code", ctypes.c_int8), - ("error_buf", RustBuffer), + ("error_buf", _UniffiRustBuffer), ] # These match the values from the uniffi::rustcalls module CALL_SUCCESS = 0 CALL_ERROR = 1 - CALL_PANIC = 2 + CALL_UNEXPECTED_ERROR = 2 + + @staticmethod + def default(): + return _UniffiRustCallStatus(code=_UniffiRustCallStatus.CALL_SUCCESS, error_buf=_UniffiRustBuffer.default()) def __str__(self): - if self.code == RustCallStatus.CALL_SUCCESS: - return "RustCallStatus(CALL_SUCCESS)" - elif self.code == RustCallStatus.CALL_ERROR: - return "RustCallStatus(CALL_ERROR)" - elif self.code == RustCallStatus.CALL_PANIC: - return "RustCallStatus(CALL_PANIC)" + if self.code == _UniffiRustCallStatus.CALL_SUCCESS: + return "_UniffiRustCallStatus(CALL_SUCCESS)" + elif self.code == _UniffiRustCallStatus.CALL_ERROR: + return "_UniffiRustCallStatus(CALL_ERROR)" + elif self.code == _UniffiRustCallStatus.CALL_UNEXPECTED_ERROR: + return "_UniffiRustCallStatus(CALL_UNEXPECTED_ERROR)" else: - return "RustCallStatus()" + return "_UniffiRustCallStatus()" -def rust_call(fn, *args): +def _uniffi_rust_call(fn, *args): # Call a rust function - return rust_call_with_error(None, fn, *args) + return _uniffi_rust_call_with_error(None, fn, *args) -def rust_call_with_error(error_ffi_converter, fn, *args): +def _uniffi_rust_call_with_error(error_ffi_converter, fn, *args): # Call a rust function and handle any errors # # This function is used for rust calls that return Result<> and therefore can set the CALL_ERROR status code. - # error_ffi_converter must be set to the FfiConverter for the error class that corresponds to the result. - call_status = RustCallStatus(code=RustCallStatus.CALL_SUCCESS, error_buf=RustBuffer(0, 0, None)) + # error_ffi_converter must be set to the _UniffiConverter for the error class that corresponds to the result. + call_status = _UniffiRustCallStatus.default() args_with_error = args + (ctypes.byref(call_status),) result = fn(*args_with_error) - uniffi_check_call_status(error_ffi_converter, call_status) + _uniffi_check_call_status(error_ffi_converter, call_status) return result -def rust_call_async(scaffolding_fn, callback_fn, *args): - # Call the scaffolding function, passing it a callback handler for `AsyncTypes.py` and a pointer - # to a python Future object. The async function then awaits the Future. - uniffi_eventloop = asyncio.get_running_loop() - uniffi_py_future = uniffi_eventloop.create_future() - uniffi_call_status = RustCallStatus(code=RustCallStatus.CALL_SUCCESS, error_buf=RustBuffer(0, 0, None)) - scaffolding_fn(*args, - FfiConverterForeignExecutor._pointer_manager.new_pointer(uniffi_eventloop), - callback_fn, - # Note: It's tempting to skip the pointer manager and just use a `py_object` pointing to a - # local variable like we do in Swift. However, Python doesn't use cooperative cancellation - # -- asyncio can cancel a task at anytime. This means if we use a local variable, the Rust - # callback could fire with a dangling pointer. - UniFfiPyFuturePointerManager.new_pointer(uniffi_py_future), - ctypes.byref(uniffi_call_status), - ) - uniffi_check_call_status(None, uniffi_call_status) - return uniffi_py_future - -def uniffi_check_call_status(error_ffi_converter, call_status): - if call_status.code == RustCallStatus.CALL_SUCCESS: +def _uniffi_check_call_status(error_ffi_converter, call_status): + if call_status.code == _UniffiRustCallStatus.CALL_SUCCESS: pass - elif call_status.code == RustCallStatus.CALL_ERROR: + elif call_status.code == _UniffiRustCallStatus.CALL_ERROR: if error_ffi_converter is None: call_status.error_buf.free() - raise InternalError("rust_call_with_error: CALL_ERROR, but error_ffi_converter is None") + raise InternalError("_uniffi_rust_call_with_error: CALL_ERROR, but error_ffi_converter is None") else: raise error_ffi_converter.lift(call_status.error_buf) - elif call_status.code == RustCallStatus.CALL_PANIC: - # When the rust code sees a panic, it tries to construct a RustBuffer + elif call_status.code == _UniffiRustCallStatus.CALL_UNEXPECTED_ERROR: + # When the rust code sees a panic, it tries to construct a _UniffiRustBuffer # with the message. But if that code panics, then it just sends back # an empty buffer. if call_status.error_buf.len > 0: - msg = FfiConverterString.lift(call_status.error_buf) + msg = _UniffiConverterString.lift(call_status.error_buf) else: msg = "Unknown rust panic" raise InternalError(msg) else: - raise InternalError("Invalid RustCallStatus code: {}".format( + raise InternalError("Invalid _UniffiRustCallStatus code: {}".format( call_status.code)) -# A function pointer for a callback as defined by UniFFI. -# Rust definition `fn(handle: u64, method: u32, args: RustBuffer, buf_ptr: *mut RustBuffer) -> int` -FOREIGN_CALLBACK_T = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_ulonglong, ctypes.c_ulong, ctypes.POINTER(ctypes.c_char), ctypes.c_int, ctypes.POINTER(RustBuffer)) -class UniFfiPointerManagerCPython: - """ - Manage giving out pointers to Python objects on CPython +def _uniffi_trait_interface_call(call_status, make_call, write_return_value): + try: + return write_return_value(make_call()) + except Exception as e: + call_status.code = _UniffiRustCallStatus.CALL_UNEXPECTED_ERROR + call_status.error_buf = _UniffiConverterString.lower(repr(e)) - This class is used to generate opaque pointers that reference Python objects to pass to Rust. - It assumes a CPython platform. See UniFfiPointerManagerGeneral for the alternative. - """ - - def new_pointer(self, obj): - """ - Get a pointer for an object as a ctypes.c_size_t instance - - Each call to new_pointer() must be balanced with exactly one call to release_pointer() - - This returns a ctypes.c_size_t. This is always the same size as a pointer and can be - interchanged with pointers for FFI function arguments and return values. - """ - # IncRef the object since we're going to pass a pointer to Rust - ctypes.pythonapi.Py_IncRef(ctypes.py_object(obj)) - # id() is the object address on CPython - # (https://docs.python.org/3/library/functions.html#id) - return id(obj) - - def release_pointer(self, address): - py_obj = ctypes.cast(address, ctypes.py_object) - obj = py_obj.value - ctypes.pythonapi.Py_DecRef(py_obj) - return obj - - def lookup(self, address): - return ctypes.cast(address, ctypes.py_object).value - -class UniFfiPointerManagerGeneral: +def _uniffi_trait_interface_call_with_error(call_status, make_call, write_return_value, error_type, lower_error): + try: + try: + return write_return_value(make_call()) + except error_type as e: + call_status.code = _UniffiRustCallStatus.CALL_ERROR + call_status.error_buf = lower_error(e) + except Exception as e: + call_status.code = _UniffiRustCallStatus.CALL_UNEXPECTED_ERROR + call_status.error_buf = _UniffiConverterString.lower(repr(e)) +class _UniffiHandleMap: """ - Manage giving out pointers to Python objects on non-CPython platforms - - This has the same API as UniFfiPointerManagerCPython, but doesn't assume we're running on - CPython and is slightly slower. - - Instead of using real pointers, it maps integer values to objects and returns the keys as - c_size_t values. + A map where inserting, getting and removing data is synchronized with a lock. """ def __init__(self): - self._map = {} + # type Handle = int + self._map = {} # type: Dict[Handle, Any] self._lock = threading.Lock() - self._current_handle = 0 + self._counter = itertools.count() - def new_pointer(self, obj): + def insert(self, obj): with self._lock: - handle = self._current_handle - self._current_handle += 1 + handle = next(self._counter) self._map[handle] = obj - return handle - - def release_pointer(self, handle): - with self._lock: - return self._map.pop(handle) + return handle - def lookup(self, handle): - with self._lock: - return self._map[handle] - -# Pick an pointer manager implementation based on the platform -if platform.python_implementation() == 'CPython': - UniFfiPointerManager = UniFfiPointerManagerCPython # type: ignore -else: - UniFfiPointerManager = UniFfiPointerManagerGeneral # type: ignore -# Types conforming to `FfiConverterPrimitive` pass themselves directly over the FFI. -class FfiConverterPrimitive: - @classmethod - def check(cls, value): - return value + def get(self, handle): + try: + with self._lock: + return self._map[handle] + except KeyError: + raise InternalError("_UniffiHandleMap.get: Invalid handle") + def remove(self, handle): + try: + with self._lock: + return self._map.pop(handle) + except KeyError: + raise InternalError("_UniffiHandleMap.remove: Invalid handle") + + def __len__(self): + return len(self._map) +# Types conforming to `_UniffiConverterPrimitive` pass themselves directly over the FFI. +class _UniffiConverterPrimitive: @classmethod def lift(cls, value): return value @classmethod def lower(cls, value): - return cls.lowerUnchecked(cls.check(value)) - - @classmethod - def lowerUnchecked(cls, value): return value +class _UniffiConverterPrimitiveInt(_UniffiConverterPrimitive): @classmethod - def write(cls, value, buf): - cls.writeUnchecked(cls.check(value), buf) - -class FfiConverterPrimitiveInt(FfiConverterPrimitive): - @classmethod - def check(cls, value): + def check_lower(cls, value): try: value = value.__index__() except Exception: @@ -428,67 +387,46 @@ def check(cls, value): raise TypeError("__index__ returned non-int (type {})".format(type(value).__name__)) if not cls.VALUE_MIN <= value < cls.VALUE_MAX: raise ValueError("{} requires {} <= value < {}".format(cls.CLASS_NAME, cls.VALUE_MIN, cls.VALUE_MAX)) - return super().check(value) -class FfiConverterPrimitiveFloat(FfiConverterPrimitive): +class _UniffiConverterPrimitiveFloat(_UniffiConverterPrimitive): @classmethod - def check(cls, value): + def check_lower(cls, value): try: value = value.__float__() except Exception: raise TypeError("must be real number, not {}".format(type(value).__name__)) if not isinstance(value, float): raise TypeError("__float__ returned non-float (type {})".format(type(value).__name__)) - return super().check(value) -# Helper class for wrapper types that will always go through a RustBuffer. +# Helper class for wrapper types that will always go through a _UniffiRustBuffer. # Classes should inherit from this and implement the `read` and `write` static methods. -class FfiConverterRustBuffer: +class _UniffiConverterRustBuffer: @classmethod def lift(cls, rbuf): - with rbuf.consumeWithStream() as stream: + with rbuf.consume_with_stream() as stream: return cls.read(stream) @classmethod def lower(cls, value): - with RustBuffer.allocWithBuilder() as builder: + with _UniffiRustBuffer.alloc_with_builder() as builder: cls.write(value, builder) return builder.finalize() -# Contains loading, initialization code, -# and the FFI Function declarations in a com.sun.jna.Library. +# Contains loading, initialization code, and the FFI Function declarations. # Define some ctypes FFI types that we use in the library -""" -ctypes type for the foreign executor callback. This is a built-in interface for scheduling -tasks - -Args: - executor: opaque c_size_t value representing the eventloop - delay: delay in ms - task: function pointer to the task callback - task_data: void pointer to the task callback data - -Normally we should call task(task_data) after the detail. -However, when task is NULL this indicates that Rust has dropped the ForeignExecutor and we should -decrease the EventLoop refcount. -""" -UNIFFI_FOREIGN_EXECUTOR_CALLBACK_T = ctypes.CFUNCTYPE(None, ctypes.c_size_t, ctypes.c_uint32, ctypes.c_void_p, ctypes.c_void_p) - """ Function pointer for a Rust task, which a callback function that takes a opaque pointer """ -UNIFFI_RUST_TASK = ctypes.CFUNCTYPE(None, ctypes.c_void_p) +_UNIFFI_RUST_TASK = ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.c_int8) -def uniffi_future_callback_t(return_type): +def _uniffi_future_callback_t(return_type): """ Factory function to create callback function types for async functions """ - return ctypes.CFUNCTYPE(None, ctypes.c_size_t, return_type, RustCallStatus) + return ctypes.CFUNCTYPE(None, ctypes.c_uint64, return_type, _UniffiRustCallStatus) -from pathlib import Path - -def loadIndirect(): +def _uniffi_load_indirect(): """ This is how we find and load the dynamic library provided by the component. For now we just look it up by name. @@ -509,395 +447,826 @@ def loadIndirect(): libname = "lib{}.so" libname = libname.format("uniffi_c2pa") - path = str(Path(__file__).parent / libname) + path = os.path.join(os.path.dirname(__file__), libname) lib = ctypes.cdll.LoadLibrary(path) return lib -def uniffi_check_contract_api_version(lib): +def _uniffi_check_contract_api_version(lib): # Get the bindings contract version from our ComponentInterface - bindings_contract_version = 22 + bindings_contract_version = 26 # Get the scaffolding contract version by calling the into the dylib scaffolding_contract_version = lib.ffi_c2pa_uniffi_contract_version() if bindings_contract_version != scaffolding_contract_version: raise InternalError("UniFFI contract version mismatch: try cleaning and rebuilding your project") -def uniffi_check_api_checksums(lib): - if lib.uniffi_c2pa_checksum_func_version() != 31632: +def _uniffi_check_api_checksums(lib): + if lib.uniffi_c2pa_checksum_func_sdk_version() != 37245: + raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + if lib.uniffi_c2pa_checksum_func_version() != 61576: + raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + if lib.uniffi_c2pa_checksum_method_builder_add_ingredient() != 56163: + raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + if lib.uniffi_c2pa_checksum_method_builder_add_resource() != 52123: + raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + if lib.uniffi_c2pa_checksum_method_builder_from_archive() != 45068: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_func_sdk_version() != 32199: + if lib.uniffi_c2pa_checksum_method_builder_set_no_embed() != 4775: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_method_reader_from_stream() != 50669: + if lib.uniffi_c2pa_checksum_method_builder_set_remote_url() != 26105: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_method_reader_from_manifest_data_and_stream() != 30428: + if lib.uniffi_c2pa_checksum_method_builder_sign() != 5940: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_method_reader_json() != 18261: + if lib.uniffi_c2pa_checksum_method_builder_sign_file() != 2785: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_method_reader_resource_to_stream() != 29142: + if lib.uniffi_c2pa_checksum_method_builder_to_archive() != 56076: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_method_builder_with_json() != 29835: + if lib.uniffi_c2pa_checksum_method_builder_with_json() != 60973: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_method_builder_set_no_embed() != 46988: + if lib.uniffi_c2pa_checksum_method_reader_from_manifest_data_and_stream() != 58448: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_method_builder_set_remote_url() != 25667: + if lib.uniffi_c2pa_checksum_method_reader_from_stream() != 62816: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_method_builder_add_resource() != 29891: + if lib.uniffi_c2pa_checksum_method_reader_json() != 25079: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_method_builder_add_ingredient() != 50859: + if lib.uniffi_c2pa_checksum_method_reader_resource_to_stream() != 32633: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_method_builder_to_archive() != 6987: + if lib.uniffi_c2pa_checksum_constructor_builder_new() != 43948: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_method_builder_from_archive() != 56644: + if lib.uniffi_c2pa_checksum_constructor_callbacksigner_new() != 65452: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_method_builder_sign() != 9859: + if lib.uniffi_c2pa_checksum_constructor_callbacksigner_new_from_signer() != 27376: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_method_builder_sign_file() != 64222: + if lib.uniffi_c2pa_checksum_constructor_reader_new() != 19939: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_constructor_reader_new() != 39952: + if lib.uniffi_c2pa_checksum_method_signercallback_sign() != 64776: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_constructor_callbacksigner_new() != 15795: + if lib.uniffi_c2pa_checksum_method_stream_read_stream() != 16779: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_constructor_callbacksigner_new_from_signer() != 25848: + if lib.uniffi_c2pa_checksum_method_stream_seek_stream() != 39220: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_constructor_builder_new() != 6168: + if lib.uniffi_c2pa_checksum_method_stream_write_stream() != 63217: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") # A ctypes library to expose the extern-C FFI definitions. # This is an implementation detail which will be called internally by the public API. -_UniFFILib = loadIndirect() -_UniFFILib.uniffi_c2pa_fn_free_reader.argtypes = ( +_UniffiLib = _uniffi_load_indirect() +_UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK = ctypes.CFUNCTYPE(None,ctypes.c_uint64,ctypes.c_int8, +) +_UNIFFI_FOREIGN_FUTURE_FREE = ctypes.CFUNCTYPE(None,ctypes.c_uint64, +) +_UNIFFI_CALLBACK_INTERFACE_FREE = ctypes.CFUNCTYPE(None,ctypes.c_uint64, +) +class _UniffiForeignFuture(ctypes.Structure): + _fields_ = [ + ("handle", ctypes.c_uint64), + ("free", _UNIFFI_FOREIGN_FUTURE_FREE), + ] +class _UniffiForeignFutureStructU8(ctypes.Structure): + _fields_ = [ + ("return_value", ctypes.c_uint8), + ("call_status", _UniffiRustCallStatus), + ] +_UNIFFI_FOREIGN_FUTURE_COMPLETE_U8 = ctypes.CFUNCTYPE(None,ctypes.c_uint64,_UniffiForeignFutureStructU8, +) +class _UniffiForeignFutureStructI8(ctypes.Structure): + _fields_ = [ + ("return_value", ctypes.c_int8), + ("call_status", _UniffiRustCallStatus), + ] +_UNIFFI_FOREIGN_FUTURE_COMPLETE_I8 = ctypes.CFUNCTYPE(None,ctypes.c_uint64,_UniffiForeignFutureStructI8, +) +class _UniffiForeignFutureStructU16(ctypes.Structure): + _fields_ = [ + ("return_value", ctypes.c_uint16), + ("call_status", _UniffiRustCallStatus), + ] +_UNIFFI_FOREIGN_FUTURE_COMPLETE_U16 = ctypes.CFUNCTYPE(None,ctypes.c_uint64,_UniffiForeignFutureStructU16, +) +class _UniffiForeignFutureStructI16(ctypes.Structure): + _fields_ = [ + ("return_value", ctypes.c_int16), + ("call_status", _UniffiRustCallStatus), + ] +_UNIFFI_FOREIGN_FUTURE_COMPLETE_I16 = ctypes.CFUNCTYPE(None,ctypes.c_uint64,_UniffiForeignFutureStructI16, +) +class _UniffiForeignFutureStructU32(ctypes.Structure): + _fields_ = [ + ("return_value", ctypes.c_uint32), + ("call_status", _UniffiRustCallStatus), + ] +_UNIFFI_FOREIGN_FUTURE_COMPLETE_U32 = ctypes.CFUNCTYPE(None,ctypes.c_uint64,_UniffiForeignFutureStructU32, +) +class _UniffiForeignFutureStructI32(ctypes.Structure): + _fields_ = [ + ("return_value", ctypes.c_int32), + ("call_status", _UniffiRustCallStatus), + ] +_UNIFFI_FOREIGN_FUTURE_COMPLETE_I32 = ctypes.CFUNCTYPE(None,ctypes.c_uint64,_UniffiForeignFutureStructI32, +) +class _UniffiForeignFutureStructU64(ctypes.Structure): + _fields_ = [ + ("return_value", ctypes.c_uint64), + ("call_status", _UniffiRustCallStatus), + ] +_UNIFFI_FOREIGN_FUTURE_COMPLETE_U64 = ctypes.CFUNCTYPE(None,ctypes.c_uint64,_UniffiForeignFutureStructU64, +) +class _UniffiForeignFutureStructI64(ctypes.Structure): + _fields_ = [ + ("return_value", ctypes.c_int64), + ("call_status", _UniffiRustCallStatus), + ] +_UNIFFI_FOREIGN_FUTURE_COMPLETE_I64 = ctypes.CFUNCTYPE(None,ctypes.c_uint64,_UniffiForeignFutureStructI64, +) +class _UniffiForeignFutureStructF32(ctypes.Structure): + _fields_ = [ + ("return_value", ctypes.c_float), + ("call_status", _UniffiRustCallStatus), + ] +_UNIFFI_FOREIGN_FUTURE_COMPLETE_F32 = ctypes.CFUNCTYPE(None,ctypes.c_uint64,_UniffiForeignFutureStructF32, +) +class _UniffiForeignFutureStructF64(ctypes.Structure): + _fields_ = [ + ("return_value", ctypes.c_double), + ("call_status", _UniffiRustCallStatus), + ] +_UNIFFI_FOREIGN_FUTURE_COMPLETE_F64 = ctypes.CFUNCTYPE(None,ctypes.c_uint64,_UniffiForeignFutureStructF64, +) +class _UniffiForeignFutureStructPointer(ctypes.Structure): + _fields_ = [ + ("return_value", ctypes.c_void_p), + ("call_status", _UniffiRustCallStatus), + ] +_UNIFFI_FOREIGN_FUTURE_COMPLETE_POINTER = ctypes.CFUNCTYPE(None,ctypes.c_uint64,_UniffiForeignFutureStructPointer, +) +class _UniffiForeignFutureStructRustBuffer(ctypes.Structure): + _fields_ = [ + ("return_value", _UniffiRustBuffer), + ("call_status", _UniffiRustCallStatus), + ] +_UNIFFI_FOREIGN_FUTURE_COMPLETE_RUST_BUFFER = ctypes.CFUNCTYPE(None,ctypes.c_uint64,_UniffiForeignFutureStructRustBuffer, +) +class _UniffiForeignFutureStructVoid(ctypes.Structure): + _fields_ = [ + ("call_status", _UniffiRustCallStatus), + ] +_UNIFFI_FOREIGN_FUTURE_COMPLETE_VOID = ctypes.CFUNCTYPE(None,ctypes.c_uint64,_UniffiForeignFutureStructVoid, +) +_UNIFFI_CALLBACK_INTERFACE_SIGNER_CALLBACK_METHOD0 = ctypes.CFUNCTYPE(None,ctypes.c_uint64,_UniffiRustBuffer,ctypes.POINTER(_UniffiRustBuffer), + ctypes.POINTER(_UniffiRustCallStatus), +) +_UNIFFI_CALLBACK_INTERFACE_STREAM_METHOD0 = ctypes.CFUNCTYPE(None,ctypes.c_uint64,ctypes.c_uint64,ctypes.POINTER(_UniffiRustBuffer), + ctypes.POINTER(_UniffiRustCallStatus), +) +_UNIFFI_CALLBACK_INTERFACE_STREAM_METHOD1 = ctypes.CFUNCTYPE(None,ctypes.c_uint64,ctypes.c_int64,_UniffiRustBuffer,ctypes.POINTER(ctypes.c_uint64), + ctypes.POINTER(_UniffiRustCallStatus), +) +_UNIFFI_CALLBACK_INTERFACE_STREAM_METHOD2 = ctypes.CFUNCTYPE(None,ctypes.c_uint64,_UniffiRustBuffer,ctypes.POINTER(ctypes.c_uint64), + ctypes.POINTER(_UniffiRustCallStatus), +) +class _UniffiVTableCallbackInterfaceSignerCallback(ctypes.Structure): + _fields_ = [ + ("sign", _UNIFFI_CALLBACK_INTERFACE_SIGNER_CALLBACK_METHOD0), + ("uniffi_free", _UNIFFI_CALLBACK_INTERFACE_FREE), + ] +class _UniffiVTableCallbackInterfaceStream(ctypes.Structure): + _fields_ = [ + ("read_stream", _UNIFFI_CALLBACK_INTERFACE_STREAM_METHOD0), + ("seek_stream", _UNIFFI_CALLBACK_INTERFACE_STREAM_METHOD1), + ("write_stream", _UNIFFI_CALLBACK_INTERFACE_STREAM_METHOD2), + ("uniffi_free", _UNIFFI_CALLBACK_INTERFACE_FREE), + ] +_UniffiLib.uniffi_c2pa_fn_clone_builder.argtypes = ( + ctypes.c_void_p, + ctypes.POINTER(_UniffiRustCallStatus), +) +_UniffiLib.uniffi_c2pa_fn_clone_builder.restype = ctypes.c_void_p +_UniffiLib.uniffi_c2pa_fn_free_builder.argtypes = ( ctypes.c_void_p, - ctypes.POINTER(RustCallStatus), + ctypes.POINTER(_UniffiRustCallStatus), ) -_UniFFILib.uniffi_c2pa_fn_free_reader.restype = None -_UniFFILib.uniffi_c2pa_fn_constructor_reader_new.argtypes = ( - ctypes.POINTER(RustCallStatus), +_UniffiLib.uniffi_c2pa_fn_free_builder.restype = None +_UniffiLib.uniffi_c2pa_fn_constructor_builder_new.argtypes = ( + ctypes.POINTER(_UniffiRustCallStatus), ) -_UniFFILib.uniffi_c2pa_fn_constructor_reader_new.restype = ctypes.c_void_p -_UniFFILib.uniffi_c2pa_fn_method_reader_from_stream.argtypes = ( +_UniffiLib.uniffi_c2pa_fn_constructor_builder_new.restype = ctypes.c_void_p +_UniffiLib.uniffi_c2pa_fn_method_builder_add_ingredient.argtypes = ( ctypes.c_void_p, - RustBuffer, + _UniffiRustBuffer, + _UniffiRustBuffer, ctypes.c_uint64, - ctypes.POINTER(RustCallStatus), + ctypes.POINTER(_UniffiRustCallStatus), ) -_UniFFILib.uniffi_c2pa_fn_method_reader_from_stream.restype = RustBuffer -_UniFFILib.uniffi_c2pa_fn_method_reader_from_manifest_data_and_stream.argtypes = ( +_UniffiLib.uniffi_c2pa_fn_method_builder_add_ingredient.restype = None +_UniffiLib.uniffi_c2pa_fn_method_builder_add_resource.argtypes = ( ctypes.c_void_p, - RustBuffer, - RustBuffer, + _UniffiRustBuffer, ctypes.c_uint64, - ctypes.POINTER(RustCallStatus), + ctypes.POINTER(_UniffiRustCallStatus), ) -_UniFFILib.uniffi_c2pa_fn_method_reader_from_manifest_data_and_stream.restype = RustBuffer -_UniFFILib.uniffi_c2pa_fn_method_reader_json.argtypes = ( +_UniffiLib.uniffi_c2pa_fn_method_builder_add_resource.restype = None +_UniffiLib.uniffi_c2pa_fn_method_builder_from_archive.argtypes = ( ctypes.c_void_p, - ctypes.POINTER(RustCallStatus), + ctypes.c_uint64, + ctypes.POINTER(_UniffiRustCallStatus), ) -_UniFFILib.uniffi_c2pa_fn_method_reader_json.restype = RustBuffer -_UniFFILib.uniffi_c2pa_fn_method_reader_resource_to_stream.argtypes = ( +_UniffiLib.uniffi_c2pa_fn_method_builder_from_archive.restype = None +_UniffiLib.uniffi_c2pa_fn_method_builder_set_no_embed.argtypes = ( ctypes.c_void_p, - RustBuffer, - ctypes.c_uint64, - ctypes.POINTER(RustCallStatus), + ctypes.POINTER(_UniffiRustCallStatus), ) -_UniFFILib.uniffi_c2pa_fn_method_reader_resource_to_stream.restype = ctypes.c_uint64 -_UniFFILib.uniffi_c2pa_fn_free_callbacksigner.argtypes = ( +_UniffiLib.uniffi_c2pa_fn_method_builder_set_no_embed.restype = None +_UniffiLib.uniffi_c2pa_fn_method_builder_set_remote_url.argtypes = ( ctypes.c_void_p, - ctypes.POINTER(RustCallStatus), + _UniffiRustBuffer, + ctypes.POINTER(_UniffiRustCallStatus), ) -_UniFFILib.uniffi_c2pa_fn_free_callbacksigner.restype = None -_UniFFILib.uniffi_c2pa_fn_constructor_callbacksigner_new.argtypes = ( +_UniffiLib.uniffi_c2pa_fn_method_builder_set_remote_url.restype = None +_UniffiLib.uniffi_c2pa_fn_method_builder_sign.argtypes = ( + ctypes.c_void_p, + ctypes.c_void_p, + _UniffiRustBuffer, ctypes.c_uint64, - RustBuffer, - RustBuffer, - RustBuffer, - ctypes.POINTER(RustCallStatus), -) -_UniFFILib.uniffi_c2pa_fn_constructor_callbacksigner_new.restype = ctypes.c_void_p -_UniFFILib.uniffi_c2pa_fn_constructor_callbacksigner_new_from_signer.argtypes = ( ctypes.c_uint64, - RustBuffer, - ctypes.c_uint32, - ctypes.POINTER(RustCallStatus), + ctypes.POINTER(_UniffiRustCallStatus), ) -_UniFFILib.uniffi_c2pa_fn_constructor_callbacksigner_new_from_signer.restype = ctypes.c_void_p -_UniFFILib.uniffi_c2pa_fn_free_builder.argtypes = ( +_UniffiLib.uniffi_c2pa_fn_method_builder_sign.restype = _UniffiRustBuffer +_UniffiLib.uniffi_c2pa_fn_method_builder_sign_file.argtypes = ( ctypes.c_void_p, - ctypes.POINTER(RustCallStatus), -) -_UniFFILib.uniffi_c2pa_fn_free_builder.restype = None -_UniFFILib.uniffi_c2pa_fn_constructor_builder_new.argtypes = ( - ctypes.POINTER(RustCallStatus), + ctypes.c_void_p, + _UniffiRustBuffer, + _UniffiRustBuffer, + ctypes.POINTER(_UniffiRustCallStatus), ) -_UniFFILib.uniffi_c2pa_fn_constructor_builder_new.restype = ctypes.c_void_p -_UniFFILib.uniffi_c2pa_fn_method_builder_with_json.argtypes = ( +_UniffiLib.uniffi_c2pa_fn_method_builder_sign_file.restype = _UniffiRustBuffer +_UniffiLib.uniffi_c2pa_fn_method_builder_to_archive.argtypes = ( ctypes.c_void_p, - RustBuffer, - ctypes.POINTER(RustCallStatus), + ctypes.c_uint64, + ctypes.POINTER(_UniffiRustCallStatus), ) -_UniFFILib.uniffi_c2pa_fn_method_builder_with_json.restype = None -_UniFFILib.uniffi_c2pa_fn_method_builder_set_no_embed.argtypes = ( +_UniffiLib.uniffi_c2pa_fn_method_builder_to_archive.restype = None +_UniffiLib.uniffi_c2pa_fn_method_builder_with_json.argtypes = ( ctypes.c_void_p, - ctypes.POINTER(RustCallStatus), + _UniffiRustBuffer, + ctypes.POINTER(_UniffiRustCallStatus), ) -_UniFFILib.uniffi_c2pa_fn_method_builder_set_no_embed.restype = None -_UniFFILib.uniffi_c2pa_fn_method_builder_set_remote_url.argtypes = ( +_UniffiLib.uniffi_c2pa_fn_method_builder_with_json.restype = None +_UniffiLib.uniffi_c2pa_fn_clone_callbacksigner.argtypes = ( ctypes.c_void_p, - RustBuffer, - ctypes.POINTER(RustCallStatus), + ctypes.POINTER(_UniffiRustCallStatus), ) -_UniFFILib.uniffi_c2pa_fn_method_builder_set_remote_url.restype = None -_UniFFILib.uniffi_c2pa_fn_method_builder_add_resource.argtypes = ( +_UniffiLib.uniffi_c2pa_fn_clone_callbacksigner.restype = ctypes.c_void_p +_UniffiLib.uniffi_c2pa_fn_free_callbacksigner.argtypes = ( ctypes.c_void_p, - RustBuffer, + ctypes.POINTER(_UniffiRustCallStatus), +) +_UniffiLib.uniffi_c2pa_fn_free_callbacksigner.restype = None +_UniffiLib.uniffi_c2pa_fn_constructor_callbacksigner_new.argtypes = ( ctypes.c_uint64, - ctypes.POINTER(RustCallStatus), + _UniffiRustBuffer, + _UniffiRustBuffer, + _UniffiRustBuffer, + ctypes.POINTER(_UniffiRustCallStatus), ) -_UniFFILib.uniffi_c2pa_fn_method_builder_add_resource.restype = None -_UniFFILib.uniffi_c2pa_fn_method_builder_add_ingredient.argtypes = ( - ctypes.c_void_p, - RustBuffer, - RustBuffer, +_UniffiLib.uniffi_c2pa_fn_constructor_callbacksigner_new.restype = ctypes.c_void_p +_UniffiLib.uniffi_c2pa_fn_constructor_callbacksigner_new_from_signer.argtypes = ( ctypes.c_uint64, - ctypes.POINTER(RustCallStatus), + _UniffiRustBuffer, + ctypes.c_uint32, + ctypes.POINTER(_UniffiRustCallStatus), +) +_UniffiLib.uniffi_c2pa_fn_constructor_callbacksigner_new_from_signer.restype = ctypes.c_void_p +_UniffiLib.uniffi_c2pa_fn_clone_reader.argtypes = ( + ctypes.c_void_p, + ctypes.POINTER(_UniffiRustCallStatus), +) +_UniffiLib.uniffi_c2pa_fn_clone_reader.restype = ctypes.c_void_p +_UniffiLib.uniffi_c2pa_fn_free_reader.argtypes = ( + ctypes.c_void_p, + ctypes.POINTER(_UniffiRustCallStatus), +) +_UniffiLib.uniffi_c2pa_fn_free_reader.restype = None +_UniffiLib.uniffi_c2pa_fn_constructor_reader_new.argtypes = ( + ctypes.POINTER(_UniffiRustCallStatus), ) -_UniFFILib.uniffi_c2pa_fn_method_builder_add_ingredient.restype = None -_UniFFILib.uniffi_c2pa_fn_method_builder_to_archive.argtypes = ( +_UniffiLib.uniffi_c2pa_fn_constructor_reader_new.restype = ctypes.c_void_p +_UniffiLib.uniffi_c2pa_fn_method_reader_from_manifest_data_and_stream.argtypes = ( ctypes.c_void_p, + _UniffiRustBuffer, + _UniffiRustBuffer, ctypes.c_uint64, - ctypes.POINTER(RustCallStatus), + ctypes.POINTER(_UniffiRustCallStatus), ) -_UniFFILib.uniffi_c2pa_fn_method_builder_to_archive.restype = None -_UniFFILib.uniffi_c2pa_fn_method_builder_from_archive.argtypes = ( +_UniffiLib.uniffi_c2pa_fn_method_reader_from_manifest_data_and_stream.restype = _UniffiRustBuffer +_UniffiLib.uniffi_c2pa_fn_method_reader_from_stream.argtypes = ( ctypes.c_void_p, + _UniffiRustBuffer, ctypes.c_uint64, - ctypes.POINTER(RustCallStatus), + ctypes.POINTER(_UniffiRustCallStatus), ) -_UniFFILib.uniffi_c2pa_fn_method_builder_from_archive.restype = None -_UniFFILib.uniffi_c2pa_fn_method_builder_sign.argtypes = ( +_UniffiLib.uniffi_c2pa_fn_method_reader_from_stream.restype = _UniffiRustBuffer +_UniffiLib.uniffi_c2pa_fn_method_reader_json.argtypes = ( ctypes.c_void_p, + ctypes.POINTER(_UniffiRustCallStatus), +) +_UniffiLib.uniffi_c2pa_fn_method_reader_json.restype = _UniffiRustBuffer +_UniffiLib.uniffi_c2pa_fn_method_reader_resource_to_stream.argtypes = ( ctypes.c_void_p, - RustBuffer, + _UniffiRustBuffer, ctypes.c_uint64, + ctypes.POINTER(_UniffiRustCallStatus), +) +_UniffiLib.uniffi_c2pa_fn_method_reader_resource_to_stream.restype = ctypes.c_uint64 +_UniffiLib.uniffi_c2pa_fn_init_callback_vtable_signercallback.argtypes = ( + ctypes.POINTER(_UniffiVTableCallbackInterfaceSignerCallback), +) +_UniffiLib.uniffi_c2pa_fn_init_callback_vtable_signercallback.restype = None +_UniffiLib.uniffi_c2pa_fn_init_callback_vtable_stream.argtypes = ( + ctypes.POINTER(_UniffiVTableCallbackInterfaceStream), +) +_UniffiLib.uniffi_c2pa_fn_init_callback_vtable_stream.restype = None +_UniffiLib.uniffi_c2pa_fn_func_sdk_version.argtypes = ( + ctypes.POINTER(_UniffiRustCallStatus), +) +_UniffiLib.uniffi_c2pa_fn_func_sdk_version.restype = _UniffiRustBuffer +_UniffiLib.uniffi_c2pa_fn_func_version.argtypes = ( + ctypes.POINTER(_UniffiRustCallStatus), +) +_UniffiLib.uniffi_c2pa_fn_func_version.restype = _UniffiRustBuffer +_UniffiLib.ffi_c2pa_rustbuffer_alloc.argtypes = ( ctypes.c_uint64, - ctypes.POINTER(RustCallStatus), + ctypes.POINTER(_UniffiRustCallStatus), ) -_UniFFILib.uniffi_c2pa_fn_method_builder_sign.restype = RustBuffer -_UniFFILib.uniffi_c2pa_fn_method_builder_sign_file.argtypes = ( - ctypes.c_void_p, - ctypes.c_void_p, - RustBuffer, - RustBuffer, - ctypes.POINTER(RustCallStatus), +_UniffiLib.ffi_c2pa_rustbuffer_alloc.restype = _UniffiRustBuffer +_UniffiLib.ffi_c2pa_rustbuffer_from_bytes.argtypes = ( + _UniffiForeignBytes, + ctypes.POINTER(_UniffiRustCallStatus), +) +_UniffiLib.ffi_c2pa_rustbuffer_from_bytes.restype = _UniffiRustBuffer +_UniffiLib.ffi_c2pa_rustbuffer_free.argtypes = ( + _UniffiRustBuffer, + ctypes.POINTER(_UniffiRustCallStatus), +) +_UniffiLib.ffi_c2pa_rustbuffer_free.restype = None +_UniffiLib.ffi_c2pa_rustbuffer_reserve.argtypes = ( + _UniffiRustBuffer, + ctypes.c_uint64, + ctypes.POINTER(_UniffiRustCallStatus), +) +_UniffiLib.ffi_c2pa_rustbuffer_reserve.restype = _UniffiRustBuffer +_UniffiLib.ffi_c2pa_rust_future_poll_u8.argtypes = ( + ctypes.c_uint64, + _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK, + ctypes.c_uint64, +) +_UniffiLib.ffi_c2pa_rust_future_poll_u8.restype = None +_UniffiLib.ffi_c2pa_rust_future_cancel_u8.argtypes = ( + ctypes.c_uint64, +) +_UniffiLib.ffi_c2pa_rust_future_cancel_u8.restype = None +_UniffiLib.ffi_c2pa_rust_future_free_u8.argtypes = ( + ctypes.c_uint64, +) +_UniffiLib.ffi_c2pa_rust_future_free_u8.restype = None +_UniffiLib.ffi_c2pa_rust_future_complete_u8.argtypes = ( + ctypes.c_uint64, + ctypes.POINTER(_UniffiRustCallStatus), +) +_UniffiLib.ffi_c2pa_rust_future_complete_u8.restype = ctypes.c_uint8 +_UniffiLib.ffi_c2pa_rust_future_poll_i8.argtypes = ( + ctypes.c_uint64, + _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK, + ctypes.c_uint64, +) +_UniffiLib.ffi_c2pa_rust_future_poll_i8.restype = None +_UniffiLib.ffi_c2pa_rust_future_cancel_i8.argtypes = ( + ctypes.c_uint64, +) +_UniffiLib.ffi_c2pa_rust_future_cancel_i8.restype = None +_UniffiLib.ffi_c2pa_rust_future_free_i8.argtypes = ( + ctypes.c_uint64, +) +_UniffiLib.ffi_c2pa_rust_future_free_i8.restype = None +_UniffiLib.ffi_c2pa_rust_future_complete_i8.argtypes = ( + ctypes.c_uint64, + ctypes.POINTER(_UniffiRustCallStatus), +) +_UniffiLib.ffi_c2pa_rust_future_complete_i8.restype = ctypes.c_int8 +_UniffiLib.ffi_c2pa_rust_future_poll_u16.argtypes = ( + ctypes.c_uint64, + _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK, + ctypes.c_uint64, +) +_UniffiLib.ffi_c2pa_rust_future_poll_u16.restype = None +_UniffiLib.ffi_c2pa_rust_future_cancel_u16.argtypes = ( + ctypes.c_uint64, +) +_UniffiLib.ffi_c2pa_rust_future_cancel_u16.restype = None +_UniffiLib.ffi_c2pa_rust_future_free_u16.argtypes = ( + ctypes.c_uint64, +) +_UniffiLib.ffi_c2pa_rust_future_free_u16.restype = None +_UniffiLib.ffi_c2pa_rust_future_complete_u16.argtypes = ( + ctypes.c_uint64, + ctypes.POINTER(_UniffiRustCallStatus), +) +_UniffiLib.ffi_c2pa_rust_future_complete_u16.restype = ctypes.c_uint16 +_UniffiLib.ffi_c2pa_rust_future_poll_i16.argtypes = ( + ctypes.c_uint64, + _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK, + ctypes.c_uint64, +) +_UniffiLib.ffi_c2pa_rust_future_poll_i16.restype = None +_UniffiLib.ffi_c2pa_rust_future_cancel_i16.argtypes = ( + ctypes.c_uint64, +) +_UniffiLib.ffi_c2pa_rust_future_cancel_i16.restype = None +_UniffiLib.ffi_c2pa_rust_future_free_i16.argtypes = ( + ctypes.c_uint64, +) +_UniffiLib.ffi_c2pa_rust_future_free_i16.restype = None +_UniffiLib.ffi_c2pa_rust_future_complete_i16.argtypes = ( + ctypes.c_uint64, + ctypes.POINTER(_UniffiRustCallStatus), +) +_UniffiLib.ffi_c2pa_rust_future_complete_i16.restype = ctypes.c_int16 +_UniffiLib.ffi_c2pa_rust_future_poll_u32.argtypes = ( + ctypes.c_uint64, + _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK, + ctypes.c_uint64, +) +_UniffiLib.ffi_c2pa_rust_future_poll_u32.restype = None +_UniffiLib.ffi_c2pa_rust_future_cancel_u32.argtypes = ( + ctypes.c_uint64, +) +_UniffiLib.ffi_c2pa_rust_future_cancel_u32.restype = None +_UniffiLib.ffi_c2pa_rust_future_free_u32.argtypes = ( + ctypes.c_uint64, +) +_UniffiLib.ffi_c2pa_rust_future_free_u32.restype = None +_UniffiLib.ffi_c2pa_rust_future_complete_u32.argtypes = ( + ctypes.c_uint64, + ctypes.POINTER(_UniffiRustCallStatus), +) +_UniffiLib.ffi_c2pa_rust_future_complete_u32.restype = ctypes.c_uint32 +_UniffiLib.ffi_c2pa_rust_future_poll_i32.argtypes = ( + ctypes.c_uint64, + _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK, + ctypes.c_uint64, +) +_UniffiLib.ffi_c2pa_rust_future_poll_i32.restype = None +_UniffiLib.ffi_c2pa_rust_future_cancel_i32.argtypes = ( + ctypes.c_uint64, +) +_UniffiLib.ffi_c2pa_rust_future_cancel_i32.restype = None +_UniffiLib.ffi_c2pa_rust_future_free_i32.argtypes = ( + ctypes.c_uint64, +) +_UniffiLib.ffi_c2pa_rust_future_free_i32.restype = None +_UniffiLib.ffi_c2pa_rust_future_complete_i32.argtypes = ( + ctypes.c_uint64, + ctypes.POINTER(_UniffiRustCallStatus), +) +_UniffiLib.ffi_c2pa_rust_future_complete_i32.restype = ctypes.c_int32 +_UniffiLib.ffi_c2pa_rust_future_poll_u64.argtypes = ( + ctypes.c_uint64, + _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK, + ctypes.c_uint64, +) +_UniffiLib.ffi_c2pa_rust_future_poll_u64.restype = None +_UniffiLib.ffi_c2pa_rust_future_cancel_u64.argtypes = ( + ctypes.c_uint64, +) +_UniffiLib.ffi_c2pa_rust_future_cancel_u64.restype = None +_UniffiLib.ffi_c2pa_rust_future_free_u64.argtypes = ( + ctypes.c_uint64, +) +_UniffiLib.ffi_c2pa_rust_future_free_u64.restype = None +_UniffiLib.ffi_c2pa_rust_future_complete_u64.argtypes = ( + ctypes.c_uint64, + ctypes.POINTER(_UniffiRustCallStatus), +) +_UniffiLib.ffi_c2pa_rust_future_complete_u64.restype = ctypes.c_uint64 +_UniffiLib.ffi_c2pa_rust_future_poll_i64.argtypes = ( + ctypes.c_uint64, + _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK, + ctypes.c_uint64, +) +_UniffiLib.ffi_c2pa_rust_future_poll_i64.restype = None +_UniffiLib.ffi_c2pa_rust_future_cancel_i64.argtypes = ( + ctypes.c_uint64, +) +_UniffiLib.ffi_c2pa_rust_future_cancel_i64.restype = None +_UniffiLib.ffi_c2pa_rust_future_free_i64.argtypes = ( + ctypes.c_uint64, +) +_UniffiLib.ffi_c2pa_rust_future_free_i64.restype = None +_UniffiLib.ffi_c2pa_rust_future_complete_i64.argtypes = ( + ctypes.c_uint64, + ctypes.POINTER(_UniffiRustCallStatus), +) +_UniffiLib.ffi_c2pa_rust_future_complete_i64.restype = ctypes.c_int64 +_UniffiLib.ffi_c2pa_rust_future_poll_f32.argtypes = ( + ctypes.c_uint64, + _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK, + ctypes.c_uint64, +) +_UniffiLib.ffi_c2pa_rust_future_poll_f32.restype = None +_UniffiLib.ffi_c2pa_rust_future_cancel_f32.argtypes = ( + ctypes.c_uint64, +) +_UniffiLib.ffi_c2pa_rust_future_cancel_f32.restype = None +_UniffiLib.ffi_c2pa_rust_future_free_f32.argtypes = ( + ctypes.c_uint64, +) +_UniffiLib.ffi_c2pa_rust_future_free_f32.restype = None +_UniffiLib.ffi_c2pa_rust_future_complete_f32.argtypes = ( + ctypes.c_uint64, + ctypes.POINTER(_UniffiRustCallStatus), +) +_UniffiLib.ffi_c2pa_rust_future_complete_f32.restype = ctypes.c_float +_UniffiLib.ffi_c2pa_rust_future_poll_f64.argtypes = ( + ctypes.c_uint64, + _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK, + ctypes.c_uint64, +) +_UniffiLib.ffi_c2pa_rust_future_poll_f64.restype = None +_UniffiLib.ffi_c2pa_rust_future_cancel_f64.argtypes = ( + ctypes.c_uint64, +) +_UniffiLib.ffi_c2pa_rust_future_cancel_f64.restype = None +_UniffiLib.ffi_c2pa_rust_future_free_f64.argtypes = ( + ctypes.c_uint64, +) +_UniffiLib.ffi_c2pa_rust_future_free_f64.restype = None +_UniffiLib.ffi_c2pa_rust_future_complete_f64.argtypes = ( + ctypes.c_uint64, + ctypes.POINTER(_UniffiRustCallStatus), +) +_UniffiLib.ffi_c2pa_rust_future_complete_f64.restype = ctypes.c_double +_UniffiLib.ffi_c2pa_rust_future_poll_pointer.argtypes = ( + ctypes.c_uint64, + _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK, + ctypes.c_uint64, ) -_UniFFILib.uniffi_c2pa_fn_method_builder_sign_file.restype = RustBuffer -_UniFFILib.uniffi_c2pa_fn_init_callback_stream.argtypes = ( - FOREIGN_CALLBACK_T, - ctypes.POINTER(RustCallStatus), +_UniffiLib.ffi_c2pa_rust_future_poll_pointer.restype = None +_UniffiLib.ffi_c2pa_rust_future_cancel_pointer.argtypes = ( + ctypes.c_uint64, +) +_UniffiLib.ffi_c2pa_rust_future_cancel_pointer.restype = None +_UniffiLib.ffi_c2pa_rust_future_free_pointer.argtypes = ( + ctypes.c_uint64, +) +_UniffiLib.ffi_c2pa_rust_future_free_pointer.restype = None +_UniffiLib.ffi_c2pa_rust_future_complete_pointer.argtypes = ( + ctypes.c_uint64, + ctypes.POINTER(_UniffiRustCallStatus), ) -_UniFFILib.uniffi_c2pa_fn_init_callback_stream.restype = None -_UniFFILib.uniffi_c2pa_fn_init_callback_signercallback.argtypes = ( - FOREIGN_CALLBACK_T, - ctypes.POINTER(RustCallStatus), +_UniffiLib.ffi_c2pa_rust_future_complete_pointer.restype = ctypes.c_void_p +_UniffiLib.ffi_c2pa_rust_future_poll_rust_buffer.argtypes = ( + ctypes.c_uint64, + _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK, + ctypes.c_uint64, ) -_UniFFILib.uniffi_c2pa_fn_init_callback_signercallback.restype = None -_UniFFILib.uniffi_c2pa_fn_func_version.argtypes = ( - ctypes.POINTER(RustCallStatus), +_UniffiLib.ffi_c2pa_rust_future_poll_rust_buffer.restype = None +_UniffiLib.ffi_c2pa_rust_future_cancel_rust_buffer.argtypes = ( + ctypes.c_uint64, ) -_UniFFILib.uniffi_c2pa_fn_func_version.restype = RustBuffer -_UniFFILib.uniffi_c2pa_fn_func_sdk_version.argtypes = ( - ctypes.POINTER(RustCallStatus), +_UniffiLib.ffi_c2pa_rust_future_cancel_rust_buffer.restype = None +_UniffiLib.ffi_c2pa_rust_future_free_rust_buffer.argtypes = ( + ctypes.c_uint64, ) -_UniFFILib.uniffi_c2pa_fn_func_sdk_version.restype = RustBuffer -_UniFFILib.ffi_c2pa_rustbuffer_alloc.argtypes = ( - ctypes.c_int32, - ctypes.POINTER(RustCallStatus), +_UniffiLib.ffi_c2pa_rust_future_free_rust_buffer.restype = None +_UniffiLib.ffi_c2pa_rust_future_complete_rust_buffer.argtypes = ( + ctypes.c_uint64, + ctypes.POINTER(_UniffiRustCallStatus), +) +_UniffiLib.ffi_c2pa_rust_future_complete_rust_buffer.restype = _UniffiRustBuffer +_UniffiLib.ffi_c2pa_rust_future_poll_void.argtypes = ( + ctypes.c_uint64, + _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK, + ctypes.c_uint64, +) +_UniffiLib.ffi_c2pa_rust_future_poll_void.restype = None +_UniffiLib.ffi_c2pa_rust_future_cancel_void.argtypes = ( + ctypes.c_uint64, +) +_UniffiLib.ffi_c2pa_rust_future_cancel_void.restype = None +_UniffiLib.ffi_c2pa_rust_future_free_void.argtypes = ( + ctypes.c_uint64, +) +_UniffiLib.ffi_c2pa_rust_future_free_void.restype = None +_UniffiLib.ffi_c2pa_rust_future_complete_void.argtypes = ( + ctypes.c_uint64, + ctypes.POINTER(_UniffiRustCallStatus), ) -_UniFFILib.ffi_c2pa_rustbuffer_alloc.restype = RustBuffer -_UniFFILib.ffi_c2pa_rustbuffer_from_bytes.argtypes = ( - ForeignBytes, - ctypes.POINTER(RustCallStatus), +_UniffiLib.ffi_c2pa_rust_future_complete_void.restype = None +_UniffiLib.uniffi_c2pa_checksum_func_sdk_version.argtypes = ( ) -_UniFFILib.ffi_c2pa_rustbuffer_from_bytes.restype = RustBuffer -_UniFFILib.ffi_c2pa_rustbuffer_free.argtypes = ( - RustBuffer, - ctypes.POINTER(RustCallStatus), +_UniffiLib.uniffi_c2pa_checksum_func_sdk_version.restype = ctypes.c_uint16 +_UniffiLib.uniffi_c2pa_checksum_func_version.argtypes = ( ) -_UniFFILib.ffi_c2pa_rustbuffer_free.restype = None -_UniFFILib.ffi_c2pa_rustbuffer_reserve.argtypes = ( - RustBuffer, - ctypes.c_int32, - ctypes.POINTER(RustCallStatus), +_UniffiLib.uniffi_c2pa_checksum_func_version.restype = ctypes.c_uint16 +_UniffiLib.uniffi_c2pa_checksum_method_builder_add_ingredient.argtypes = ( ) -_UniFFILib.ffi_c2pa_rustbuffer_reserve.restype = RustBuffer -_UniFFILib.uniffi_c2pa_checksum_func_version.argtypes = ( +_UniffiLib.uniffi_c2pa_checksum_method_builder_add_ingredient.restype = ctypes.c_uint16 +_UniffiLib.uniffi_c2pa_checksum_method_builder_add_resource.argtypes = ( ) -_UniFFILib.uniffi_c2pa_checksum_func_version.restype = ctypes.c_uint16 -_UniFFILib.uniffi_c2pa_checksum_func_sdk_version.argtypes = ( +_UniffiLib.uniffi_c2pa_checksum_method_builder_add_resource.restype = ctypes.c_uint16 +_UniffiLib.uniffi_c2pa_checksum_method_builder_from_archive.argtypes = ( ) -_UniFFILib.uniffi_c2pa_checksum_func_sdk_version.restype = ctypes.c_uint16 -_UniFFILib.uniffi_c2pa_checksum_method_reader_from_stream.argtypes = ( +_UniffiLib.uniffi_c2pa_checksum_method_builder_from_archive.restype = ctypes.c_uint16 +_UniffiLib.uniffi_c2pa_checksum_method_builder_set_no_embed.argtypes = ( ) -_UniFFILib.uniffi_c2pa_checksum_method_reader_from_stream.restype = ctypes.c_uint16 -_UniFFILib.uniffi_c2pa_checksum_method_reader_from_manifest_data_and_stream.argtypes = ( +_UniffiLib.uniffi_c2pa_checksum_method_builder_set_no_embed.restype = ctypes.c_uint16 +_UniffiLib.uniffi_c2pa_checksum_method_builder_set_remote_url.argtypes = ( ) -_UniFFILib.uniffi_c2pa_checksum_method_reader_from_manifest_data_and_stream.restype = ctypes.c_uint16 -_UniFFILib.uniffi_c2pa_checksum_method_reader_json.argtypes = ( +_UniffiLib.uniffi_c2pa_checksum_method_builder_set_remote_url.restype = ctypes.c_uint16 +_UniffiLib.uniffi_c2pa_checksum_method_builder_sign.argtypes = ( ) -_UniFFILib.uniffi_c2pa_checksum_method_reader_json.restype = ctypes.c_uint16 -_UniFFILib.uniffi_c2pa_checksum_method_reader_resource_to_stream.argtypes = ( +_UniffiLib.uniffi_c2pa_checksum_method_builder_sign.restype = ctypes.c_uint16 +_UniffiLib.uniffi_c2pa_checksum_method_builder_sign_file.argtypes = ( ) -_UniFFILib.uniffi_c2pa_checksum_method_reader_resource_to_stream.restype = ctypes.c_uint16 -_UniFFILib.uniffi_c2pa_checksum_method_builder_with_json.argtypes = ( +_UniffiLib.uniffi_c2pa_checksum_method_builder_sign_file.restype = ctypes.c_uint16 +_UniffiLib.uniffi_c2pa_checksum_method_builder_to_archive.argtypes = ( ) -_UniFFILib.uniffi_c2pa_checksum_method_builder_with_json.restype = ctypes.c_uint16 -_UniFFILib.uniffi_c2pa_checksum_method_builder_set_no_embed.argtypes = ( +_UniffiLib.uniffi_c2pa_checksum_method_builder_to_archive.restype = ctypes.c_uint16 +_UniffiLib.uniffi_c2pa_checksum_method_builder_with_json.argtypes = ( ) -_UniFFILib.uniffi_c2pa_checksum_method_builder_set_no_embed.restype = ctypes.c_uint16 -_UniFFILib.uniffi_c2pa_checksum_method_builder_set_remote_url.argtypes = ( +_UniffiLib.uniffi_c2pa_checksum_method_builder_with_json.restype = ctypes.c_uint16 +_UniffiLib.uniffi_c2pa_checksum_method_reader_from_manifest_data_and_stream.argtypes = ( ) -_UniFFILib.uniffi_c2pa_checksum_method_builder_set_remote_url.restype = ctypes.c_uint16 -_UniFFILib.uniffi_c2pa_checksum_method_builder_add_resource.argtypes = ( +_UniffiLib.uniffi_c2pa_checksum_method_reader_from_manifest_data_and_stream.restype = ctypes.c_uint16 +_UniffiLib.uniffi_c2pa_checksum_method_reader_from_stream.argtypes = ( ) -_UniFFILib.uniffi_c2pa_checksum_method_builder_add_resource.restype = ctypes.c_uint16 -_UniFFILib.uniffi_c2pa_checksum_method_builder_add_ingredient.argtypes = ( +_UniffiLib.uniffi_c2pa_checksum_method_reader_from_stream.restype = ctypes.c_uint16 +_UniffiLib.uniffi_c2pa_checksum_method_reader_json.argtypes = ( ) -_UniFFILib.uniffi_c2pa_checksum_method_builder_add_ingredient.restype = ctypes.c_uint16 -_UniFFILib.uniffi_c2pa_checksum_method_builder_to_archive.argtypes = ( +_UniffiLib.uniffi_c2pa_checksum_method_reader_json.restype = ctypes.c_uint16 +_UniffiLib.uniffi_c2pa_checksum_method_reader_resource_to_stream.argtypes = ( ) -_UniFFILib.uniffi_c2pa_checksum_method_builder_to_archive.restype = ctypes.c_uint16 -_UniFFILib.uniffi_c2pa_checksum_method_builder_from_archive.argtypes = ( +_UniffiLib.uniffi_c2pa_checksum_method_reader_resource_to_stream.restype = ctypes.c_uint16 +_UniffiLib.uniffi_c2pa_checksum_constructor_builder_new.argtypes = ( ) -_UniFFILib.uniffi_c2pa_checksum_method_builder_from_archive.restype = ctypes.c_uint16 -_UniFFILib.uniffi_c2pa_checksum_method_builder_sign.argtypes = ( +_UniffiLib.uniffi_c2pa_checksum_constructor_builder_new.restype = ctypes.c_uint16 +_UniffiLib.uniffi_c2pa_checksum_constructor_callbacksigner_new.argtypes = ( ) -_UniFFILib.uniffi_c2pa_checksum_method_builder_sign.restype = ctypes.c_uint16 -_UniFFILib.uniffi_c2pa_checksum_method_builder_sign_file.argtypes = ( +_UniffiLib.uniffi_c2pa_checksum_constructor_callbacksigner_new.restype = ctypes.c_uint16 +_UniffiLib.uniffi_c2pa_checksum_constructor_callbacksigner_new_from_signer.argtypes = ( ) -_UniFFILib.uniffi_c2pa_checksum_method_builder_sign_file.restype = ctypes.c_uint16 -_UniFFILib.uniffi_c2pa_checksum_constructor_reader_new.argtypes = ( +_UniffiLib.uniffi_c2pa_checksum_constructor_callbacksigner_new_from_signer.restype = ctypes.c_uint16 +_UniffiLib.uniffi_c2pa_checksum_constructor_reader_new.argtypes = ( ) -_UniFFILib.uniffi_c2pa_checksum_constructor_reader_new.restype = ctypes.c_uint16 -_UniFFILib.uniffi_c2pa_checksum_constructor_callbacksigner_new.argtypes = ( +_UniffiLib.uniffi_c2pa_checksum_constructor_reader_new.restype = ctypes.c_uint16 +_UniffiLib.uniffi_c2pa_checksum_method_signercallback_sign.argtypes = ( ) -_UniFFILib.uniffi_c2pa_checksum_constructor_callbacksigner_new.restype = ctypes.c_uint16 -_UniFFILib.uniffi_c2pa_checksum_constructor_callbacksigner_new_from_signer.argtypes = ( +_UniffiLib.uniffi_c2pa_checksum_method_signercallback_sign.restype = ctypes.c_uint16 +_UniffiLib.uniffi_c2pa_checksum_method_stream_read_stream.argtypes = ( ) -_UniFFILib.uniffi_c2pa_checksum_constructor_callbacksigner_new_from_signer.restype = ctypes.c_uint16 -_UniFFILib.uniffi_c2pa_checksum_constructor_builder_new.argtypes = ( +_UniffiLib.uniffi_c2pa_checksum_method_stream_read_stream.restype = ctypes.c_uint16 +_UniffiLib.uniffi_c2pa_checksum_method_stream_seek_stream.argtypes = ( ) -_UniFFILib.uniffi_c2pa_checksum_constructor_builder_new.restype = ctypes.c_uint16 -_UniFFILib.ffi_c2pa_uniffi_contract_version.argtypes = ( +_UniffiLib.uniffi_c2pa_checksum_method_stream_seek_stream.restype = ctypes.c_uint16 +_UniffiLib.uniffi_c2pa_checksum_method_stream_write_stream.argtypes = ( ) -_UniFFILib.ffi_c2pa_uniffi_contract_version.restype = ctypes.c_uint32 -uniffi_check_contract_api_version(_UniFFILib) -uniffi_check_api_checksums(_UniFFILib) +_UniffiLib.uniffi_c2pa_checksum_method_stream_write_stream.restype = ctypes.c_uint16 +_UniffiLib.ffi_c2pa_uniffi_contract_version.argtypes = ( +) +_UniffiLib.ffi_c2pa_uniffi_contract_version.restype = ctypes.c_uint32 + +_uniffi_check_contract_api_version(_UniffiLib) +_uniffi_check_api_checksums(_UniffiLib) # Public interface members begin here. -class FfiConverterUInt32(FfiConverterPrimitiveInt): +class _UniffiConverterUInt32(_UniffiConverterPrimitiveInt): CLASS_NAME = "u32" VALUE_MIN = 0 VALUE_MAX = 2**32 @staticmethod def read(buf): - return buf.readU32() + return buf.read_u32() @staticmethod - def writeUnchecked(value, buf): - buf.writeU32(value) + def write(value, buf): + buf.write_u32(value) -class FfiConverterUInt64(FfiConverterPrimitiveInt): +class _UniffiConverterUInt64(_UniffiConverterPrimitiveInt): CLASS_NAME = "u64" VALUE_MIN = 0 VALUE_MAX = 2**64 @staticmethod def read(buf): - return buf.readU64() + return buf.read_u64() @staticmethod - def writeUnchecked(value, buf): - buf.writeU64(value) + def write(value, buf): + buf.write_u64(value) -class FfiConverterInt64(FfiConverterPrimitiveInt): +class _UniffiConverterInt64(_UniffiConverterPrimitiveInt): CLASS_NAME = "i64" VALUE_MIN = -2**63 VALUE_MAX = 2**63 @staticmethod def read(buf): - return buf.readI64() + return buf.read_i64() @staticmethod - def writeUnchecked(value, buf): - buf.writeI64(value) + def write(value, buf): + buf.write_i64(value) -class FfiConverterString: +class _UniffiConverterString: @staticmethod - def check(value): + def check_lower(value): if not isinstance(value, str): raise TypeError("argument must be str, not {}".format(type(value).__name__)) return value @staticmethod def read(buf): - size = buf.readI32() + size = buf.read_i32() if size < 0: raise InternalError("Unexpected negative string length") - utf8Bytes = buf.read(size) - return utf8Bytes.decode("utf-8") + utf8_bytes = buf.read(size) + return utf8_bytes.decode("utf-8") @staticmethod def write(value, buf): - value = FfiConverterString.check(value) - utf8Bytes = value.encode("utf-8") - buf.writeI32(len(utf8Bytes)) - buf.write(utf8Bytes) + utf8_bytes = value.encode("utf-8") + buf.write_i32(len(utf8_bytes)) + buf.write(utf8_bytes) @staticmethod def lift(buf): - with buf.consumeWithStream() as stream: + with buf.consume_with_stream() as stream: return stream.read(stream.remaining()).decode("utf-8") @staticmethod def lower(value): - value = FfiConverterString.check(value) - with RustBuffer.allocWithBuilder() as builder: + with _UniffiRustBuffer.alloc_with_builder() as builder: builder.write(value.encode("utf-8")) return builder.finalize() -class FfiConverterBytes(FfiConverterRustBuffer): +class _UniffiConverterBytes(_UniffiConverterRustBuffer): @staticmethod def read(buf): - size = buf.readI32() + size = buf.read_i32() if size < 0: raise InternalError("Unexpected negative byte string length") return buf.read(size) @staticmethod - def write(value, buf): + def check_lower(value): try: memoryview(value) except TypeError: raise TypeError("a bytes-like object is required, not {!r}".format(type(value).__name__)) - buf.writeI32(len(value)) + + @staticmethod + def write(value, buf): + buf.write_i32(len(value)) buf.write(value) +class BuilderProtocol(typing.Protocol): + def add_ingredient(self, ingredient_json: "str",format: "str",stream: "Stream"): + raise NotImplementedError + def add_resource(self, uri: "str",stream: "Stream"): + raise NotImplementedError + def from_archive(self, stream: "Stream"): + raise NotImplementedError + def set_no_embed(self, ): + raise NotImplementedError + def set_remote_url(self, url: "str"): + raise NotImplementedError + def sign(self, signer: "CallbackSigner",format: "str",input: "Stream",output: "Stream"): + raise NotImplementedError + def sign_file(self, signer: "CallbackSigner",input: "str",output: "str"): + raise NotImplementedError + def to_archive(self, stream: "Stream"): + raise NotImplementedError + def with_json(self, json: "str"): + raise NotImplementedError + + class Builder: _pointer: ctypes.c_void_p def __init__(self, ): - self._pointer = rust_call(_UniFFILib.uniffi_c2pa_fn_constructor_builder_new,) + self._pointer = _uniffi_rust_call(_UniffiLib.uniffi_c2pa_fn_constructor_builder_new,) def __del__(self): # In case of partial initialization of instances. pointer = getattr(self, "_pointer", None) if pointer is not None: - rust_call(_UniFFILib.uniffi_c2pa_fn_free_builder, pointer) + _uniffi_rust_call(_UniffiLib.uniffi_c2pa_fn_free_builder, pointer) + + def _uniffi_clone_pointer(self): + return _uniffi_rust_call(_UniffiLib.uniffi_c2pa_fn_clone_builder, self._pointer) # Used by alternative constructors or any methods which return this type. @classmethod @@ -909,88 +1278,61 @@ def _make_instance_(cls, pointer): return inst - def with_json(self, json: "str"): + def add_ingredient(self, ingredient_json: "str",format: "str",stream: "Stream") -> None: + _UniffiConverterString.check_lower(ingredient_json) - rust_call_with_error( - FfiConverterTypeError,_UniFFILib.uniffi_c2pa_fn_method_builder_with_json,self._pointer, - FfiConverterString.lower(json)) - - - - - - - - def set_no_embed(self, ): - rust_call_with_error( - FfiConverterTypeError,_UniFFILib.uniffi_c2pa_fn_method_builder_set_no_embed,self._pointer,) - - - - - - - - def set_remote_url(self, url: "str"): + _UniffiConverterString.check_lower(format) - rust_call_with_error( - FfiConverterTypeError,_UniFFILib.uniffi_c2pa_fn_method_builder_set_remote_url,self._pointer, - FfiConverterString.lower(url)) - + _UniffiConverterCallbackInterfaceStream.check_lower(stream) + + _uniffi_rust_call_with_error(_UniffiConverterTypeError,_UniffiLib.uniffi_c2pa_fn_method_builder_add_ingredient,self._uniffi_clone_pointer(), + _UniffiConverterString.lower(ingredient_json), + _UniffiConverterString.lower(format), + _UniffiConverterCallbackInterfaceStream.lower(stream)) - def add_resource(self, uri: "str",stream: "Stream"): + def add_resource(self, uri: "str",stream: "Stream") -> None: + _UniffiConverterString.check_lower(uri) + _UniffiConverterCallbackInterfaceStream.check_lower(stream) - rust_call_with_error( - FfiConverterTypeError,_UniFFILib.uniffi_c2pa_fn_method_builder_add_resource,self._pointer, - FfiConverterString.lower(uri), - FfiConverterCallbackInterfaceStream.lower(stream)) - - - + _uniffi_rust_call_with_error(_UniffiConverterTypeError,_UniffiLib.uniffi_c2pa_fn_method_builder_add_resource,self._uniffi_clone_pointer(), + _UniffiConverterString.lower(uri), + _UniffiConverterCallbackInterfaceStream.lower(stream)) - def add_ingredient(self, ingredient_json: "str",format: "str",stream: "Stream"): - - - - rust_call_with_error( - FfiConverterTypeError,_UniFFILib.uniffi_c2pa_fn_method_builder_add_ingredient,self._pointer, - FfiConverterString.lower(ingredient_json), - FfiConverterString.lower(format), - FfiConverterCallbackInterfaceStream.lower(stream)) + def from_archive(self, stream: "Stream") -> None: + _UniffiConverterCallbackInterfaceStream.check_lower(stream) + + _uniffi_rust_call_with_error(_UniffiConverterTypeError,_UniffiLib.uniffi_c2pa_fn_method_builder_from_archive,self._uniffi_clone_pointer(), + _UniffiConverterCallbackInterfaceStream.lower(stream)) - def to_archive(self, stream: "Stream"): - - rust_call_with_error( - FfiConverterTypeError,_UniFFILib.uniffi_c2pa_fn_method_builder_to_archive,self._pointer, - FfiConverterCallbackInterfaceStream.lower(stream)) + def set_no_embed(self, ) -> None: + _uniffi_rust_call_with_error(_UniffiConverterTypeError,_UniffiLib.uniffi_c2pa_fn_method_builder_set_no_embed,self._uniffi_clone_pointer(),) - def from_archive(self, stream: "Stream"): + def set_remote_url(self, url: "str") -> None: + _UniffiConverterString.check_lower(url) - rust_call_with_error( - FfiConverterTypeError,_UniFFILib.uniffi_c2pa_fn_method_builder_from_archive,self._pointer, - FfiConverterCallbackInterfaceStream.lower(stream)) - + _uniffi_rust_call_with_error(_UniffiConverterTypeError,_UniffiLib.uniffi_c2pa_fn_method_builder_set_remote_url,self._uniffi_clone_pointer(), + _UniffiConverterString.lower(url)) @@ -998,83 +1340,126 @@ def from_archive(self, stream: "Stream"): def sign(self, signer: "CallbackSigner",format: "str",input: "Stream",output: "Stream") -> "bytes": + _UniffiConverterTypeCallbackSigner.check_lower(signer) + _UniffiConverterString.check_lower(format) + _UniffiConverterCallbackInterfaceStream.check_lower(input) + _UniffiConverterCallbackInterfaceStream.check_lower(output) - return FfiConverterBytes.lift( - rust_call_with_error( - FfiConverterTypeError,_UniFFILib.uniffi_c2pa_fn_method_builder_sign,self._pointer, - FfiConverterTypeCallbackSigner.lower(signer), - FfiConverterString.lower(format), - FfiConverterCallbackInterfaceStream.lower(input), - FfiConverterCallbackInterfaceStream.lower(output)) + return _UniffiConverterBytes.lift( + _uniffi_rust_call_with_error(_UniffiConverterTypeError,_UniffiLib.uniffi_c2pa_fn_method_builder_sign,self._uniffi_clone_pointer(), + _UniffiConverterTypeCallbackSigner.lower(signer), + _UniffiConverterString.lower(format), + _UniffiConverterCallbackInterfaceStream.lower(input), + _UniffiConverterCallbackInterfaceStream.lower(output)) ) - def sign_file(self, signer: "CallbackSigner",input: "str",output: "str") -> "bytes": + _UniffiConverterTypeCallbackSigner.check_lower(signer) + _UniffiConverterString.check_lower(input) + _UniffiConverterString.check_lower(output) - return FfiConverterBytes.lift( - rust_call_with_error( - FfiConverterTypeError,_UniFFILib.uniffi_c2pa_fn_method_builder_sign_file,self._pointer, - FfiConverterTypeCallbackSigner.lower(signer), - FfiConverterString.lower(input), - FfiConverterString.lower(output)) + return _UniffiConverterBytes.lift( + _uniffi_rust_call_with_error(_UniffiConverterTypeError,_UniffiLib.uniffi_c2pa_fn_method_builder_sign_file,self._uniffi_clone_pointer(), + _UniffiConverterTypeCallbackSigner.lower(signer), + _UniffiConverterString.lower(input), + _UniffiConverterString.lower(output)) ) + def to_archive(self, stream: "Stream") -> None: + _UniffiConverterCallbackInterfaceStream.check_lower(stream) + + _uniffi_rust_call_with_error(_UniffiConverterTypeError,_UniffiLib.uniffi_c2pa_fn_method_builder_to_archive,self._uniffi_clone_pointer(), + _UniffiConverterCallbackInterfaceStream.lower(stream)) + + + + + + + def with_json(self, json: "str") -> None: + _UniffiConverterString.check_lower(json) + + _uniffi_rust_call_with_error(_UniffiConverterTypeError,_UniffiLib.uniffi_c2pa_fn_method_builder_with_json,self._uniffi_clone_pointer(), + _UniffiConverterString.lower(json)) + + + + + + + +class _UniffiConverterTypeBuilder: + + @staticmethod + def lift(value: int): + return Builder._make_instance_(value) + + @staticmethod + def check_lower(value: Builder): + if not isinstance(value, Builder): + raise TypeError("Expected Builder instance, {} found".format(type(value).__name__)) + + @staticmethod + def lower(value: BuilderProtocol): + if not isinstance(value, Builder): + raise TypeError("Expected Builder instance, {} found".format(type(value).__name__)) + return value._uniffi_clone_pointer() -class FfiConverterTypeBuilder: @classmethod - def read(cls, buf): - ptr = buf.readU64() + def read(cls, buf: _UniffiRustBuffer): + ptr = buf.read_u64() if ptr == 0: raise InternalError("Raw pointer value was null") return cls.lift(ptr) @classmethod - def write(cls, value, buf): - if not isinstance(value, Builder): - raise TypeError("Expected Builder instance, {} found".format(value.__class__.__name__)) - buf.writeU64(cls.lower(value)) + def write(cls, value: BuilderProtocol, buf: _UniffiRustBuffer): + buf.write_u64(cls.lower(value)) - @staticmethod - def lift(value): - return Builder._make_instance_(value) - @staticmethod - def lower(value): - return value._pointer +class CallbackSignerProtocol(typing.Protocol): + pass class CallbackSigner: _pointer: ctypes.c_void_p def __init__(self, callback: "SignerCallback",alg: "SigningAlg",certs: "bytes",ta_url: "typing.Optional[str]"): + _UniffiConverterCallbackInterfaceSignerCallback.check_lower(callback) + _UniffiConverterTypeSigningAlg.check_lower(alg) + _UniffiConverterBytes.check_lower(certs) + _UniffiConverterOptionalString.check_lower(ta_url) - self._pointer = rust_call(_UniFFILib.uniffi_c2pa_fn_constructor_callbacksigner_new, - FfiConverterCallbackInterfaceSignerCallback.lower(callback), - FfiConverterTypeSigningAlg.lower(alg), - FfiConverterBytes.lower(certs), - FfiConverterOptionalString.lower(ta_url)) + self._pointer = _uniffi_rust_call(_UniffiLib.uniffi_c2pa_fn_constructor_callbacksigner_new, + _UniffiConverterCallbackInterfaceSignerCallback.lower(callback), + _UniffiConverterTypeSigningAlg.lower(alg), + _UniffiConverterBytes.lower(certs), + _UniffiConverterOptionalString.lower(ta_url)) def __del__(self): # In case of partial initialization of instances. pointer = getattr(self, "_pointer", None) if pointer is not None: - rust_call(_UniFFILib.uniffi_c2pa_fn_free_callbacksigner, pointer) + _uniffi_rust_call(_UniffiLib.uniffi_c2pa_fn_free_callbacksigner, pointer) + + def _uniffi_clone_pointer(self): + return _uniffi_rust_call(_UniffiLib.uniffi_c2pa_fn_clone_callbacksigner, self._pointer) # Used by alternative constructors or any methods which return this type. @classmethod @@ -1087,52 +1472,76 @@ def _make_instance_(cls, pointer): @classmethod def new_from_signer(cls, callback: "SignerCallback",alg: "SigningAlg",reserve_size: "int"): + _UniffiConverterCallbackInterfaceSignerCallback.check_lower(callback) + _UniffiConverterTypeSigningAlg.check_lower(alg) + _UniffiConverterUInt32.check_lower(reserve_size) # Call the (fallible) function before creating any half-baked object instances. - pointer = rust_call(_UniFFILib.uniffi_c2pa_fn_constructor_callbacksigner_new_from_signer, - FfiConverterCallbackInterfaceSignerCallback.lower(callback), - FfiConverterTypeSigningAlg.lower(alg), - FfiConverterUInt32.lower(reserve_size)) + pointer = _uniffi_rust_call(_UniffiLib.uniffi_c2pa_fn_constructor_callbacksigner_new_from_signer, + _UniffiConverterCallbackInterfaceSignerCallback.lower(callback), + _UniffiConverterTypeSigningAlg.lower(alg), + _UniffiConverterUInt32.lower(reserve_size)) return cls._make_instance_(pointer) -class FfiConverterTypeCallbackSigner: + +class _UniffiConverterTypeCallbackSigner: + + @staticmethod + def lift(value: int): + return CallbackSigner._make_instance_(value) + + @staticmethod + def check_lower(value: CallbackSigner): + if not isinstance(value, CallbackSigner): + raise TypeError("Expected CallbackSigner instance, {} found".format(type(value).__name__)) + + @staticmethod + def lower(value: CallbackSignerProtocol): + if not isinstance(value, CallbackSigner): + raise TypeError("Expected CallbackSigner instance, {} found".format(type(value).__name__)) + return value._uniffi_clone_pointer() + @classmethod - def read(cls, buf): - ptr = buf.readU64() + def read(cls, buf: _UniffiRustBuffer): + ptr = buf.read_u64() if ptr == 0: raise InternalError("Raw pointer value was null") return cls.lift(ptr) @classmethod - def write(cls, value, buf): - if not isinstance(value, CallbackSigner): - raise TypeError("Expected CallbackSigner instance, {} found".format(value.__class__.__name__)) - buf.writeU64(cls.lower(value)) + def write(cls, value: CallbackSignerProtocol, buf: _UniffiRustBuffer): + buf.write_u64(cls.lower(value)) - @staticmethod - def lift(value): - return CallbackSigner._make_instance_(value) - @staticmethod - def lower(value): - return value._pointer +class ReaderProtocol(typing.Protocol): + def from_manifest_data_and_stream(self, manifest_data: "bytes",format: "str",reader: "Stream"): + raise NotImplementedError + def from_stream(self, format: "str",reader: "Stream"): + raise NotImplementedError + def json(self, ): + raise NotImplementedError + def resource_to_stream(self, uri: "str",stream: "Stream"): + raise NotImplementedError class Reader: _pointer: ctypes.c_void_p def __init__(self, ): - self._pointer = rust_call(_UniFFILib.uniffi_c2pa_fn_constructor_reader_new,) + self._pointer = _uniffi_rust_call(_UniffiLib.uniffi_c2pa_fn_constructor_reader_new,) def __del__(self): # In case of partial initialization of instances. pointer = getattr(self, "_pointer", None) if pointer is not None: - rust_call(_UniFFILib.uniffi_c2pa_fn_free_reader, pointer) + _uniffi_rust_call(_UniffiLib.uniffi_c2pa_fn_free_reader, pointer) + + def _uniffi_clone_pointer(self): + return _uniffi_rust_call(_UniffiLib.uniffi_c2pa_fn_clone_reader, self._pointer) # Used by alternative constructors or any methods which return this type. @classmethod @@ -1144,57 +1553,57 @@ def _make_instance_(cls, pointer): return inst - def from_stream(self, format: "str",reader: "Stream") -> "str": + def from_manifest_data_and_stream(self, manifest_data: "bytes",format: "str",reader: "Stream") -> "str": + _UniffiConverterBytes.check_lower(manifest_data) + _UniffiConverterString.check_lower(format) - return FfiConverterString.lift( - rust_call_with_error( - FfiConverterTypeError,_UniFFILib.uniffi_c2pa_fn_method_reader_from_stream,self._pointer, - FfiConverterString.lower(format), - FfiConverterCallbackInterfaceStream.lower(reader)) + _UniffiConverterCallbackInterfaceStream.check_lower(reader) + + return _UniffiConverterString.lift( + _uniffi_rust_call_with_error(_UniffiConverterTypeError,_UniffiLib.uniffi_c2pa_fn_method_reader_from_manifest_data_and_stream,self._uniffi_clone_pointer(), + _UniffiConverterBytes.lower(manifest_data), + _UniffiConverterString.lower(format), + _UniffiConverterCallbackInterfaceStream.lower(reader)) ) - - def from_manifest_data_and_stream(self, manifest_data: "bytes",format: "str",reader: "Stream") -> "str": - + def from_stream(self, format: "str",reader: "Stream") -> "str": + _UniffiConverterString.check_lower(format) + _UniffiConverterCallbackInterfaceStream.check_lower(reader) - return FfiConverterString.lift( - rust_call_with_error( - FfiConverterTypeError,_UniFFILib.uniffi_c2pa_fn_method_reader_from_manifest_data_and_stream,self._pointer, - FfiConverterBytes.lower(manifest_data), - FfiConverterString.lower(format), - FfiConverterCallbackInterfaceStream.lower(reader)) + return _UniffiConverterString.lift( + _uniffi_rust_call_with_error(_UniffiConverterTypeError,_UniffiLib.uniffi_c2pa_fn_method_reader_from_stream,self._uniffi_clone_pointer(), + _UniffiConverterString.lower(format), + _UniffiConverterCallbackInterfaceStream.lower(reader)) ) - def json(self, ) -> "str": - return FfiConverterString.lift( - rust_call_with_error( - FfiConverterTypeError,_UniFFILib.uniffi_c2pa_fn_method_reader_json,self._pointer,) + return _UniffiConverterString.lift( + _uniffi_rust_call_with_error(_UniffiConverterTypeError,_UniffiLib.uniffi_c2pa_fn_method_reader_json,self._uniffi_clone_pointer(),) ) - def resource_to_stream(self, uri: "str",stream: "Stream") -> "int": + _UniffiConverterString.check_lower(uri) + _UniffiConverterCallbackInterfaceStream.check_lower(stream) - return FfiConverterUInt64.lift( - rust_call_with_error( - FfiConverterTypeError,_UniFFILib.uniffi_c2pa_fn_method_reader_resource_to_stream,self._pointer, - FfiConverterString.lower(uri), - FfiConverterCallbackInterfaceStream.lower(stream)) + return _UniffiConverterUInt64.lift( + _uniffi_rust_call_with_error(_UniffiConverterTypeError,_UniffiLib.uniffi_c2pa_fn_method_reader_resource_to_stream,self._uniffi_clone_pointer(), + _UniffiConverterString.lower(uri), + _UniffiConverterCallbackInterfaceStream.lower(stream)) ) @@ -1202,27 +1611,33 @@ def resource_to_stream(self, uri: "str",stream: "Stream") -> "int": -class FfiConverterTypeReader: +class _UniffiConverterTypeReader: + + @staticmethod + def lift(value: int): + return Reader._make_instance_(value) + + @staticmethod + def check_lower(value: Reader): + if not isinstance(value, Reader): + raise TypeError("Expected Reader instance, {} found".format(type(value).__name__)) + + @staticmethod + def lower(value: ReaderProtocol): + if not isinstance(value, Reader): + raise TypeError("Expected Reader instance, {} found".format(type(value).__name__)) + return value._uniffi_clone_pointer() + @classmethod - def read(cls, buf): - ptr = buf.readU64() + def read(cls, buf: _UniffiRustBuffer): + ptr = buf.read_u64() if ptr == 0: raise InternalError("Raw pointer value was null") return cls.lift(ptr) @classmethod - def write(cls, value, buf): - if not isinstance(value, Reader): - raise TypeError("Expected Reader instance, {} found".format(value.__class__.__name__)) - buf.writeU64(cls.lower(value)) - - @staticmethod - def lift(value): - return Reader._make_instance_(value) - - @staticmethod - def lower(value): - return value._pointer + def write(cls, value: ReaderProtocol, buf: _UniffiRustBuffer): + buf.write_u64(cls.lower(value)) # Error @@ -1234,289 +1649,357 @@ def lower(value): class Error(Exception): pass -UniFFITempError = Error +_UniffiTempError = Error class Error: # type: ignore - class Assertion(UniFFITempError): + class Assertion(_UniffiTempError): def __init__(self, reason): super().__init__(", ".join([ "reason={!r}".format(reason), ])) self.reason = reason + def __repr__(self): return "Error.Assertion({})".format(str(self)) - UniFFITempError.Assertion = Assertion # type: ignore - class AssertionNotFound(UniFFITempError): + _UniffiTempError.Assertion = Assertion # type: ignore + class AssertionNotFound(_UniffiTempError): def __init__(self, reason): super().__init__(", ".join([ "reason={!r}".format(reason), ])) self.reason = reason + def __repr__(self): return "Error.AssertionNotFound({})".format(str(self)) - UniFFITempError.AssertionNotFound = AssertionNotFound # type: ignore - class Decoding(UniFFITempError): + _UniffiTempError.AssertionNotFound = AssertionNotFound # type: ignore + class Decoding(_UniffiTempError): def __init__(self, reason): super().__init__(", ".join([ "reason={!r}".format(reason), ])) self.reason = reason + def __repr__(self): return "Error.Decoding({})".format(str(self)) - UniFFITempError.Decoding = Decoding # type: ignore - class Encoding(UniFFITempError): + _UniffiTempError.Decoding = Decoding # type: ignore + class Encoding(_UniffiTempError): def __init__(self, reason): super().__init__(", ".join([ "reason={!r}".format(reason), ])) self.reason = reason + def __repr__(self): return "Error.Encoding({})".format(str(self)) - UniFFITempError.Encoding = Encoding # type: ignore - class FileNotFound(UniFFITempError): + _UniffiTempError.Encoding = Encoding # type: ignore + class FileNotFound(_UniffiTempError): def __init__(self, reason): super().__init__(", ".join([ "reason={!r}".format(reason), ])) self.reason = reason + def __repr__(self): return "Error.FileNotFound({})".format(str(self)) - UniFFITempError.FileNotFound = FileNotFound # type: ignore - class Io(UniFFITempError): + _UniffiTempError.FileNotFound = FileNotFound # type: ignore + class Io(_UniffiTempError): def __init__(self, reason): super().__init__(", ".join([ "reason={!r}".format(reason), ])) self.reason = reason + def __repr__(self): return "Error.Io({})".format(str(self)) - UniFFITempError.Io = Io # type: ignore - class Json(UniFFITempError): + _UniffiTempError.Io = Io # type: ignore + class Json(_UniffiTempError): def __init__(self, reason): super().__init__(", ".join([ "reason={!r}".format(reason), ])) self.reason = reason + def __repr__(self): return "Error.Json({})".format(str(self)) - UniFFITempError.Json = Json # type: ignore - class Manifest(UniFFITempError): + _UniffiTempError.Json = Json # type: ignore + class Manifest(_UniffiTempError): def __init__(self, reason): super().__init__(", ".join([ "reason={!r}".format(reason), ])) self.reason = reason + def __repr__(self): return "Error.Manifest({})".format(str(self)) - UniFFITempError.Manifest = Manifest # type: ignore - class ManifestNotFound(UniFFITempError): + _UniffiTempError.Manifest = Manifest # type: ignore + class ManifestNotFound(_UniffiTempError): def __init__(self, reason): super().__init__(", ".join([ "reason={!r}".format(reason), ])) self.reason = reason + def __repr__(self): return "Error.ManifestNotFound({})".format(str(self)) - UniFFITempError.ManifestNotFound = ManifestNotFound # type: ignore - class NotSupported(UniFFITempError): + _UniffiTempError.ManifestNotFound = ManifestNotFound # type: ignore + class NotSupported(_UniffiTempError): def __init__(self, reason): super().__init__(", ".join([ "reason={!r}".format(reason), ])) self.reason = reason + def __repr__(self): return "Error.NotSupported({})".format(str(self)) - UniFFITempError.NotSupported = NotSupported # type: ignore - class Other(UniFFITempError): + _UniffiTempError.NotSupported = NotSupported # type: ignore + class Other(_UniffiTempError): def __init__(self, reason): super().__init__(", ".join([ "reason={!r}".format(reason), ])) self.reason = reason + def __repr__(self): return "Error.Other({})".format(str(self)) - UniFFITempError.Other = Other # type: ignore - class RemoteManifest(UniFFITempError): + _UniffiTempError.Other = Other # type: ignore + class RemoteManifest(_UniffiTempError): def __init__(self, reason): super().__init__(", ".join([ "reason={!r}".format(reason), ])) self.reason = reason + def __repr__(self): return "Error.RemoteManifest({})".format(str(self)) - UniFFITempError.RemoteManifest = RemoteManifest # type: ignore - class ResourceNotFound(UniFFITempError): + _UniffiTempError.RemoteManifest = RemoteManifest # type: ignore + class ResourceNotFound(_UniffiTempError): def __init__(self, reason): super().__init__(", ".join([ "reason={!r}".format(reason), ])) self.reason = reason + def __repr__(self): return "Error.ResourceNotFound({})".format(str(self)) - UniFFITempError.ResourceNotFound = ResourceNotFound # type: ignore - class RwLock(UniFFITempError): + _UniffiTempError.ResourceNotFound = ResourceNotFound # type: ignore + class RwLock(_UniffiTempError): def __init__(self): pass + def __repr__(self): return "Error.RwLock({})".format(str(self)) - UniFFITempError.RwLock = RwLock # type: ignore - class Signature(UniFFITempError): + _UniffiTempError.RwLock = RwLock # type: ignore + class Signature(_UniffiTempError): def __init__(self, reason): super().__init__(", ".join([ "reason={!r}".format(reason), ])) self.reason = reason + def __repr__(self): return "Error.Signature({})".format(str(self)) - UniFFITempError.Signature = Signature # type: ignore - class Verify(UniFFITempError): + _UniffiTempError.Signature = Signature # type: ignore + class Verify(_UniffiTempError): def __init__(self, reason): super().__init__(", ".join([ "reason={!r}".format(reason), ])) self.reason = reason + def __repr__(self): return "Error.Verify({})".format(str(self)) - UniFFITempError.Verify = Verify # type: ignore + _UniffiTempError.Verify = Verify # type: ignore -Error = UniFFITempError # type: ignore -del UniFFITempError +Error = _UniffiTempError # type: ignore +del _UniffiTempError -class FfiConverterTypeError(FfiConverterRustBuffer): +class _UniffiConverterTypeError(_UniffiConverterRustBuffer): @staticmethod def read(buf): - variant = buf.readI32() + variant = buf.read_i32() if variant == 1: return Error.Assertion( - reason=FfiConverterString.read(buf), + _UniffiConverterString.read(buf), ) if variant == 2: return Error.AssertionNotFound( - reason=FfiConverterString.read(buf), + _UniffiConverterString.read(buf), ) if variant == 3: return Error.Decoding( - reason=FfiConverterString.read(buf), + _UniffiConverterString.read(buf), ) if variant == 4: return Error.Encoding( - reason=FfiConverterString.read(buf), + _UniffiConverterString.read(buf), ) if variant == 5: return Error.FileNotFound( - reason=FfiConverterString.read(buf), + _UniffiConverterString.read(buf), ) if variant == 6: return Error.Io( - reason=FfiConverterString.read(buf), + _UniffiConverterString.read(buf), ) if variant == 7: return Error.Json( - reason=FfiConverterString.read(buf), + _UniffiConverterString.read(buf), ) if variant == 8: return Error.Manifest( - reason=FfiConverterString.read(buf), + _UniffiConverterString.read(buf), ) if variant == 9: return Error.ManifestNotFound( - reason=FfiConverterString.read(buf), + _UniffiConverterString.read(buf), ) if variant == 10: return Error.NotSupported( - reason=FfiConverterString.read(buf), + _UniffiConverterString.read(buf), ) if variant == 11: return Error.Other( - reason=FfiConverterString.read(buf), + _UniffiConverterString.read(buf), ) if variant == 12: return Error.RemoteManifest( - reason=FfiConverterString.read(buf), + _UniffiConverterString.read(buf), ) if variant == 13: return Error.ResourceNotFound( - reason=FfiConverterString.read(buf), + _UniffiConverterString.read(buf), ) if variant == 14: return Error.RwLock( ) if variant == 15: return Error.Signature( - reason=FfiConverterString.read(buf), + _UniffiConverterString.read(buf), ) if variant == 16: return Error.Verify( - reason=FfiConverterString.read(buf), + _UniffiConverterString.read(buf), ) raise InternalError("Raw enum value doesn't match any cases") + @staticmethod + def check_lower(value): + if isinstance(value, Error.Assertion): + _UniffiConverterString.check_lower(value.reason) + return + if isinstance(value, Error.AssertionNotFound): + _UniffiConverterString.check_lower(value.reason) + return + if isinstance(value, Error.Decoding): + _UniffiConverterString.check_lower(value.reason) + return + if isinstance(value, Error.Encoding): + _UniffiConverterString.check_lower(value.reason) + return + if isinstance(value, Error.FileNotFound): + _UniffiConverterString.check_lower(value.reason) + return + if isinstance(value, Error.Io): + _UniffiConverterString.check_lower(value.reason) + return + if isinstance(value, Error.Json): + _UniffiConverterString.check_lower(value.reason) + return + if isinstance(value, Error.Manifest): + _UniffiConverterString.check_lower(value.reason) + return + if isinstance(value, Error.ManifestNotFound): + _UniffiConverterString.check_lower(value.reason) + return + if isinstance(value, Error.NotSupported): + _UniffiConverterString.check_lower(value.reason) + return + if isinstance(value, Error.Other): + _UniffiConverterString.check_lower(value.reason) + return + if isinstance(value, Error.RemoteManifest): + _UniffiConverterString.check_lower(value.reason) + return + if isinstance(value, Error.ResourceNotFound): + _UniffiConverterString.check_lower(value.reason) + return + if isinstance(value, Error.RwLock): + return + if isinstance(value, Error.Signature): + _UniffiConverterString.check_lower(value.reason) + return + if isinstance(value, Error.Verify): + _UniffiConverterString.check_lower(value.reason) + return + @staticmethod def write(value, buf): if isinstance(value, Error.Assertion): - buf.writeI32(1) - FfiConverterString.write(value.reason, buf) + buf.write_i32(1) + _UniffiConverterString.write(value.reason, buf) if isinstance(value, Error.AssertionNotFound): - buf.writeI32(2) - FfiConverterString.write(value.reason, buf) + buf.write_i32(2) + _UniffiConverterString.write(value.reason, buf) if isinstance(value, Error.Decoding): - buf.writeI32(3) - FfiConverterString.write(value.reason, buf) + buf.write_i32(3) + _UniffiConverterString.write(value.reason, buf) if isinstance(value, Error.Encoding): - buf.writeI32(4) - FfiConverterString.write(value.reason, buf) + buf.write_i32(4) + _UniffiConverterString.write(value.reason, buf) if isinstance(value, Error.FileNotFound): - buf.writeI32(5) - FfiConverterString.write(value.reason, buf) + buf.write_i32(5) + _UniffiConverterString.write(value.reason, buf) if isinstance(value, Error.Io): - buf.writeI32(6) - FfiConverterString.write(value.reason, buf) + buf.write_i32(6) + _UniffiConverterString.write(value.reason, buf) if isinstance(value, Error.Json): - buf.writeI32(7) - FfiConverterString.write(value.reason, buf) + buf.write_i32(7) + _UniffiConverterString.write(value.reason, buf) if isinstance(value, Error.Manifest): - buf.writeI32(8) - FfiConverterString.write(value.reason, buf) + buf.write_i32(8) + _UniffiConverterString.write(value.reason, buf) if isinstance(value, Error.ManifestNotFound): - buf.writeI32(9) - FfiConverterString.write(value.reason, buf) + buf.write_i32(9) + _UniffiConverterString.write(value.reason, buf) if isinstance(value, Error.NotSupported): - buf.writeI32(10) - FfiConverterString.write(value.reason, buf) + buf.write_i32(10) + _UniffiConverterString.write(value.reason, buf) if isinstance(value, Error.Other): - buf.writeI32(11) - FfiConverterString.write(value.reason, buf) + buf.write_i32(11) + _UniffiConverterString.write(value.reason, buf) if isinstance(value, Error.RemoteManifest): - buf.writeI32(12) - FfiConverterString.write(value.reason, buf) + buf.write_i32(12) + _UniffiConverterString.write(value.reason, buf) if isinstance(value, Error.ResourceNotFound): - buf.writeI32(13) - FfiConverterString.write(value.reason, buf) + buf.write_i32(13) + _UniffiConverterString.write(value.reason, buf) if isinstance(value, Error.RwLock): - buf.writeI32(14) + buf.write_i32(14) if isinstance(value, Error.Signature): - buf.writeI32(15) - FfiConverterString.write(value.reason, buf) + buf.write_i32(15) + _UniffiConverterString.write(value.reason, buf) if isinstance(value, Error.Verify): - buf.writeI32(16) - FfiConverterString.write(value.reason, buf) + buf.write_i32(16) + _UniffiConverterString.write(value.reason, buf) class SeekMode(enum.Enum): - START = 1 - END = 2 - CURRENT = 3 + START = 0 + + END = 1 + + CURRENT = 2 -class FfiConverterTypeSeekMode(FfiConverterRustBuffer): +class _UniffiConverterTypeSeekMode(_UniffiConverterRustBuffer): @staticmethod def read(buf): - variant = buf.readI32() + variant = buf.read_i32() if variant == 1: return SeekMode.START if variant == 2: @@ -1525,13 +2008,25 @@ def read(buf): return SeekMode.CURRENT raise InternalError("Raw enum value doesn't match any cases") + @staticmethod + def check_lower(value): + if value == SeekMode.START: + return + if value == SeekMode.END: + return + if value == SeekMode.CURRENT: + return + raise ValueError(value) + + @staticmethod def write(value, buf): if value == SeekMode.START: - buf.writeI32(1) + buf.write_i32(1) if value == SeekMode.END: - buf.writeI32(2) + buf.write_i32(2) if value == SeekMode.CURRENT: - buf.writeI32(3) + buf.write_i32(3) + @@ -1539,20 +2034,26 @@ def write(value, buf): class SigningAlg(enum.Enum): - ES256 = 1 - ES384 = 2 - ES512 = 3 - PS256 = 4 - PS384 = 5 - PS512 = 6 - ED25519 = 7 + ES256 = 0 + + ES384 = 1 + + ES512 = 2 + + PS256 = 3 + + PS384 = 4 + + PS512 = 5 + + ED25519 = 6 -class FfiConverterTypeSigningAlg(FfiConverterRustBuffer): +class _UniffiConverterTypeSigningAlg(_UniffiConverterRustBuffer): @staticmethod def read(buf): - variant = buf.readI32() + variant = buf.read_i32() if variant == 1: return SigningAlg.ES256 if variant == 2: @@ -1569,94 +2070,72 @@ def read(buf): return SigningAlg.ED25519 raise InternalError("Raw enum value doesn't match any cases") - def write(value, buf): + @staticmethod + def check_lower(value): if value == SigningAlg.ES256: - buf.writeI32(1) + return if value == SigningAlg.ES384: - buf.writeI32(2) + return if value == SigningAlg.ES512: - buf.writeI32(3) + return if value == SigningAlg.PS256: - buf.writeI32(4) + return if value == SigningAlg.PS384: - buf.writeI32(5) + return if value == SigningAlg.PS512: - buf.writeI32(6) + return if value == SigningAlg.ED25519: - buf.writeI32(7) - - - - -import threading - -class ConcurrentHandleMap: - """ - A map where inserting, getting and removing data is synchronized with a lock. - """ - - def __init__(self): - # type Handle = int - self._left_map = {} # type: Dict[Handle, Any] - self._right_map = {} # type: Dict[Any, Handle] + return + raise ValueError(value) - self._lock = threading.Lock() - self._current_handle = 0 - self._stride = 1 + @staticmethod + def write(value, buf): + if value == SigningAlg.ES256: + buf.write_i32(1) + if value == SigningAlg.ES384: + buf.write_i32(2) + if value == SigningAlg.ES512: + buf.write_i32(3) + if value == SigningAlg.PS256: + buf.write_i32(4) + if value == SigningAlg.PS384: + buf.write_i32(5) + if value == SigningAlg.PS512: + buf.write_i32(6) + if value == SigningAlg.ED25519: + buf.write_i32(7) - def insert(self, obj): - with self._lock: - if obj in self._right_map: - return self._right_map[obj] - else: - handle = self._current_handle - self._current_handle += self._stride - self._left_map[handle] = obj - self._right_map[obj] = handle - return handle - def get(self, handle): - with self._lock: - return self._left_map.get(handle) - def remove(self, handle): - with self._lock: - if handle in self._left_map: - obj = self._left_map.pop(handle) - del self._right_map[obj] - return obj +class SignerCallback(typing.Protocol): + def sign(self, data: "bytes"): + raise NotImplementedError # Magic number for the Rust proxy to call using the same mechanism as every other method, # to free the callback once it's dropped by Rust. -IDX_CALLBACK_FREE = 0 +_UNIFFI_IDX_CALLBACK_FREE = 0 # Return codes for callback calls -UNIFFI_CALLBACK_SUCCESS = 0 -UNIFFI_CALLBACK_ERROR = 1 -UNIFFI_CALLBACK_UNEXPECTED_ERROR = 2 - -class FfiConverterCallbackInterface: - _handle_map = ConcurrentHandleMap() +_UNIFFI_CALLBACK_SUCCESS = 0 +_UNIFFI_CALLBACK_ERROR = 1 +_UNIFFI_CALLBACK_UNEXPECTED_ERROR = 2 - def __init__(self, cb): - self._foreign_callback = cb - - def drop(self, handle): - self.__class__._handle_map.remove(handle) +class _UniffiCallbackInterfaceFfiConverter: + _handle_map = _UniffiHandleMap() @classmethod def lift(cls, handle): - obj = cls._handle_map.get(handle) - if not obj: - raise InternalError("The object in the handle map has been dropped already") - - return obj + return cls._handle_map.get(handle) @classmethod def read(cls, buf): - handle = buf.readU64() + handle = buf.read_u64() cls.lift(handle) + @classmethod + def check_lower(cls, cb): + pass + @classmethod def lower(cls, cb): handle = cls._handle_map.insert(cb) @@ -1664,269 +2143,193 @@ def lower(cls, cb): @classmethod def write(cls, cb, buf): - buf.writeU64(cls.lower(cb)) - -# Declaration and FfiConverters for SignerCallback Callback Interface - -class SignerCallback: - def sign(self, data: "bytes"): - raise NotImplementedError - - - -def py_foreignCallbackCallbackInterfaceSignerCallback(handle, method, args_data, args_len, buf_ptr): - - def invoke_sign(python_callback, args_stream, buf_ptr): - def makeCall():return python_callback.sign( - FfiConverterBytes.read(args_stream) - ) - - def makeCallAndHandleReturn(): - rval = makeCall() - with RustBuffer.allocWithBuilder() as builder: - FfiConverterBytes.write(rval, builder) - buf_ptr[0] = builder.finalize() - return UNIFFI_CALLBACK_SUCCESS - try: - return makeCallAndHandleReturn() - except Error as e: - # Catch errors declared in the UDL file - with RustBuffer.allocWithBuilder() as builder: - FfiConverterTypeError.write(e, builder) - buf_ptr[0] = builder.finalize() - return UNIFFI_CALLBACK_ERROR - - - - cb = FfiConverterCallbackInterfaceSignerCallback.lift(handle) - if not cb: - raise InternalError("No callback in handlemap; this is a Uniffi bug") - - if method == IDX_CALLBACK_FREE: - FfiConverterCallbackInterfaceSignerCallback.drop(handle) - # Successfull return - # See docs of ForeignCallback in `uniffi_core/src/ffi/foreigncallbacks.rs` - return UNIFFI_CALLBACK_SUCCESS + buf.write_u64(cls.lower(cb)) + +# Put all the bits inside a class to keep the top-level namespace clean +class _UniffiTraitImplSignerCallback: + # For each method, generate a callback function to pass to Rust + + @_UNIFFI_CALLBACK_INTERFACE_SIGNER_CALLBACK_METHOD0 + def sign( + uniffi_handle, + data, + uniffi_out_return, + uniffi_call_status_ptr, + ): + uniffi_obj = _UniffiConverterCallbackInterfaceSignerCallback._handle_map.get(uniffi_handle) + def make_call(): + args = (_UniffiConverterBytes.lift(data), ) + method = uniffi_obj.sign + return method(*args) - if method == 1: - # Call the method and handle any errors - # See docs of ForeignCallback in `uniffi_core/src/ffi/foreigncallbacks.rs` for details - try: - return invoke_sign(cb, RustBufferStream(args_data, args_len), buf_ptr) - except BaseException as e: - # Catch unexpected errors - try: - # Try to serialize the exception into a String - buf_ptr[0] = FfiConverterString.lower(repr(e)) - except: - # If that fails, just give up - pass - return UNIFFI_CALLBACK_UNEXPECTED_ERROR - - - # This should never happen, because an out of bounds method index won't - # ever be used. Once we can catch errors, we should return an InternalException. - # https://github.com/mozilla/uniffi-rs/issues/351 - - # An unexpected error happened. - # See docs of ForeignCallback in `uniffi_core/src/ffi/foreigncallbacks.rs` - return UNIFFI_CALLBACK_UNEXPECTED_ERROR - -# We need to keep this function reference alive: -# if they get GC'd while in use then UniFFI internals could attempt to call a function -# that is in freed memory. -# That would be...uh...bad. Yeah, that's the word. Bad. -foreignCallbackCallbackInterfaceSignerCallback = FOREIGN_CALLBACK_T(py_foreignCallbackCallbackInterfaceSignerCallback) -rust_call(lambda err: _UniFFILib.uniffi_c2pa_fn_init_callback_signercallback(foreignCallbackCallbackInterfaceSignerCallback, err)) - -# The FfiConverter which transforms the Callbacks in to Handles to pass to Rust. -FfiConverterCallbackInterfaceSignerCallback = FfiConverterCallbackInterface(foreignCallbackCallbackInterfaceSignerCallback) + + def write_return_value(v): + uniffi_out_return[0] = _UniffiConverterBytes.lower(v) + _uniffi_trait_interface_call_with_error( + uniffi_call_status_ptr.contents, + make_call, + write_return_value, + Error, + _UniffiConverterTypeError.lower, + ) + @_UNIFFI_CALLBACK_INTERFACE_FREE + def _uniffi_free(uniffi_handle): + _UniffiConverterCallbackInterfaceSignerCallback._handle_map.remove(uniffi_handle) + # Generate the FFI VTable. This has a field for each callback interface method. + _uniffi_vtable = _UniffiVTableCallbackInterfaceSignerCallback( + sign, + _uniffi_free + ) + # Send Rust a pointer to the VTable. Note: this means we need to keep the struct alive forever, + # or else bad things will happen when Rust tries to access it. + _UniffiLib.uniffi_c2pa_fn_init_callback_vtable_signercallback(ctypes.byref(_uniffi_vtable)) +# The _UniffiConverter which transforms the Callbacks in to Handles to pass to Rust. +_UniffiConverterCallbackInterfaceSignerCallback = _UniffiCallbackInterfaceFfiConverter() -# Declaration and FfiConverters for Stream Callback Interface -class Stream: +class Stream(typing.Protocol): def read_stream(self, length: "int"): raise NotImplementedError - def seek_stream(self, pos: "int",mode: "SeekMode"): raise NotImplementedError - def write_stream(self, data: "bytes"): raise NotImplementedError - -def py_foreignCallbackCallbackInterfaceStream(handle, method, args_data, args_len, buf_ptr): - - def invoke_read_stream(python_callback, args_stream, buf_ptr): - def makeCall():return python_callback.read_stream( - FfiConverterUInt64.read(args_stream) - ) - - def makeCallAndHandleReturn(): - rval = makeCall() - with RustBuffer.allocWithBuilder() as builder: - FfiConverterBytes.write(rval, builder) - buf_ptr[0] = builder.finalize() - return UNIFFI_CALLBACK_SUCCESS - try: - return makeCallAndHandleReturn() - except Error as e: - # Catch errors declared in the UDL file - with RustBuffer.allocWithBuilder() as builder: - FfiConverterTypeError.write(e, builder) - buf_ptr[0] = builder.finalize() - return UNIFFI_CALLBACK_ERROR +# Put all the bits inside a class to keep the top-level namespace clean +class _UniffiTraitImplStream: + # For each method, generate a callback function to pass to Rust - - def invoke_seek_stream(python_callback, args_stream, buf_ptr): - def makeCall():return python_callback.seek_stream( - FfiConverterInt64.read(args_stream), - FfiConverterTypeSeekMode.read(args_stream) - ) - - def makeCallAndHandleReturn(): - rval = makeCall() - with RustBuffer.allocWithBuilder() as builder: - FfiConverterUInt64.write(rval, builder) - buf_ptr[0] = builder.finalize() - return UNIFFI_CALLBACK_SUCCESS - try: - return makeCallAndHandleReturn() - except Error as e: - # Catch errors declared in the UDL file - with RustBuffer.allocWithBuilder() as builder: - FfiConverterTypeError.write(e, builder) - buf_ptr[0] = builder.finalize() - return UNIFFI_CALLBACK_ERROR + @_UNIFFI_CALLBACK_INTERFACE_STREAM_METHOD0 + def read_stream( + uniffi_handle, + length, + uniffi_out_return, + uniffi_call_status_ptr, + ): + uniffi_obj = _UniffiConverterCallbackInterfaceStream._handle_map.get(uniffi_handle) + def make_call(): + args = (_UniffiConverterUInt64.lift(length), ) + method = uniffi_obj.read_stream + return method(*args) - - def invoke_write_stream(python_callback, args_stream, buf_ptr): - def makeCall():return python_callback.write_stream( - FfiConverterBytes.read(args_stream) - ) - - def makeCallAndHandleReturn(): - rval = makeCall() - with RustBuffer.allocWithBuilder() as builder: - FfiConverterUInt64.write(rval, builder) - buf_ptr[0] = builder.finalize() - return UNIFFI_CALLBACK_SUCCESS - try: - return makeCallAndHandleReturn() - except Error as e: - # Catch errors declared in the UDL file - with RustBuffer.allocWithBuilder() as builder: - FfiConverterTypeError.write(e, builder) - buf_ptr[0] = builder.finalize() - return UNIFFI_CALLBACK_ERROR + + def write_return_value(v): + uniffi_out_return[0] = _UniffiConverterBytes.lower(v) + _uniffi_trait_interface_call_with_error( + uniffi_call_status_ptr.contents, + make_call, + write_return_value, + Error, + _UniffiConverterTypeError.lower, + ) - + @_UNIFFI_CALLBACK_INTERFACE_STREAM_METHOD1 + def seek_stream( + uniffi_handle, + pos, + mode, + uniffi_out_return, + uniffi_call_status_ptr, + ): + uniffi_obj = _UniffiConverterCallbackInterfaceStream._handle_map.get(uniffi_handle) + def make_call(): + args = (_UniffiConverterInt64.lift(pos), _UniffiConverterTypeSeekMode.lift(mode), ) + method = uniffi_obj.seek_stream + return method(*args) - cb = FfiConverterCallbackInterfaceStream.lift(handle) - if not cb: - raise InternalError("No callback in handlemap; this is a Uniffi bug") + + def write_return_value(v): + uniffi_out_return[0] = _UniffiConverterUInt64.lower(v) + _uniffi_trait_interface_call_with_error( + uniffi_call_status_ptr.contents, + make_call, + write_return_value, + Error, + _UniffiConverterTypeError.lower, + ) - if method == IDX_CALLBACK_FREE: - FfiConverterCallbackInterfaceStream.drop(handle) - # Successfull return - # See docs of ForeignCallback in `uniffi_core/src/ffi/foreigncallbacks.rs` - return UNIFFI_CALLBACK_SUCCESS + @_UNIFFI_CALLBACK_INTERFACE_STREAM_METHOD2 + def write_stream( + uniffi_handle, + data, + uniffi_out_return, + uniffi_call_status_ptr, + ): + uniffi_obj = _UniffiConverterCallbackInterfaceStream._handle_map.get(uniffi_handle) + def make_call(): + args = (_UniffiConverterBytes.lift(data), ) + method = uniffi_obj.write_stream + return method(*args) - if method == 1: - # Call the method and handle any errors - # See docs of ForeignCallback in `uniffi_core/src/ffi/foreigncallbacks.rs` for details - try: - return invoke_read_stream(cb, RustBufferStream(args_data, args_len), buf_ptr) - except BaseException as e: - # Catch unexpected errors - try: - # Try to serialize the exception into a String - buf_ptr[0] = FfiConverterString.lower(repr(e)) - except: - # If that fails, just give up - pass - return UNIFFI_CALLBACK_UNEXPECTED_ERROR - if method == 2: - # Call the method and handle any errors - # See docs of ForeignCallback in `uniffi_core/src/ffi/foreigncallbacks.rs` for details - try: - return invoke_seek_stream(cb, RustBufferStream(args_data, args_len), buf_ptr) - except BaseException as e: - # Catch unexpected errors - try: - # Try to serialize the exception into a String - buf_ptr[0] = FfiConverterString.lower(repr(e)) - except: - # If that fails, just give up - pass - return UNIFFI_CALLBACK_UNEXPECTED_ERROR - if method == 3: - # Call the method and handle any errors - # See docs of ForeignCallback in `uniffi_core/src/ffi/foreigncallbacks.rs` for details - try: - return invoke_write_stream(cb, RustBufferStream(args_data, args_len), buf_ptr) - except BaseException as e: - # Catch unexpected errors - try: - # Try to serialize the exception into a String - buf_ptr[0] = FfiConverterString.lower(repr(e)) - except: - # If that fails, just give up - pass - return UNIFFI_CALLBACK_UNEXPECTED_ERROR - + + def write_return_value(v): + uniffi_out_return[0] = _UniffiConverterUInt64.lower(v) + _uniffi_trait_interface_call_with_error( + uniffi_call_status_ptr.contents, + make_call, + write_return_value, + Error, + _UniffiConverterTypeError.lower, + ) - # This should never happen, because an out of bounds method index won't - # ever be used. Once we can catch errors, we should return an InternalException. - # https://github.com/mozilla/uniffi-rs/issues/351 + @_UNIFFI_CALLBACK_INTERFACE_FREE + def _uniffi_free(uniffi_handle): + _UniffiConverterCallbackInterfaceStream._handle_map.remove(uniffi_handle) - # An unexpected error happened. - # See docs of ForeignCallback in `uniffi_core/src/ffi/foreigncallbacks.rs` - return UNIFFI_CALLBACK_UNEXPECTED_ERROR + # Generate the FFI VTable. This has a field for each callback interface method. + _uniffi_vtable = _UniffiVTableCallbackInterfaceStream( + read_stream, + seek_stream, + write_stream, + _uniffi_free + ) + # Send Rust a pointer to the VTable. Note: this means we need to keep the struct alive forever, + # or else bad things will happen when Rust tries to access it. + _UniffiLib.uniffi_c2pa_fn_init_callback_vtable_stream(ctypes.byref(_uniffi_vtable)) -# We need to keep this function reference alive: -# if they get GC'd while in use then UniFFI internals could attempt to call a function -# that is in freed memory. -# That would be...uh...bad. Yeah, that's the word. Bad. -foreignCallbackCallbackInterfaceStream = FOREIGN_CALLBACK_T(py_foreignCallbackCallbackInterfaceStream) -rust_call(lambda err: _UniFFILib.uniffi_c2pa_fn_init_callback_stream(foreignCallbackCallbackInterfaceStream, err)) +# The _UniffiConverter which transforms the Callbacks in to Handles to pass to Rust. +_UniffiConverterCallbackInterfaceStream = _UniffiCallbackInterfaceFfiConverter() -# The FfiConverter which transforms the Callbacks in to Handles to pass to Rust. -FfiConverterCallbackInterfaceStream = FfiConverterCallbackInterface(foreignCallbackCallbackInterfaceStream) +class _UniffiConverterOptionalString(_UniffiConverterRustBuffer): + @classmethod + def check_lower(cls, value): + if value is not None: + _UniffiConverterString.check_lower(value) -class FfiConverterOptionalString(FfiConverterRustBuffer): @classmethod def write(cls, value, buf): if value is None: - buf.writeU8(0) + buf.write_u8(0) return - buf.writeU8(1) - FfiConverterString.write(value, buf) + buf.write_u8(1) + _UniffiConverterString.write(value, buf) @classmethod def read(cls, buf): - flag = buf.readU8() + flag = buf.read_u8() if flag == 0: return None elif flag == 1: - return FfiConverterString.read(buf) + return _UniffiConverterString.read(buf) else: raise InternalError("Unexpected flag byte for optional type") -def version(): - return FfiConverterString.lift(rust_call(_UniFFILib.uniffi_c2pa_fn_func_version,)) +# Async support + +def sdk_version() -> "str": + return _UniffiConverterString.lift(_uniffi_rust_call(_UniffiLib.uniffi_c2pa_fn_func_sdk_version,)) -def sdk_version(): - return FfiConverterString.lift(rust_call(_UniFFILib.uniffi_c2pa_fn_func_sdk_version,)) +def version() -> "str": + return _UniffiConverterString.lift(_uniffi_rust_call(_UniffiLib.uniffi_c2pa_fn_func_version,)) __all__ = [ @@ -1934,12 +2337,12 @@ def sdk_version(): "Error", "SeekMode", "SigningAlg", - "version", "sdk_version", - "Reader", - "CallbackSigner", + "version", "Builder", - "Stream", + "CallbackSigner", + "Reader", "SignerCallback", + "Stream", ] diff --git a/requirements.txt b/requirements.txt index f21244b1..c4f07d43 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ maturin==1.7.4 -uniffi-bindgen==0.24.1 +uniffi-bindgen==0.28.0 cryptography==43.0.1 \ No newline at end of file From 7be48a89c1e36dbf6ebeb8228f73dfd055e884df Mon Sep 17 00:00:00 2001 From: Tania Mathern Date: Wed, 13 Nov 2024 21:45:04 -0800 Subject: [PATCH 06/25] up --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e63710a0..59cfd34f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,9 +19,9 @@ serde = { version = "1.0.197", features = ["derive"] } serde_derive = "1.0" serde_json = "1.0" thiserror = "1.0.49" -uniffi = "0.24.1" +uniffi = "0.28.2" openssl-src = "=300.3.1" # Required for openssl-sys log = "0.4.21" [build-dependencies] -uniffi = { version = "0.24.1", features = ["build"] } +uniffi = { version = "0.28.2", features = ["build"] } From 688d8df099ae12b31cc8abc7817064dde92ee2f6 Mon Sep 17 00:00:00 2001 From: Tania Mathern Date: Wed, 13 Nov 2024 21:50:05 -0800 Subject: [PATCH 07/25] WIP --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 2d57e7bd..e96924b6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ requires = ["maturin>=1.7.4,<2.0","uniffi_bindgen>=0.24,<0.25"] build-backend = "maturin" [project] -name = "c2pa-python" +name = "c2pa_python" dependencies = ["cffi"] requires-python = ">=3.7" description = "Python bindings for the C2PA Content Authenticity Initiative (CAI) library" From 93890d5deed9be11b52ce67fc6b2d08a92915424 Mon Sep 17 00:00:00 2001 From: Tania Mathern Date: Wed, 13 Nov 2024 21:51:51 -0800 Subject: [PATCH 08/25] WIP --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 59cfd34f..d8f44ee6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,8 +6,8 @@ authors = ["Gavin Peacock Date: Wed, 13 Nov 2024 22:16:12 -0800 Subject: [PATCH 09/25] Revert name changes --- Cargo.toml | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d8f44ee6..7de7353f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ authors = ["Gavin Peacock =1.7.4,<2.0","uniffi_bindgen>=0.24,<0.25"] build-backend = "maturin" [project] -name = "c2pa_python" +name = "c2pa" dependencies = ["cffi"] requires-python = ">=3.7" description = "Python bindings for the C2PA Content Authenticity Initiative (CAI) library" From e255033d5afa63ac11a536adbbc7b749ffd960ce Mon Sep 17 00:00:00 2001 From: Tania Mathern Date: Wed, 13 Nov 2024 22:34:32 -0800 Subject: [PATCH 10/25] WIP --- Makefile | 10 - c2pa/c2pa/.gitkeep | 0 c2pa/c2pa/__init__.py | 1 - c2pa/c2pa/c2pa.py | 2348 ----------------------------------------- 4 files changed, 2359 deletions(-) create mode 100644 c2pa/c2pa/.gitkeep delete mode 100644 c2pa/c2pa/__init__.py delete mode 100644 c2pa/c2pa/c2pa.py diff --git a/Makefile b/Makefile index ad116932..fbd5bb41 100644 --- a/Makefile +++ b/Makefile @@ -8,13 +8,3 @@ build-python: release python3 -m pip install -r requirements.txt python3 -m pip install -r requirements-dev.txt maturin develop - -# Pre-requisite: Python virtual environment is active (source .venv/bin/activate) -python-redeploy: release - maturin develop - -# Pre-requisite: Python virtual environment is active (source .venv/bin/activate) -python-test: - python3 -m pip install -r requirements-dev.txt - python3 -m pip install -U c2pa-python - python3 ./tests/test_api.py \ No newline at end of file diff --git a/c2pa/c2pa/.gitkeep b/c2pa/c2pa/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/c2pa/c2pa/__init__.py b/c2pa/c2pa/__init__.py deleted file mode 100644 index fb73f71e..00000000 --- a/c2pa/c2pa/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .c2pa import * # NOQA diff --git a/c2pa/c2pa/c2pa.py b/c2pa/c2pa/c2pa.py deleted file mode 100644 index 44d755b0..00000000 --- a/c2pa/c2pa/c2pa.py +++ /dev/null @@ -1,2348 +0,0 @@ - - -# This file was autogenerated by some hot garbage in the `uniffi` crate. -# Trust me, you don't want to mess with it! - -# Common helper code. -# -# Ideally this would live in a separate .py file where it can be unittested etc -# in isolation, and perhaps even published as a re-useable package. -# -# However, it's important that the details of how this helper code works (e.g. the -# way that different builtin types are passed across the FFI) exactly match what's -# expected by the rust code on the other side of the interface. In practice right -# now that means coming from the exact some version of `uniffi` that was used to -# compile the rust component. The easiest way to ensure this is to bundle the Python -# helpers directly inline like we're doing here. - -from __future__ import annotations -import os -import sys -import ctypes -import enum -import struct -import contextlib -import datetime -import threading -import itertools -import traceback -import typing -import platform - -# Used for default argument values -_DEFAULT = object() # type: typing.Any - - -class _UniffiRustBuffer(ctypes.Structure): - _fields_ = [ - ("capacity", ctypes.c_uint64), - ("len", ctypes.c_uint64), - ("data", ctypes.POINTER(ctypes.c_char)), - ] - - @staticmethod - def default(): - return _UniffiRustBuffer(0, 0, None) - - @staticmethod - def alloc(size): - return _uniffi_rust_call(_UniffiLib.ffi_c2pa_rustbuffer_alloc, size) - - @staticmethod - def reserve(rbuf, additional): - return _uniffi_rust_call(_UniffiLib.ffi_c2pa_rustbuffer_reserve, rbuf, additional) - - def free(self): - return _uniffi_rust_call(_UniffiLib.ffi_c2pa_rustbuffer_free, self) - - def __str__(self): - return "_UniffiRustBuffer(capacity={}, len={}, data={})".format( - self.capacity, - self.len, - self.data[0:self.len] - ) - - @contextlib.contextmanager - def alloc_with_builder(*args): - """Context-manger to allocate a buffer using a _UniffiRustBufferBuilder. - - The allocated buffer will be automatically freed if an error occurs, ensuring that - we don't accidentally leak it. - """ - builder = _UniffiRustBufferBuilder() - try: - yield builder - except: - builder.discard() - raise - - @contextlib.contextmanager - def consume_with_stream(self): - """Context-manager to consume a buffer using a _UniffiRustBufferStream. - - The _UniffiRustBuffer will be freed once the context-manager exits, ensuring that we don't - leak it even if an error occurs. - """ - try: - s = _UniffiRustBufferStream.from_rust_buffer(self) - yield s - if s.remaining() != 0: - raise RuntimeError("junk data left in buffer at end of consume_with_stream") - finally: - self.free() - - @contextlib.contextmanager - def read_with_stream(self): - """Context-manager to read a buffer using a _UniffiRustBufferStream. - - This is like consume_with_stream, but doesn't free the buffer afterwards. - It should only be used with borrowed `_UniffiRustBuffer` data. - """ - s = _UniffiRustBufferStream.from_rust_buffer(self) - yield s - if s.remaining() != 0: - raise RuntimeError("junk data left in buffer at end of read_with_stream") - -class _UniffiForeignBytes(ctypes.Structure): - _fields_ = [ - ("len", ctypes.c_int32), - ("data", ctypes.POINTER(ctypes.c_char)), - ] - - def __str__(self): - return "_UniffiForeignBytes(len={}, data={})".format(self.len, self.data[0:self.len]) - - -class _UniffiRustBufferStream: - """ - Helper for structured reading of bytes from a _UniffiRustBuffer - """ - - def __init__(self, data, len): - self.data = data - self.len = len - self.offset = 0 - - @classmethod - def from_rust_buffer(cls, buf): - return cls(buf.data, buf.len) - - def remaining(self): - return self.len - self.offset - - def _unpack_from(self, size, format): - if self.offset + size > self.len: - raise InternalError("read past end of rust buffer") - value = struct.unpack(format, self.data[self.offset:self.offset+size])[0] - self.offset += size - return value - - def read(self, size): - if self.offset + size > self.len: - raise InternalError("read past end of rust buffer") - data = self.data[self.offset:self.offset+size] - self.offset += size - return data - - def read_i8(self): - return self._unpack_from(1, ">b") - - def read_u8(self): - return self._unpack_from(1, ">B") - - def read_i16(self): - return self._unpack_from(2, ">h") - - def read_u16(self): - return self._unpack_from(2, ">H") - - def read_i32(self): - return self._unpack_from(4, ">i") - - def read_u32(self): - return self._unpack_from(4, ">I") - - def read_i64(self): - return self._unpack_from(8, ">q") - - def read_u64(self): - return self._unpack_from(8, ">Q") - - def read_float(self): - v = self._unpack_from(4, ">f") - return v - - def read_double(self): - return self._unpack_from(8, ">d") - -class _UniffiRustBufferBuilder: - """ - Helper for structured writing of bytes into a _UniffiRustBuffer. - """ - - def __init__(self): - self.rbuf = _UniffiRustBuffer.alloc(16) - self.rbuf.len = 0 - - def finalize(self): - rbuf = self.rbuf - self.rbuf = None - return rbuf - - def discard(self): - if self.rbuf is not None: - rbuf = self.finalize() - rbuf.free() - - @contextlib.contextmanager - def _reserve(self, num_bytes): - if self.rbuf.len + num_bytes > self.rbuf.capacity: - self.rbuf = _UniffiRustBuffer.reserve(self.rbuf, num_bytes) - yield None - self.rbuf.len += num_bytes - - def _pack_into(self, size, format, value): - with self._reserve(size): - # XXX TODO: I feel like I should be able to use `struct.pack_into` here but can't figure it out. - for i, byte in enumerate(struct.pack(format, value)): - self.rbuf.data[self.rbuf.len + i] = byte - - def write(self, value): - with self._reserve(len(value)): - for i, byte in enumerate(value): - self.rbuf.data[self.rbuf.len + i] = byte - - def write_i8(self, v): - self._pack_into(1, ">b", v) - - def write_u8(self, v): - self._pack_into(1, ">B", v) - - def write_i16(self, v): - self._pack_into(2, ">h", v) - - def write_u16(self, v): - self._pack_into(2, ">H", v) - - def write_i32(self, v): - self._pack_into(4, ">i", v) - - def write_u32(self, v): - self._pack_into(4, ">I", v) - - def write_i64(self, v): - self._pack_into(8, ">q", v) - - def write_u64(self, v): - self._pack_into(8, ">Q", v) - - def write_float(self, v): - self._pack_into(4, ">f", v) - - def write_double(self, v): - self._pack_into(8, ">d", v) - - def write_c_size_t(self, v): - self._pack_into(ctypes.sizeof(ctypes.c_size_t) , "@N", v) -# A handful of classes and functions to support the generated data structures. -# This would be a good candidate for isolating in its own ffi-support lib. - -class InternalError(Exception): - pass - -class _UniffiRustCallStatus(ctypes.Structure): - """ - Error runtime. - """ - _fields_ = [ - ("code", ctypes.c_int8), - ("error_buf", _UniffiRustBuffer), - ] - - # These match the values from the uniffi::rustcalls module - CALL_SUCCESS = 0 - CALL_ERROR = 1 - CALL_UNEXPECTED_ERROR = 2 - - @staticmethod - def default(): - return _UniffiRustCallStatus(code=_UniffiRustCallStatus.CALL_SUCCESS, error_buf=_UniffiRustBuffer.default()) - - def __str__(self): - if self.code == _UniffiRustCallStatus.CALL_SUCCESS: - return "_UniffiRustCallStatus(CALL_SUCCESS)" - elif self.code == _UniffiRustCallStatus.CALL_ERROR: - return "_UniffiRustCallStatus(CALL_ERROR)" - elif self.code == _UniffiRustCallStatus.CALL_UNEXPECTED_ERROR: - return "_UniffiRustCallStatus(CALL_UNEXPECTED_ERROR)" - else: - return "_UniffiRustCallStatus()" - -def _uniffi_rust_call(fn, *args): - # Call a rust function - return _uniffi_rust_call_with_error(None, fn, *args) - -def _uniffi_rust_call_with_error(error_ffi_converter, fn, *args): - # Call a rust function and handle any errors - # - # This function is used for rust calls that return Result<> and therefore can set the CALL_ERROR status code. - # error_ffi_converter must be set to the _UniffiConverter for the error class that corresponds to the result. - call_status = _UniffiRustCallStatus.default() - - args_with_error = args + (ctypes.byref(call_status),) - result = fn(*args_with_error) - _uniffi_check_call_status(error_ffi_converter, call_status) - return result - -def _uniffi_check_call_status(error_ffi_converter, call_status): - if call_status.code == _UniffiRustCallStatus.CALL_SUCCESS: - pass - elif call_status.code == _UniffiRustCallStatus.CALL_ERROR: - if error_ffi_converter is None: - call_status.error_buf.free() - raise InternalError("_uniffi_rust_call_with_error: CALL_ERROR, but error_ffi_converter is None") - else: - raise error_ffi_converter.lift(call_status.error_buf) - elif call_status.code == _UniffiRustCallStatus.CALL_UNEXPECTED_ERROR: - # When the rust code sees a panic, it tries to construct a _UniffiRustBuffer - # with the message. But if that code panics, then it just sends back - # an empty buffer. - if call_status.error_buf.len > 0: - msg = _UniffiConverterString.lift(call_status.error_buf) - else: - msg = "Unknown rust panic" - raise InternalError(msg) - else: - raise InternalError("Invalid _UniffiRustCallStatus code: {}".format( - call_status.code)) - -def _uniffi_trait_interface_call(call_status, make_call, write_return_value): - try: - return write_return_value(make_call()) - except Exception as e: - call_status.code = _UniffiRustCallStatus.CALL_UNEXPECTED_ERROR - call_status.error_buf = _UniffiConverterString.lower(repr(e)) - -def _uniffi_trait_interface_call_with_error(call_status, make_call, write_return_value, error_type, lower_error): - try: - try: - return write_return_value(make_call()) - except error_type as e: - call_status.code = _UniffiRustCallStatus.CALL_ERROR - call_status.error_buf = lower_error(e) - except Exception as e: - call_status.code = _UniffiRustCallStatus.CALL_UNEXPECTED_ERROR - call_status.error_buf = _UniffiConverterString.lower(repr(e)) -class _UniffiHandleMap: - """ - A map where inserting, getting and removing data is synchronized with a lock. - """ - - def __init__(self): - # type Handle = int - self._map = {} # type: Dict[Handle, Any] - self._lock = threading.Lock() - self._counter = itertools.count() - - def insert(self, obj): - with self._lock: - handle = next(self._counter) - self._map[handle] = obj - return handle - - def get(self, handle): - try: - with self._lock: - return self._map[handle] - except KeyError: - raise InternalError("_UniffiHandleMap.get: Invalid handle") - - def remove(self, handle): - try: - with self._lock: - return self._map.pop(handle) - except KeyError: - raise InternalError("_UniffiHandleMap.remove: Invalid handle") - - def __len__(self): - return len(self._map) -# Types conforming to `_UniffiConverterPrimitive` pass themselves directly over the FFI. -class _UniffiConverterPrimitive: - @classmethod - def lift(cls, value): - return value - - @classmethod - def lower(cls, value): - return value - -class _UniffiConverterPrimitiveInt(_UniffiConverterPrimitive): - @classmethod - def check_lower(cls, value): - try: - value = value.__index__() - except Exception: - raise TypeError("'{}' object cannot be interpreted as an integer".format(type(value).__name__)) - if not isinstance(value, int): - raise TypeError("__index__ returned non-int (type {})".format(type(value).__name__)) - if not cls.VALUE_MIN <= value < cls.VALUE_MAX: - raise ValueError("{} requires {} <= value < {}".format(cls.CLASS_NAME, cls.VALUE_MIN, cls.VALUE_MAX)) - -class _UniffiConverterPrimitiveFloat(_UniffiConverterPrimitive): - @classmethod - def check_lower(cls, value): - try: - value = value.__float__() - except Exception: - raise TypeError("must be real number, not {}".format(type(value).__name__)) - if not isinstance(value, float): - raise TypeError("__float__ returned non-float (type {})".format(type(value).__name__)) - -# Helper class for wrapper types that will always go through a _UniffiRustBuffer. -# Classes should inherit from this and implement the `read` and `write` static methods. -class _UniffiConverterRustBuffer: - @classmethod - def lift(cls, rbuf): - with rbuf.consume_with_stream() as stream: - return cls.read(stream) - - @classmethod - def lower(cls, value): - with _UniffiRustBuffer.alloc_with_builder() as builder: - cls.write(value, builder) - return builder.finalize() - -# Contains loading, initialization code, and the FFI Function declarations. -# Define some ctypes FFI types that we use in the library - -""" -Function pointer for a Rust task, which a callback function that takes a opaque pointer -""" -_UNIFFI_RUST_TASK = ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.c_int8) - -def _uniffi_future_callback_t(return_type): - """ - Factory function to create callback function types for async functions - """ - return ctypes.CFUNCTYPE(None, ctypes.c_uint64, return_type, _UniffiRustCallStatus) - -def _uniffi_load_indirect(): - """ - This is how we find and load the dynamic library provided by the component. - For now we just look it up by name. - """ - if sys.platform == "darwin": - libname = "lib{}.dylib" - elif sys.platform.startswith("win"): - # As of python3.8, ctypes does not seem to search $PATH when loading DLLs. - # We could use `os.add_dll_directory` to configure the search path, but - # it doesn't feel right to mess with application-wide settings. Let's - # assume that the `.dll` is next to the `.py` file and load by full path. - libname = os.path.join( - os.path.dirname(__file__), - "{}.dll", - ) - else: - # Anything else must be an ELF platform - Linux, *BSD, Solaris/illumos - libname = "lib{}.so" - - libname = libname.format("uniffi_c2pa") - path = os.path.join(os.path.dirname(__file__), libname) - lib = ctypes.cdll.LoadLibrary(path) - return lib - -def _uniffi_check_contract_api_version(lib): - # Get the bindings contract version from our ComponentInterface - bindings_contract_version = 26 - # Get the scaffolding contract version by calling the into the dylib - scaffolding_contract_version = lib.ffi_c2pa_uniffi_contract_version() - if bindings_contract_version != scaffolding_contract_version: - raise InternalError("UniFFI contract version mismatch: try cleaning and rebuilding your project") - -def _uniffi_check_api_checksums(lib): - if lib.uniffi_c2pa_checksum_func_sdk_version() != 37245: - raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_func_version() != 61576: - raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_method_builder_add_ingredient() != 56163: - raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_method_builder_add_resource() != 52123: - raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_method_builder_from_archive() != 45068: - raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_method_builder_set_no_embed() != 4775: - raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_method_builder_set_remote_url() != 26105: - raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_method_builder_sign() != 5940: - raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_method_builder_sign_file() != 2785: - raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_method_builder_to_archive() != 56076: - raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_method_builder_with_json() != 60973: - raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_method_reader_from_manifest_data_and_stream() != 58448: - raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_method_reader_from_stream() != 62816: - raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_method_reader_json() != 25079: - raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_method_reader_resource_to_stream() != 32633: - raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_constructor_builder_new() != 43948: - raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_constructor_callbacksigner_new() != 65452: - raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_constructor_callbacksigner_new_from_signer() != 27376: - raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_constructor_reader_new() != 19939: - raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_method_signercallback_sign() != 64776: - raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_method_stream_read_stream() != 16779: - raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_method_stream_seek_stream() != 39220: - raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_c2pa_checksum_method_stream_write_stream() != 63217: - raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - -# A ctypes library to expose the extern-C FFI definitions. -# This is an implementation detail which will be called internally by the public API. - -_UniffiLib = _uniffi_load_indirect() -_UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK = ctypes.CFUNCTYPE(None,ctypes.c_uint64,ctypes.c_int8, -) -_UNIFFI_FOREIGN_FUTURE_FREE = ctypes.CFUNCTYPE(None,ctypes.c_uint64, -) -_UNIFFI_CALLBACK_INTERFACE_FREE = ctypes.CFUNCTYPE(None,ctypes.c_uint64, -) -class _UniffiForeignFuture(ctypes.Structure): - _fields_ = [ - ("handle", ctypes.c_uint64), - ("free", _UNIFFI_FOREIGN_FUTURE_FREE), - ] -class _UniffiForeignFutureStructU8(ctypes.Structure): - _fields_ = [ - ("return_value", ctypes.c_uint8), - ("call_status", _UniffiRustCallStatus), - ] -_UNIFFI_FOREIGN_FUTURE_COMPLETE_U8 = ctypes.CFUNCTYPE(None,ctypes.c_uint64,_UniffiForeignFutureStructU8, -) -class _UniffiForeignFutureStructI8(ctypes.Structure): - _fields_ = [ - ("return_value", ctypes.c_int8), - ("call_status", _UniffiRustCallStatus), - ] -_UNIFFI_FOREIGN_FUTURE_COMPLETE_I8 = ctypes.CFUNCTYPE(None,ctypes.c_uint64,_UniffiForeignFutureStructI8, -) -class _UniffiForeignFutureStructU16(ctypes.Structure): - _fields_ = [ - ("return_value", ctypes.c_uint16), - ("call_status", _UniffiRustCallStatus), - ] -_UNIFFI_FOREIGN_FUTURE_COMPLETE_U16 = ctypes.CFUNCTYPE(None,ctypes.c_uint64,_UniffiForeignFutureStructU16, -) -class _UniffiForeignFutureStructI16(ctypes.Structure): - _fields_ = [ - ("return_value", ctypes.c_int16), - ("call_status", _UniffiRustCallStatus), - ] -_UNIFFI_FOREIGN_FUTURE_COMPLETE_I16 = ctypes.CFUNCTYPE(None,ctypes.c_uint64,_UniffiForeignFutureStructI16, -) -class _UniffiForeignFutureStructU32(ctypes.Structure): - _fields_ = [ - ("return_value", ctypes.c_uint32), - ("call_status", _UniffiRustCallStatus), - ] -_UNIFFI_FOREIGN_FUTURE_COMPLETE_U32 = ctypes.CFUNCTYPE(None,ctypes.c_uint64,_UniffiForeignFutureStructU32, -) -class _UniffiForeignFutureStructI32(ctypes.Structure): - _fields_ = [ - ("return_value", ctypes.c_int32), - ("call_status", _UniffiRustCallStatus), - ] -_UNIFFI_FOREIGN_FUTURE_COMPLETE_I32 = ctypes.CFUNCTYPE(None,ctypes.c_uint64,_UniffiForeignFutureStructI32, -) -class _UniffiForeignFutureStructU64(ctypes.Structure): - _fields_ = [ - ("return_value", ctypes.c_uint64), - ("call_status", _UniffiRustCallStatus), - ] -_UNIFFI_FOREIGN_FUTURE_COMPLETE_U64 = ctypes.CFUNCTYPE(None,ctypes.c_uint64,_UniffiForeignFutureStructU64, -) -class _UniffiForeignFutureStructI64(ctypes.Structure): - _fields_ = [ - ("return_value", ctypes.c_int64), - ("call_status", _UniffiRustCallStatus), - ] -_UNIFFI_FOREIGN_FUTURE_COMPLETE_I64 = ctypes.CFUNCTYPE(None,ctypes.c_uint64,_UniffiForeignFutureStructI64, -) -class _UniffiForeignFutureStructF32(ctypes.Structure): - _fields_ = [ - ("return_value", ctypes.c_float), - ("call_status", _UniffiRustCallStatus), - ] -_UNIFFI_FOREIGN_FUTURE_COMPLETE_F32 = ctypes.CFUNCTYPE(None,ctypes.c_uint64,_UniffiForeignFutureStructF32, -) -class _UniffiForeignFutureStructF64(ctypes.Structure): - _fields_ = [ - ("return_value", ctypes.c_double), - ("call_status", _UniffiRustCallStatus), - ] -_UNIFFI_FOREIGN_FUTURE_COMPLETE_F64 = ctypes.CFUNCTYPE(None,ctypes.c_uint64,_UniffiForeignFutureStructF64, -) -class _UniffiForeignFutureStructPointer(ctypes.Structure): - _fields_ = [ - ("return_value", ctypes.c_void_p), - ("call_status", _UniffiRustCallStatus), - ] -_UNIFFI_FOREIGN_FUTURE_COMPLETE_POINTER = ctypes.CFUNCTYPE(None,ctypes.c_uint64,_UniffiForeignFutureStructPointer, -) -class _UniffiForeignFutureStructRustBuffer(ctypes.Structure): - _fields_ = [ - ("return_value", _UniffiRustBuffer), - ("call_status", _UniffiRustCallStatus), - ] -_UNIFFI_FOREIGN_FUTURE_COMPLETE_RUST_BUFFER = ctypes.CFUNCTYPE(None,ctypes.c_uint64,_UniffiForeignFutureStructRustBuffer, -) -class _UniffiForeignFutureStructVoid(ctypes.Structure): - _fields_ = [ - ("call_status", _UniffiRustCallStatus), - ] -_UNIFFI_FOREIGN_FUTURE_COMPLETE_VOID = ctypes.CFUNCTYPE(None,ctypes.c_uint64,_UniffiForeignFutureStructVoid, -) -_UNIFFI_CALLBACK_INTERFACE_SIGNER_CALLBACK_METHOD0 = ctypes.CFUNCTYPE(None,ctypes.c_uint64,_UniffiRustBuffer,ctypes.POINTER(_UniffiRustBuffer), - ctypes.POINTER(_UniffiRustCallStatus), -) -_UNIFFI_CALLBACK_INTERFACE_STREAM_METHOD0 = ctypes.CFUNCTYPE(None,ctypes.c_uint64,ctypes.c_uint64,ctypes.POINTER(_UniffiRustBuffer), - ctypes.POINTER(_UniffiRustCallStatus), -) -_UNIFFI_CALLBACK_INTERFACE_STREAM_METHOD1 = ctypes.CFUNCTYPE(None,ctypes.c_uint64,ctypes.c_int64,_UniffiRustBuffer,ctypes.POINTER(ctypes.c_uint64), - ctypes.POINTER(_UniffiRustCallStatus), -) -_UNIFFI_CALLBACK_INTERFACE_STREAM_METHOD2 = ctypes.CFUNCTYPE(None,ctypes.c_uint64,_UniffiRustBuffer,ctypes.POINTER(ctypes.c_uint64), - ctypes.POINTER(_UniffiRustCallStatus), -) -class _UniffiVTableCallbackInterfaceSignerCallback(ctypes.Structure): - _fields_ = [ - ("sign", _UNIFFI_CALLBACK_INTERFACE_SIGNER_CALLBACK_METHOD0), - ("uniffi_free", _UNIFFI_CALLBACK_INTERFACE_FREE), - ] -class _UniffiVTableCallbackInterfaceStream(ctypes.Structure): - _fields_ = [ - ("read_stream", _UNIFFI_CALLBACK_INTERFACE_STREAM_METHOD0), - ("seek_stream", _UNIFFI_CALLBACK_INTERFACE_STREAM_METHOD1), - ("write_stream", _UNIFFI_CALLBACK_INTERFACE_STREAM_METHOD2), - ("uniffi_free", _UNIFFI_CALLBACK_INTERFACE_FREE), - ] -_UniffiLib.uniffi_c2pa_fn_clone_builder.argtypes = ( - ctypes.c_void_p, - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.uniffi_c2pa_fn_clone_builder.restype = ctypes.c_void_p -_UniffiLib.uniffi_c2pa_fn_free_builder.argtypes = ( - ctypes.c_void_p, - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.uniffi_c2pa_fn_free_builder.restype = None -_UniffiLib.uniffi_c2pa_fn_constructor_builder_new.argtypes = ( - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.uniffi_c2pa_fn_constructor_builder_new.restype = ctypes.c_void_p -_UniffiLib.uniffi_c2pa_fn_method_builder_add_ingredient.argtypes = ( - ctypes.c_void_p, - _UniffiRustBuffer, - _UniffiRustBuffer, - ctypes.c_uint64, - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.uniffi_c2pa_fn_method_builder_add_ingredient.restype = None -_UniffiLib.uniffi_c2pa_fn_method_builder_add_resource.argtypes = ( - ctypes.c_void_p, - _UniffiRustBuffer, - ctypes.c_uint64, - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.uniffi_c2pa_fn_method_builder_add_resource.restype = None -_UniffiLib.uniffi_c2pa_fn_method_builder_from_archive.argtypes = ( - ctypes.c_void_p, - ctypes.c_uint64, - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.uniffi_c2pa_fn_method_builder_from_archive.restype = None -_UniffiLib.uniffi_c2pa_fn_method_builder_set_no_embed.argtypes = ( - ctypes.c_void_p, - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.uniffi_c2pa_fn_method_builder_set_no_embed.restype = None -_UniffiLib.uniffi_c2pa_fn_method_builder_set_remote_url.argtypes = ( - ctypes.c_void_p, - _UniffiRustBuffer, - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.uniffi_c2pa_fn_method_builder_set_remote_url.restype = None -_UniffiLib.uniffi_c2pa_fn_method_builder_sign.argtypes = ( - ctypes.c_void_p, - ctypes.c_void_p, - _UniffiRustBuffer, - ctypes.c_uint64, - ctypes.c_uint64, - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.uniffi_c2pa_fn_method_builder_sign.restype = _UniffiRustBuffer -_UniffiLib.uniffi_c2pa_fn_method_builder_sign_file.argtypes = ( - ctypes.c_void_p, - ctypes.c_void_p, - _UniffiRustBuffer, - _UniffiRustBuffer, - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.uniffi_c2pa_fn_method_builder_sign_file.restype = _UniffiRustBuffer -_UniffiLib.uniffi_c2pa_fn_method_builder_to_archive.argtypes = ( - ctypes.c_void_p, - ctypes.c_uint64, - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.uniffi_c2pa_fn_method_builder_to_archive.restype = None -_UniffiLib.uniffi_c2pa_fn_method_builder_with_json.argtypes = ( - ctypes.c_void_p, - _UniffiRustBuffer, - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.uniffi_c2pa_fn_method_builder_with_json.restype = None -_UniffiLib.uniffi_c2pa_fn_clone_callbacksigner.argtypes = ( - ctypes.c_void_p, - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.uniffi_c2pa_fn_clone_callbacksigner.restype = ctypes.c_void_p -_UniffiLib.uniffi_c2pa_fn_free_callbacksigner.argtypes = ( - ctypes.c_void_p, - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.uniffi_c2pa_fn_free_callbacksigner.restype = None -_UniffiLib.uniffi_c2pa_fn_constructor_callbacksigner_new.argtypes = ( - ctypes.c_uint64, - _UniffiRustBuffer, - _UniffiRustBuffer, - _UniffiRustBuffer, - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.uniffi_c2pa_fn_constructor_callbacksigner_new.restype = ctypes.c_void_p -_UniffiLib.uniffi_c2pa_fn_constructor_callbacksigner_new_from_signer.argtypes = ( - ctypes.c_uint64, - _UniffiRustBuffer, - ctypes.c_uint32, - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.uniffi_c2pa_fn_constructor_callbacksigner_new_from_signer.restype = ctypes.c_void_p -_UniffiLib.uniffi_c2pa_fn_clone_reader.argtypes = ( - ctypes.c_void_p, - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.uniffi_c2pa_fn_clone_reader.restype = ctypes.c_void_p -_UniffiLib.uniffi_c2pa_fn_free_reader.argtypes = ( - ctypes.c_void_p, - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.uniffi_c2pa_fn_free_reader.restype = None -_UniffiLib.uniffi_c2pa_fn_constructor_reader_new.argtypes = ( - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.uniffi_c2pa_fn_constructor_reader_new.restype = ctypes.c_void_p -_UniffiLib.uniffi_c2pa_fn_method_reader_from_manifest_data_and_stream.argtypes = ( - ctypes.c_void_p, - _UniffiRustBuffer, - _UniffiRustBuffer, - ctypes.c_uint64, - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.uniffi_c2pa_fn_method_reader_from_manifest_data_and_stream.restype = _UniffiRustBuffer -_UniffiLib.uniffi_c2pa_fn_method_reader_from_stream.argtypes = ( - ctypes.c_void_p, - _UniffiRustBuffer, - ctypes.c_uint64, - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.uniffi_c2pa_fn_method_reader_from_stream.restype = _UniffiRustBuffer -_UniffiLib.uniffi_c2pa_fn_method_reader_json.argtypes = ( - ctypes.c_void_p, - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.uniffi_c2pa_fn_method_reader_json.restype = _UniffiRustBuffer -_UniffiLib.uniffi_c2pa_fn_method_reader_resource_to_stream.argtypes = ( - ctypes.c_void_p, - _UniffiRustBuffer, - ctypes.c_uint64, - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.uniffi_c2pa_fn_method_reader_resource_to_stream.restype = ctypes.c_uint64 -_UniffiLib.uniffi_c2pa_fn_init_callback_vtable_signercallback.argtypes = ( - ctypes.POINTER(_UniffiVTableCallbackInterfaceSignerCallback), -) -_UniffiLib.uniffi_c2pa_fn_init_callback_vtable_signercallback.restype = None -_UniffiLib.uniffi_c2pa_fn_init_callback_vtable_stream.argtypes = ( - ctypes.POINTER(_UniffiVTableCallbackInterfaceStream), -) -_UniffiLib.uniffi_c2pa_fn_init_callback_vtable_stream.restype = None -_UniffiLib.uniffi_c2pa_fn_func_sdk_version.argtypes = ( - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.uniffi_c2pa_fn_func_sdk_version.restype = _UniffiRustBuffer -_UniffiLib.uniffi_c2pa_fn_func_version.argtypes = ( - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.uniffi_c2pa_fn_func_version.restype = _UniffiRustBuffer -_UniffiLib.ffi_c2pa_rustbuffer_alloc.argtypes = ( - ctypes.c_uint64, - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.ffi_c2pa_rustbuffer_alloc.restype = _UniffiRustBuffer -_UniffiLib.ffi_c2pa_rustbuffer_from_bytes.argtypes = ( - _UniffiForeignBytes, - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.ffi_c2pa_rustbuffer_from_bytes.restype = _UniffiRustBuffer -_UniffiLib.ffi_c2pa_rustbuffer_free.argtypes = ( - _UniffiRustBuffer, - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.ffi_c2pa_rustbuffer_free.restype = None -_UniffiLib.ffi_c2pa_rustbuffer_reserve.argtypes = ( - _UniffiRustBuffer, - ctypes.c_uint64, - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.ffi_c2pa_rustbuffer_reserve.restype = _UniffiRustBuffer -_UniffiLib.ffi_c2pa_rust_future_poll_u8.argtypes = ( - ctypes.c_uint64, - _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK, - ctypes.c_uint64, -) -_UniffiLib.ffi_c2pa_rust_future_poll_u8.restype = None -_UniffiLib.ffi_c2pa_rust_future_cancel_u8.argtypes = ( - ctypes.c_uint64, -) -_UniffiLib.ffi_c2pa_rust_future_cancel_u8.restype = None -_UniffiLib.ffi_c2pa_rust_future_free_u8.argtypes = ( - ctypes.c_uint64, -) -_UniffiLib.ffi_c2pa_rust_future_free_u8.restype = None -_UniffiLib.ffi_c2pa_rust_future_complete_u8.argtypes = ( - ctypes.c_uint64, - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.ffi_c2pa_rust_future_complete_u8.restype = ctypes.c_uint8 -_UniffiLib.ffi_c2pa_rust_future_poll_i8.argtypes = ( - ctypes.c_uint64, - _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK, - ctypes.c_uint64, -) -_UniffiLib.ffi_c2pa_rust_future_poll_i8.restype = None -_UniffiLib.ffi_c2pa_rust_future_cancel_i8.argtypes = ( - ctypes.c_uint64, -) -_UniffiLib.ffi_c2pa_rust_future_cancel_i8.restype = None -_UniffiLib.ffi_c2pa_rust_future_free_i8.argtypes = ( - ctypes.c_uint64, -) -_UniffiLib.ffi_c2pa_rust_future_free_i8.restype = None -_UniffiLib.ffi_c2pa_rust_future_complete_i8.argtypes = ( - ctypes.c_uint64, - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.ffi_c2pa_rust_future_complete_i8.restype = ctypes.c_int8 -_UniffiLib.ffi_c2pa_rust_future_poll_u16.argtypes = ( - ctypes.c_uint64, - _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK, - ctypes.c_uint64, -) -_UniffiLib.ffi_c2pa_rust_future_poll_u16.restype = None -_UniffiLib.ffi_c2pa_rust_future_cancel_u16.argtypes = ( - ctypes.c_uint64, -) -_UniffiLib.ffi_c2pa_rust_future_cancel_u16.restype = None -_UniffiLib.ffi_c2pa_rust_future_free_u16.argtypes = ( - ctypes.c_uint64, -) -_UniffiLib.ffi_c2pa_rust_future_free_u16.restype = None -_UniffiLib.ffi_c2pa_rust_future_complete_u16.argtypes = ( - ctypes.c_uint64, - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.ffi_c2pa_rust_future_complete_u16.restype = ctypes.c_uint16 -_UniffiLib.ffi_c2pa_rust_future_poll_i16.argtypes = ( - ctypes.c_uint64, - _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK, - ctypes.c_uint64, -) -_UniffiLib.ffi_c2pa_rust_future_poll_i16.restype = None -_UniffiLib.ffi_c2pa_rust_future_cancel_i16.argtypes = ( - ctypes.c_uint64, -) -_UniffiLib.ffi_c2pa_rust_future_cancel_i16.restype = None -_UniffiLib.ffi_c2pa_rust_future_free_i16.argtypes = ( - ctypes.c_uint64, -) -_UniffiLib.ffi_c2pa_rust_future_free_i16.restype = None -_UniffiLib.ffi_c2pa_rust_future_complete_i16.argtypes = ( - ctypes.c_uint64, - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.ffi_c2pa_rust_future_complete_i16.restype = ctypes.c_int16 -_UniffiLib.ffi_c2pa_rust_future_poll_u32.argtypes = ( - ctypes.c_uint64, - _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK, - ctypes.c_uint64, -) -_UniffiLib.ffi_c2pa_rust_future_poll_u32.restype = None -_UniffiLib.ffi_c2pa_rust_future_cancel_u32.argtypes = ( - ctypes.c_uint64, -) -_UniffiLib.ffi_c2pa_rust_future_cancel_u32.restype = None -_UniffiLib.ffi_c2pa_rust_future_free_u32.argtypes = ( - ctypes.c_uint64, -) -_UniffiLib.ffi_c2pa_rust_future_free_u32.restype = None -_UniffiLib.ffi_c2pa_rust_future_complete_u32.argtypes = ( - ctypes.c_uint64, - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.ffi_c2pa_rust_future_complete_u32.restype = ctypes.c_uint32 -_UniffiLib.ffi_c2pa_rust_future_poll_i32.argtypes = ( - ctypes.c_uint64, - _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK, - ctypes.c_uint64, -) -_UniffiLib.ffi_c2pa_rust_future_poll_i32.restype = None -_UniffiLib.ffi_c2pa_rust_future_cancel_i32.argtypes = ( - ctypes.c_uint64, -) -_UniffiLib.ffi_c2pa_rust_future_cancel_i32.restype = None -_UniffiLib.ffi_c2pa_rust_future_free_i32.argtypes = ( - ctypes.c_uint64, -) -_UniffiLib.ffi_c2pa_rust_future_free_i32.restype = None -_UniffiLib.ffi_c2pa_rust_future_complete_i32.argtypes = ( - ctypes.c_uint64, - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.ffi_c2pa_rust_future_complete_i32.restype = ctypes.c_int32 -_UniffiLib.ffi_c2pa_rust_future_poll_u64.argtypes = ( - ctypes.c_uint64, - _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK, - ctypes.c_uint64, -) -_UniffiLib.ffi_c2pa_rust_future_poll_u64.restype = None -_UniffiLib.ffi_c2pa_rust_future_cancel_u64.argtypes = ( - ctypes.c_uint64, -) -_UniffiLib.ffi_c2pa_rust_future_cancel_u64.restype = None -_UniffiLib.ffi_c2pa_rust_future_free_u64.argtypes = ( - ctypes.c_uint64, -) -_UniffiLib.ffi_c2pa_rust_future_free_u64.restype = None -_UniffiLib.ffi_c2pa_rust_future_complete_u64.argtypes = ( - ctypes.c_uint64, - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.ffi_c2pa_rust_future_complete_u64.restype = ctypes.c_uint64 -_UniffiLib.ffi_c2pa_rust_future_poll_i64.argtypes = ( - ctypes.c_uint64, - _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK, - ctypes.c_uint64, -) -_UniffiLib.ffi_c2pa_rust_future_poll_i64.restype = None -_UniffiLib.ffi_c2pa_rust_future_cancel_i64.argtypes = ( - ctypes.c_uint64, -) -_UniffiLib.ffi_c2pa_rust_future_cancel_i64.restype = None -_UniffiLib.ffi_c2pa_rust_future_free_i64.argtypes = ( - ctypes.c_uint64, -) -_UniffiLib.ffi_c2pa_rust_future_free_i64.restype = None -_UniffiLib.ffi_c2pa_rust_future_complete_i64.argtypes = ( - ctypes.c_uint64, - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.ffi_c2pa_rust_future_complete_i64.restype = ctypes.c_int64 -_UniffiLib.ffi_c2pa_rust_future_poll_f32.argtypes = ( - ctypes.c_uint64, - _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK, - ctypes.c_uint64, -) -_UniffiLib.ffi_c2pa_rust_future_poll_f32.restype = None -_UniffiLib.ffi_c2pa_rust_future_cancel_f32.argtypes = ( - ctypes.c_uint64, -) -_UniffiLib.ffi_c2pa_rust_future_cancel_f32.restype = None -_UniffiLib.ffi_c2pa_rust_future_free_f32.argtypes = ( - ctypes.c_uint64, -) -_UniffiLib.ffi_c2pa_rust_future_free_f32.restype = None -_UniffiLib.ffi_c2pa_rust_future_complete_f32.argtypes = ( - ctypes.c_uint64, - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.ffi_c2pa_rust_future_complete_f32.restype = ctypes.c_float -_UniffiLib.ffi_c2pa_rust_future_poll_f64.argtypes = ( - ctypes.c_uint64, - _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK, - ctypes.c_uint64, -) -_UniffiLib.ffi_c2pa_rust_future_poll_f64.restype = None -_UniffiLib.ffi_c2pa_rust_future_cancel_f64.argtypes = ( - ctypes.c_uint64, -) -_UniffiLib.ffi_c2pa_rust_future_cancel_f64.restype = None -_UniffiLib.ffi_c2pa_rust_future_free_f64.argtypes = ( - ctypes.c_uint64, -) -_UniffiLib.ffi_c2pa_rust_future_free_f64.restype = None -_UniffiLib.ffi_c2pa_rust_future_complete_f64.argtypes = ( - ctypes.c_uint64, - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.ffi_c2pa_rust_future_complete_f64.restype = ctypes.c_double -_UniffiLib.ffi_c2pa_rust_future_poll_pointer.argtypes = ( - ctypes.c_uint64, - _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK, - ctypes.c_uint64, -) -_UniffiLib.ffi_c2pa_rust_future_poll_pointer.restype = None -_UniffiLib.ffi_c2pa_rust_future_cancel_pointer.argtypes = ( - ctypes.c_uint64, -) -_UniffiLib.ffi_c2pa_rust_future_cancel_pointer.restype = None -_UniffiLib.ffi_c2pa_rust_future_free_pointer.argtypes = ( - ctypes.c_uint64, -) -_UniffiLib.ffi_c2pa_rust_future_free_pointer.restype = None -_UniffiLib.ffi_c2pa_rust_future_complete_pointer.argtypes = ( - ctypes.c_uint64, - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.ffi_c2pa_rust_future_complete_pointer.restype = ctypes.c_void_p -_UniffiLib.ffi_c2pa_rust_future_poll_rust_buffer.argtypes = ( - ctypes.c_uint64, - _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK, - ctypes.c_uint64, -) -_UniffiLib.ffi_c2pa_rust_future_poll_rust_buffer.restype = None -_UniffiLib.ffi_c2pa_rust_future_cancel_rust_buffer.argtypes = ( - ctypes.c_uint64, -) -_UniffiLib.ffi_c2pa_rust_future_cancel_rust_buffer.restype = None -_UniffiLib.ffi_c2pa_rust_future_free_rust_buffer.argtypes = ( - ctypes.c_uint64, -) -_UniffiLib.ffi_c2pa_rust_future_free_rust_buffer.restype = None -_UniffiLib.ffi_c2pa_rust_future_complete_rust_buffer.argtypes = ( - ctypes.c_uint64, - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.ffi_c2pa_rust_future_complete_rust_buffer.restype = _UniffiRustBuffer -_UniffiLib.ffi_c2pa_rust_future_poll_void.argtypes = ( - ctypes.c_uint64, - _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK, - ctypes.c_uint64, -) -_UniffiLib.ffi_c2pa_rust_future_poll_void.restype = None -_UniffiLib.ffi_c2pa_rust_future_cancel_void.argtypes = ( - ctypes.c_uint64, -) -_UniffiLib.ffi_c2pa_rust_future_cancel_void.restype = None -_UniffiLib.ffi_c2pa_rust_future_free_void.argtypes = ( - ctypes.c_uint64, -) -_UniffiLib.ffi_c2pa_rust_future_free_void.restype = None -_UniffiLib.ffi_c2pa_rust_future_complete_void.argtypes = ( - ctypes.c_uint64, - ctypes.POINTER(_UniffiRustCallStatus), -) -_UniffiLib.ffi_c2pa_rust_future_complete_void.restype = None -_UniffiLib.uniffi_c2pa_checksum_func_sdk_version.argtypes = ( -) -_UniffiLib.uniffi_c2pa_checksum_func_sdk_version.restype = ctypes.c_uint16 -_UniffiLib.uniffi_c2pa_checksum_func_version.argtypes = ( -) -_UniffiLib.uniffi_c2pa_checksum_func_version.restype = ctypes.c_uint16 -_UniffiLib.uniffi_c2pa_checksum_method_builder_add_ingredient.argtypes = ( -) -_UniffiLib.uniffi_c2pa_checksum_method_builder_add_ingredient.restype = ctypes.c_uint16 -_UniffiLib.uniffi_c2pa_checksum_method_builder_add_resource.argtypes = ( -) -_UniffiLib.uniffi_c2pa_checksum_method_builder_add_resource.restype = ctypes.c_uint16 -_UniffiLib.uniffi_c2pa_checksum_method_builder_from_archive.argtypes = ( -) -_UniffiLib.uniffi_c2pa_checksum_method_builder_from_archive.restype = ctypes.c_uint16 -_UniffiLib.uniffi_c2pa_checksum_method_builder_set_no_embed.argtypes = ( -) -_UniffiLib.uniffi_c2pa_checksum_method_builder_set_no_embed.restype = ctypes.c_uint16 -_UniffiLib.uniffi_c2pa_checksum_method_builder_set_remote_url.argtypes = ( -) -_UniffiLib.uniffi_c2pa_checksum_method_builder_set_remote_url.restype = ctypes.c_uint16 -_UniffiLib.uniffi_c2pa_checksum_method_builder_sign.argtypes = ( -) -_UniffiLib.uniffi_c2pa_checksum_method_builder_sign.restype = ctypes.c_uint16 -_UniffiLib.uniffi_c2pa_checksum_method_builder_sign_file.argtypes = ( -) -_UniffiLib.uniffi_c2pa_checksum_method_builder_sign_file.restype = ctypes.c_uint16 -_UniffiLib.uniffi_c2pa_checksum_method_builder_to_archive.argtypes = ( -) -_UniffiLib.uniffi_c2pa_checksum_method_builder_to_archive.restype = ctypes.c_uint16 -_UniffiLib.uniffi_c2pa_checksum_method_builder_with_json.argtypes = ( -) -_UniffiLib.uniffi_c2pa_checksum_method_builder_with_json.restype = ctypes.c_uint16 -_UniffiLib.uniffi_c2pa_checksum_method_reader_from_manifest_data_and_stream.argtypes = ( -) -_UniffiLib.uniffi_c2pa_checksum_method_reader_from_manifest_data_and_stream.restype = ctypes.c_uint16 -_UniffiLib.uniffi_c2pa_checksum_method_reader_from_stream.argtypes = ( -) -_UniffiLib.uniffi_c2pa_checksum_method_reader_from_stream.restype = ctypes.c_uint16 -_UniffiLib.uniffi_c2pa_checksum_method_reader_json.argtypes = ( -) -_UniffiLib.uniffi_c2pa_checksum_method_reader_json.restype = ctypes.c_uint16 -_UniffiLib.uniffi_c2pa_checksum_method_reader_resource_to_stream.argtypes = ( -) -_UniffiLib.uniffi_c2pa_checksum_method_reader_resource_to_stream.restype = ctypes.c_uint16 -_UniffiLib.uniffi_c2pa_checksum_constructor_builder_new.argtypes = ( -) -_UniffiLib.uniffi_c2pa_checksum_constructor_builder_new.restype = ctypes.c_uint16 -_UniffiLib.uniffi_c2pa_checksum_constructor_callbacksigner_new.argtypes = ( -) -_UniffiLib.uniffi_c2pa_checksum_constructor_callbacksigner_new.restype = ctypes.c_uint16 -_UniffiLib.uniffi_c2pa_checksum_constructor_callbacksigner_new_from_signer.argtypes = ( -) -_UniffiLib.uniffi_c2pa_checksum_constructor_callbacksigner_new_from_signer.restype = ctypes.c_uint16 -_UniffiLib.uniffi_c2pa_checksum_constructor_reader_new.argtypes = ( -) -_UniffiLib.uniffi_c2pa_checksum_constructor_reader_new.restype = ctypes.c_uint16 -_UniffiLib.uniffi_c2pa_checksum_method_signercallback_sign.argtypes = ( -) -_UniffiLib.uniffi_c2pa_checksum_method_signercallback_sign.restype = ctypes.c_uint16 -_UniffiLib.uniffi_c2pa_checksum_method_stream_read_stream.argtypes = ( -) -_UniffiLib.uniffi_c2pa_checksum_method_stream_read_stream.restype = ctypes.c_uint16 -_UniffiLib.uniffi_c2pa_checksum_method_stream_seek_stream.argtypes = ( -) -_UniffiLib.uniffi_c2pa_checksum_method_stream_seek_stream.restype = ctypes.c_uint16 -_UniffiLib.uniffi_c2pa_checksum_method_stream_write_stream.argtypes = ( -) -_UniffiLib.uniffi_c2pa_checksum_method_stream_write_stream.restype = ctypes.c_uint16 -_UniffiLib.ffi_c2pa_uniffi_contract_version.argtypes = ( -) -_UniffiLib.ffi_c2pa_uniffi_contract_version.restype = ctypes.c_uint32 - -_uniffi_check_contract_api_version(_UniffiLib) -_uniffi_check_api_checksums(_UniffiLib) - -# Public interface members begin here. - - -class _UniffiConverterUInt32(_UniffiConverterPrimitiveInt): - CLASS_NAME = "u32" - VALUE_MIN = 0 - VALUE_MAX = 2**32 - - @staticmethod - def read(buf): - return buf.read_u32() - - @staticmethod - def write(value, buf): - buf.write_u32(value) - -class _UniffiConverterUInt64(_UniffiConverterPrimitiveInt): - CLASS_NAME = "u64" - VALUE_MIN = 0 - VALUE_MAX = 2**64 - - @staticmethod - def read(buf): - return buf.read_u64() - - @staticmethod - def write(value, buf): - buf.write_u64(value) - -class _UniffiConverterInt64(_UniffiConverterPrimitiveInt): - CLASS_NAME = "i64" - VALUE_MIN = -2**63 - VALUE_MAX = 2**63 - - @staticmethod - def read(buf): - return buf.read_i64() - - @staticmethod - def write(value, buf): - buf.write_i64(value) - -class _UniffiConverterString: - @staticmethod - def check_lower(value): - if not isinstance(value, str): - raise TypeError("argument must be str, not {}".format(type(value).__name__)) - return value - - @staticmethod - def read(buf): - size = buf.read_i32() - if size < 0: - raise InternalError("Unexpected negative string length") - utf8_bytes = buf.read(size) - return utf8_bytes.decode("utf-8") - - @staticmethod - def write(value, buf): - utf8_bytes = value.encode("utf-8") - buf.write_i32(len(utf8_bytes)) - buf.write(utf8_bytes) - - @staticmethod - def lift(buf): - with buf.consume_with_stream() as stream: - return stream.read(stream.remaining()).decode("utf-8") - - @staticmethod - def lower(value): - with _UniffiRustBuffer.alloc_with_builder() as builder: - builder.write(value.encode("utf-8")) - return builder.finalize() - -class _UniffiConverterBytes(_UniffiConverterRustBuffer): - @staticmethod - def read(buf): - size = buf.read_i32() - if size < 0: - raise InternalError("Unexpected negative byte string length") - return buf.read(size) - - @staticmethod - def check_lower(value): - try: - memoryview(value) - except TypeError: - raise TypeError("a bytes-like object is required, not {!r}".format(type(value).__name__)) - - @staticmethod - def write(value, buf): - buf.write_i32(len(value)) - buf.write(value) - - - -class BuilderProtocol(typing.Protocol): - def add_ingredient(self, ingredient_json: "str",format: "str",stream: "Stream"): - raise NotImplementedError - def add_resource(self, uri: "str",stream: "Stream"): - raise NotImplementedError - def from_archive(self, stream: "Stream"): - raise NotImplementedError - def set_no_embed(self, ): - raise NotImplementedError - def set_remote_url(self, url: "str"): - raise NotImplementedError - def sign(self, signer: "CallbackSigner",format: "str",input: "Stream",output: "Stream"): - raise NotImplementedError - def sign_file(self, signer: "CallbackSigner",input: "str",output: "str"): - raise NotImplementedError - def to_archive(self, stream: "Stream"): - raise NotImplementedError - def with_json(self, json: "str"): - raise NotImplementedError - - -class Builder: - _pointer: ctypes.c_void_p - def __init__(self, ): - self._pointer = _uniffi_rust_call(_UniffiLib.uniffi_c2pa_fn_constructor_builder_new,) - - def __del__(self): - # In case of partial initialization of instances. - pointer = getattr(self, "_pointer", None) - if pointer is not None: - _uniffi_rust_call(_UniffiLib.uniffi_c2pa_fn_free_builder, pointer) - - def _uniffi_clone_pointer(self): - return _uniffi_rust_call(_UniffiLib.uniffi_c2pa_fn_clone_builder, self._pointer) - - # Used by alternative constructors or any methods which return this type. - @classmethod - def _make_instance_(cls, pointer): - # Lightly yucky way to bypass the usual __init__ logic - # and just create a new instance with the required pointer. - inst = cls.__new__(cls) - inst._pointer = pointer - return inst - - - def add_ingredient(self, ingredient_json: "str",format: "str",stream: "Stream") -> None: - _UniffiConverterString.check_lower(ingredient_json) - - _UniffiConverterString.check_lower(format) - - _UniffiConverterCallbackInterfaceStream.check_lower(stream) - - _uniffi_rust_call_with_error(_UniffiConverterTypeError,_UniffiLib.uniffi_c2pa_fn_method_builder_add_ingredient,self._uniffi_clone_pointer(), - _UniffiConverterString.lower(ingredient_json), - _UniffiConverterString.lower(format), - _UniffiConverterCallbackInterfaceStream.lower(stream)) - - - - - - - def add_resource(self, uri: "str",stream: "Stream") -> None: - _UniffiConverterString.check_lower(uri) - - _UniffiConverterCallbackInterfaceStream.check_lower(stream) - - _uniffi_rust_call_with_error(_UniffiConverterTypeError,_UniffiLib.uniffi_c2pa_fn_method_builder_add_resource,self._uniffi_clone_pointer(), - _UniffiConverterString.lower(uri), - _UniffiConverterCallbackInterfaceStream.lower(stream)) - - - - - - - def from_archive(self, stream: "Stream") -> None: - _UniffiConverterCallbackInterfaceStream.check_lower(stream) - - _uniffi_rust_call_with_error(_UniffiConverterTypeError,_UniffiLib.uniffi_c2pa_fn_method_builder_from_archive,self._uniffi_clone_pointer(), - _UniffiConverterCallbackInterfaceStream.lower(stream)) - - - - - - - def set_no_embed(self, ) -> None: - _uniffi_rust_call_with_error(_UniffiConverterTypeError,_UniffiLib.uniffi_c2pa_fn_method_builder_set_no_embed,self._uniffi_clone_pointer(),) - - - - - - - def set_remote_url(self, url: "str") -> None: - _UniffiConverterString.check_lower(url) - - _uniffi_rust_call_with_error(_UniffiConverterTypeError,_UniffiLib.uniffi_c2pa_fn_method_builder_set_remote_url,self._uniffi_clone_pointer(), - _UniffiConverterString.lower(url)) - - - - - - - def sign(self, signer: "CallbackSigner",format: "str",input: "Stream",output: "Stream") -> "bytes": - _UniffiConverterTypeCallbackSigner.check_lower(signer) - - _UniffiConverterString.check_lower(format) - - _UniffiConverterCallbackInterfaceStream.check_lower(input) - - _UniffiConverterCallbackInterfaceStream.check_lower(output) - - return _UniffiConverterBytes.lift( - _uniffi_rust_call_with_error(_UniffiConverterTypeError,_UniffiLib.uniffi_c2pa_fn_method_builder_sign,self._uniffi_clone_pointer(), - _UniffiConverterTypeCallbackSigner.lower(signer), - _UniffiConverterString.lower(format), - _UniffiConverterCallbackInterfaceStream.lower(input), - _UniffiConverterCallbackInterfaceStream.lower(output)) - ) - - - - - - def sign_file(self, signer: "CallbackSigner",input: "str",output: "str") -> "bytes": - _UniffiConverterTypeCallbackSigner.check_lower(signer) - - _UniffiConverterString.check_lower(input) - - _UniffiConverterString.check_lower(output) - - return _UniffiConverterBytes.lift( - _uniffi_rust_call_with_error(_UniffiConverterTypeError,_UniffiLib.uniffi_c2pa_fn_method_builder_sign_file,self._uniffi_clone_pointer(), - _UniffiConverterTypeCallbackSigner.lower(signer), - _UniffiConverterString.lower(input), - _UniffiConverterString.lower(output)) - ) - - - - - - def to_archive(self, stream: "Stream") -> None: - _UniffiConverterCallbackInterfaceStream.check_lower(stream) - - _uniffi_rust_call_with_error(_UniffiConverterTypeError,_UniffiLib.uniffi_c2pa_fn_method_builder_to_archive,self._uniffi_clone_pointer(), - _UniffiConverterCallbackInterfaceStream.lower(stream)) - - - - - - - def with_json(self, json: "str") -> None: - _UniffiConverterString.check_lower(json) - - _uniffi_rust_call_with_error(_UniffiConverterTypeError,_UniffiLib.uniffi_c2pa_fn_method_builder_with_json,self._uniffi_clone_pointer(), - _UniffiConverterString.lower(json)) - - - - - - - -class _UniffiConverterTypeBuilder: - - @staticmethod - def lift(value: int): - return Builder._make_instance_(value) - - @staticmethod - def check_lower(value: Builder): - if not isinstance(value, Builder): - raise TypeError("Expected Builder instance, {} found".format(type(value).__name__)) - - @staticmethod - def lower(value: BuilderProtocol): - if not isinstance(value, Builder): - raise TypeError("Expected Builder instance, {} found".format(type(value).__name__)) - return value._uniffi_clone_pointer() - - @classmethod - def read(cls, buf: _UniffiRustBuffer): - ptr = buf.read_u64() - if ptr == 0: - raise InternalError("Raw pointer value was null") - return cls.lift(ptr) - - @classmethod - def write(cls, value: BuilderProtocol, buf: _UniffiRustBuffer): - buf.write_u64(cls.lower(value)) - - - -class CallbackSignerProtocol(typing.Protocol): - pass - - -class CallbackSigner: - _pointer: ctypes.c_void_p - def __init__(self, callback: "SignerCallback",alg: "SigningAlg",certs: "bytes",ta_url: "typing.Optional[str]"): - _UniffiConverterCallbackInterfaceSignerCallback.check_lower(callback) - - _UniffiConverterTypeSigningAlg.check_lower(alg) - - _UniffiConverterBytes.check_lower(certs) - - _UniffiConverterOptionalString.check_lower(ta_url) - - self._pointer = _uniffi_rust_call(_UniffiLib.uniffi_c2pa_fn_constructor_callbacksigner_new, - _UniffiConverterCallbackInterfaceSignerCallback.lower(callback), - _UniffiConverterTypeSigningAlg.lower(alg), - _UniffiConverterBytes.lower(certs), - _UniffiConverterOptionalString.lower(ta_url)) - - def __del__(self): - # In case of partial initialization of instances. - pointer = getattr(self, "_pointer", None) - if pointer is not None: - _uniffi_rust_call(_UniffiLib.uniffi_c2pa_fn_free_callbacksigner, pointer) - - def _uniffi_clone_pointer(self): - return _uniffi_rust_call(_UniffiLib.uniffi_c2pa_fn_clone_callbacksigner, self._pointer) - - # Used by alternative constructors or any methods which return this type. - @classmethod - def _make_instance_(cls, pointer): - # Lightly yucky way to bypass the usual __init__ logic - # and just create a new instance with the required pointer. - inst = cls.__new__(cls) - inst._pointer = pointer - return inst - - @classmethod - def new_from_signer(cls, callback: "SignerCallback",alg: "SigningAlg",reserve_size: "int"): - _UniffiConverterCallbackInterfaceSignerCallback.check_lower(callback) - - _UniffiConverterTypeSigningAlg.check_lower(alg) - - _UniffiConverterUInt32.check_lower(reserve_size) - - # Call the (fallible) function before creating any half-baked object instances. - pointer = _uniffi_rust_call(_UniffiLib.uniffi_c2pa_fn_constructor_callbacksigner_new_from_signer, - _UniffiConverterCallbackInterfaceSignerCallback.lower(callback), - _UniffiConverterTypeSigningAlg.lower(alg), - _UniffiConverterUInt32.lower(reserve_size)) - return cls._make_instance_(pointer) - - - - -class _UniffiConverterTypeCallbackSigner: - - @staticmethod - def lift(value: int): - return CallbackSigner._make_instance_(value) - - @staticmethod - def check_lower(value: CallbackSigner): - if not isinstance(value, CallbackSigner): - raise TypeError("Expected CallbackSigner instance, {} found".format(type(value).__name__)) - - @staticmethod - def lower(value: CallbackSignerProtocol): - if not isinstance(value, CallbackSigner): - raise TypeError("Expected CallbackSigner instance, {} found".format(type(value).__name__)) - return value._uniffi_clone_pointer() - - @classmethod - def read(cls, buf: _UniffiRustBuffer): - ptr = buf.read_u64() - if ptr == 0: - raise InternalError("Raw pointer value was null") - return cls.lift(ptr) - - @classmethod - def write(cls, value: CallbackSignerProtocol, buf: _UniffiRustBuffer): - buf.write_u64(cls.lower(value)) - - - -class ReaderProtocol(typing.Protocol): - def from_manifest_data_and_stream(self, manifest_data: "bytes",format: "str",reader: "Stream"): - raise NotImplementedError - def from_stream(self, format: "str",reader: "Stream"): - raise NotImplementedError - def json(self, ): - raise NotImplementedError - def resource_to_stream(self, uri: "str",stream: "Stream"): - raise NotImplementedError - - -class Reader: - _pointer: ctypes.c_void_p - def __init__(self, ): - self._pointer = _uniffi_rust_call(_UniffiLib.uniffi_c2pa_fn_constructor_reader_new,) - - def __del__(self): - # In case of partial initialization of instances. - pointer = getattr(self, "_pointer", None) - if pointer is not None: - _uniffi_rust_call(_UniffiLib.uniffi_c2pa_fn_free_reader, pointer) - - def _uniffi_clone_pointer(self): - return _uniffi_rust_call(_UniffiLib.uniffi_c2pa_fn_clone_reader, self._pointer) - - # Used by alternative constructors or any methods which return this type. - @classmethod - def _make_instance_(cls, pointer): - # Lightly yucky way to bypass the usual __init__ logic - # and just create a new instance with the required pointer. - inst = cls.__new__(cls) - inst._pointer = pointer - return inst - - - def from_manifest_data_and_stream(self, manifest_data: "bytes",format: "str",reader: "Stream") -> "str": - _UniffiConverterBytes.check_lower(manifest_data) - - _UniffiConverterString.check_lower(format) - - _UniffiConverterCallbackInterfaceStream.check_lower(reader) - - return _UniffiConverterString.lift( - _uniffi_rust_call_with_error(_UniffiConverterTypeError,_UniffiLib.uniffi_c2pa_fn_method_reader_from_manifest_data_and_stream,self._uniffi_clone_pointer(), - _UniffiConverterBytes.lower(manifest_data), - _UniffiConverterString.lower(format), - _UniffiConverterCallbackInterfaceStream.lower(reader)) - ) - - - - - - def from_stream(self, format: "str",reader: "Stream") -> "str": - _UniffiConverterString.check_lower(format) - - _UniffiConverterCallbackInterfaceStream.check_lower(reader) - - return _UniffiConverterString.lift( - _uniffi_rust_call_with_error(_UniffiConverterTypeError,_UniffiLib.uniffi_c2pa_fn_method_reader_from_stream,self._uniffi_clone_pointer(), - _UniffiConverterString.lower(format), - _UniffiConverterCallbackInterfaceStream.lower(reader)) - ) - - - - - - def json(self, ) -> "str": - return _UniffiConverterString.lift( - _uniffi_rust_call_with_error(_UniffiConverterTypeError,_UniffiLib.uniffi_c2pa_fn_method_reader_json,self._uniffi_clone_pointer(),) - ) - - - - - - def resource_to_stream(self, uri: "str",stream: "Stream") -> "int": - _UniffiConverterString.check_lower(uri) - - _UniffiConverterCallbackInterfaceStream.check_lower(stream) - - return _UniffiConverterUInt64.lift( - _uniffi_rust_call_with_error(_UniffiConverterTypeError,_UniffiLib.uniffi_c2pa_fn_method_reader_resource_to_stream,self._uniffi_clone_pointer(), - _UniffiConverterString.lower(uri), - _UniffiConverterCallbackInterfaceStream.lower(stream)) - ) - - - - - - -class _UniffiConverterTypeReader: - - @staticmethod - def lift(value: int): - return Reader._make_instance_(value) - - @staticmethod - def check_lower(value: Reader): - if not isinstance(value, Reader): - raise TypeError("Expected Reader instance, {} found".format(type(value).__name__)) - - @staticmethod - def lower(value: ReaderProtocol): - if not isinstance(value, Reader): - raise TypeError("Expected Reader instance, {} found".format(type(value).__name__)) - return value._uniffi_clone_pointer() - - @classmethod - def read(cls, buf: _UniffiRustBuffer): - ptr = buf.read_u64() - if ptr == 0: - raise InternalError("Raw pointer value was null") - return cls.lift(ptr) - - @classmethod - def write(cls, value: ReaderProtocol, buf: _UniffiRustBuffer): - buf.write_u64(cls.lower(value)) - - -# Error -# We want to define each variant as a nested class that's also a subclass, -# which is tricky in Python. To accomplish this we're going to create each -# class separately, then manually add the child classes to the base class's -# __dict__. All of this happens in dummy class to avoid polluting the module -# namespace. -class Error(Exception): - pass - -_UniffiTempError = Error - -class Error: # type: ignore - class Assertion(_UniffiTempError): - def __init__(self, reason): - super().__init__(", ".join([ - "reason={!r}".format(reason), - ])) - self.reason = reason - - def __repr__(self): - return "Error.Assertion({})".format(str(self)) - _UniffiTempError.Assertion = Assertion # type: ignore - class AssertionNotFound(_UniffiTempError): - def __init__(self, reason): - super().__init__(", ".join([ - "reason={!r}".format(reason), - ])) - self.reason = reason - - def __repr__(self): - return "Error.AssertionNotFound({})".format(str(self)) - _UniffiTempError.AssertionNotFound = AssertionNotFound # type: ignore - class Decoding(_UniffiTempError): - def __init__(self, reason): - super().__init__(", ".join([ - "reason={!r}".format(reason), - ])) - self.reason = reason - - def __repr__(self): - return "Error.Decoding({})".format(str(self)) - _UniffiTempError.Decoding = Decoding # type: ignore - class Encoding(_UniffiTempError): - def __init__(self, reason): - super().__init__(", ".join([ - "reason={!r}".format(reason), - ])) - self.reason = reason - - def __repr__(self): - return "Error.Encoding({})".format(str(self)) - _UniffiTempError.Encoding = Encoding # type: ignore - class FileNotFound(_UniffiTempError): - def __init__(self, reason): - super().__init__(", ".join([ - "reason={!r}".format(reason), - ])) - self.reason = reason - - def __repr__(self): - return "Error.FileNotFound({})".format(str(self)) - _UniffiTempError.FileNotFound = FileNotFound # type: ignore - class Io(_UniffiTempError): - def __init__(self, reason): - super().__init__(", ".join([ - "reason={!r}".format(reason), - ])) - self.reason = reason - - def __repr__(self): - return "Error.Io({})".format(str(self)) - _UniffiTempError.Io = Io # type: ignore - class Json(_UniffiTempError): - def __init__(self, reason): - super().__init__(", ".join([ - "reason={!r}".format(reason), - ])) - self.reason = reason - - def __repr__(self): - return "Error.Json({})".format(str(self)) - _UniffiTempError.Json = Json # type: ignore - class Manifest(_UniffiTempError): - def __init__(self, reason): - super().__init__(", ".join([ - "reason={!r}".format(reason), - ])) - self.reason = reason - - def __repr__(self): - return "Error.Manifest({})".format(str(self)) - _UniffiTempError.Manifest = Manifest # type: ignore - class ManifestNotFound(_UniffiTempError): - def __init__(self, reason): - super().__init__(", ".join([ - "reason={!r}".format(reason), - ])) - self.reason = reason - - def __repr__(self): - return "Error.ManifestNotFound({})".format(str(self)) - _UniffiTempError.ManifestNotFound = ManifestNotFound # type: ignore - class NotSupported(_UniffiTempError): - def __init__(self, reason): - super().__init__(", ".join([ - "reason={!r}".format(reason), - ])) - self.reason = reason - - def __repr__(self): - return "Error.NotSupported({})".format(str(self)) - _UniffiTempError.NotSupported = NotSupported # type: ignore - class Other(_UniffiTempError): - def __init__(self, reason): - super().__init__(", ".join([ - "reason={!r}".format(reason), - ])) - self.reason = reason - - def __repr__(self): - return "Error.Other({})".format(str(self)) - _UniffiTempError.Other = Other # type: ignore - class RemoteManifest(_UniffiTempError): - def __init__(self, reason): - super().__init__(", ".join([ - "reason={!r}".format(reason), - ])) - self.reason = reason - - def __repr__(self): - return "Error.RemoteManifest({})".format(str(self)) - _UniffiTempError.RemoteManifest = RemoteManifest # type: ignore - class ResourceNotFound(_UniffiTempError): - def __init__(self, reason): - super().__init__(", ".join([ - "reason={!r}".format(reason), - ])) - self.reason = reason - - def __repr__(self): - return "Error.ResourceNotFound({})".format(str(self)) - _UniffiTempError.ResourceNotFound = ResourceNotFound # type: ignore - class RwLock(_UniffiTempError): - def __init__(self): - pass - - def __repr__(self): - return "Error.RwLock({})".format(str(self)) - _UniffiTempError.RwLock = RwLock # type: ignore - class Signature(_UniffiTempError): - def __init__(self, reason): - super().__init__(", ".join([ - "reason={!r}".format(reason), - ])) - self.reason = reason - - def __repr__(self): - return "Error.Signature({})".format(str(self)) - _UniffiTempError.Signature = Signature # type: ignore - class Verify(_UniffiTempError): - def __init__(self, reason): - super().__init__(", ".join([ - "reason={!r}".format(reason), - ])) - self.reason = reason - - def __repr__(self): - return "Error.Verify({})".format(str(self)) - _UniffiTempError.Verify = Verify # type: ignore - -Error = _UniffiTempError # type: ignore -del _UniffiTempError - - -class _UniffiConverterTypeError(_UniffiConverterRustBuffer): - @staticmethod - def read(buf): - variant = buf.read_i32() - if variant == 1: - return Error.Assertion( - _UniffiConverterString.read(buf), - ) - if variant == 2: - return Error.AssertionNotFound( - _UniffiConverterString.read(buf), - ) - if variant == 3: - return Error.Decoding( - _UniffiConverterString.read(buf), - ) - if variant == 4: - return Error.Encoding( - _UniffiConverterString.read(buf), - ) - if variant == 5: - return Error.FileNotFound( - _UniffiConverterString.read(buf), - ) - if variant == 6: - return Error.Io( - _UniffiConverterString.read(buf), - ) - if variant == 7: - return Error.Json( - _UniffiConverterString.read(buf), - ) - if variant == 8: - return Error.Manifest( - _UniffiConverterString.read(buf), - ) - if variant == 9: - return Error.ManifestNotFound( - _UniffiConverterString.read(buf), - ) - if variant == 10: - return Error.NotSupported( - _UniffiConverterString.read(buf), - ) - if variant == 11: - return Error.Other( - _UniffiConverterString.read(buf), - ) - if variant == 12: - return Error.RemoteManifest( - _UniffiConverterString.read(buf), - ) - if variant == 13: - return Error.ResourceNotFound( - _UniffiConverterString.read(buf), - ) - if variant == 14: - return Error.RwLock( - ) - if variant == 15: - return Error.Signature( - _UniffiConverterString.read(buf), - ) - if variant == 16: - return Error.Verify( - _UniffiConverterString.read(buf), - ) - raise InternalError("Raw enum value doesn't match any cases") - - @staticmethod - def check_lower(value): - if isinstance(value, Error.Assertion): - _UniffiConverterString.check_lower(value.reason) - return - if isinstance(value, Error.AssertionNotFound): - _UniffiConverterString.check_lower(value.reason) - return - if isinstance(value, Error.Decoding): - _UniffiConverterString.check_lower(value.reason) - return - if isinstance(value, Error.Encoding): - _UniffiConverterString.check_lower(value.reason) - return - if isinstance(value, Error.FileNotFound): - _UniffiConverterString.check_lower(value.reason) - return - if isinstance(value, Error.Io): - _UniffiConverterString.check_lower(value.reason) - return - if isinstance(value, Error.Json): - _UniffiConverterString.check_lower(value.reason) - return - if isinstance(value, Error.Manifest): - _UniffiConverterString.check_lower(value.reason) - return - if isinstance(value, Error.ManifestNotFound): - _UniffiConverterString.check_lower(value.reason) - return - if isinstance(value, Error.NotSupported): - _UniffiConverterString.check_lower(value.reason) - return - if isinstance(value, Error.Other): - _UniffiConverterString.check_lower(value.reason) - return - if isinstance(value, Error.RemoteManifest): - _UniffiConverterString.check_lower(value.reason) - return - if isinstance(value, Error.ResourceNotFound): - _UniffiConverterString.check_lower(value.reason) - return - if isinstance(value, Error.RwLock): - return - if isinstance(value, Error.Signature): - _UniffiConverterString.check_lower(value.reason) - return - if isinstance(value, Error.Verify): - _UniffiConverterString.check_lower(value.reason) - return - - @staticmethod - def write(value, buf): - if isinstance(value, Error.Assertion): - buf.write_i32(1) - _UniffiConverterString.write(value.reason, buf) - if isinstance(value, Error.AssertionNotFound): - buf.write_i32(2) - _UniffiConverterString.write(value.reason, buf) - if isinstance(value, Error.Decoding): - buf.write_i32(3) - _UniffiConverterString.write(value.reason, buf) - if isinstance(value, Error.Encoding): - buf.write_i32(4) - _UniffiConverterString.write(value.reason, buf) - if isinstance(value, Error.FileNotFound): - buf.write_i32(5) - _UniffiConverterString.write(value.reason, buf) - if isinstance(value, Error.Io): - buf.write_i32(6) - _UniffiConverterString.write(value.reason, buf) - if isinstance(value, Error.Json): - buf.write_i32(7) - _UniffiConverterString.write(value.reason, buf) - if isinstance(value, Error.Manifest): - buf.write_i32(8) - _UniffiConverterString.write(value.reason, buf) - if isinstance(value, Error.ManifestNotFound): - buf.write_i32(9) - _UniffiConverterString.write(value.reason, buf) - if isinstance(value, Error.NotSupported): - buf.write_i32(10) - _UniffiConverterString.write(value.reason, buf) - if isinstance(value, Error.Other): - buf.write_i32(11) - _UniffiConverterString.write(value.reason, buf) - if isinstance(value, Error.RemoteManifest): - buf.write_i32(12) - _UniffiConverterString.write(value.reason, buf) - if isinstance(value, Error.ResourceNotFound): - buf.write_i32(13) - _UniffiConverterString.write(value.reason, buf) - if isinstance(value, Error.RwLock): - buf.write_i32(14) - if isinstance(value, Error.Signature): - buf.write_i32(15) - _UniffiConverterString.write(value.reason, buf) - if isinstance(value, Error.Verify): - buf.write_i32(16) - _UniffiConverterString.write(value.reason, buf) - - - - - -class SeekMode(enum.Enum): - START = 0 - - END = 1 - - CURRENT = 2 - - - -class _UniffiConverterTypeSeekMode(_UniffiConverterRustBuffer): - @staticmethod - def read(buf): - variant = buf.read_i32() - if variant == 1: - return SeekMode.START - if variant == 2: - return SeekMode.END - if variant == 3: - return SeekMode.CURRENT - raise InternalError("Raw enum value doesn't match any cases") - - @staticmethod - def check_lower(value): - if value == SeekMode.START: - return - if value == SeekMode.END: - return - if value == SeekMode.CURRENT: - return - raise ValueError(value) - - @staticmethod - def write(value, buf): - if value == SeekMode.START: - buf.write_i32(1) - if value == SeekMode.END: - buf.write_i32(2) - if value == SeekMode.CURRENT: - buf.write_i32(3) - - - - - - - -class SigningAlg(enum.Enum): - ES256 = 0 - - ES384 = 1 - - ES512 = 2 - - PS256 = 3 - - PS384 = 4 - - PS512 = 5 - - ED25519 = 6 - - - -class _UniffiConverterTypeSigningAlg(_UniffiConverterRustBuffer): - @staticmethod - def read(buf): - variant = buf.read_i32() - if variant == 1: - return SigningAlg.ES256 - if variant == 2: - return SigningAlg.ES384 - if variant == 3: - return SigningAlg.ES512 - if variant == 4: - return SigningAlg.PS256 - if variant == 5: - return SigningAlg.PS384 - if variant == 6: - return SigningAlg.PS512 - if variant == 7: - return SigningAlg.ED25519 - raise InternalError("Raw enum value doesn't match any cases") - - @staticmethod - def check_lower(value): - if value == SigningAlg.ES256: - return - if value == SigningAlg.ES384: - return - if value == SigningAlg.ES512: - return - if value == SigningAlg.PS256: - return - if value == SigningAlg.PS384: - return - if value == SigningAlg.PS512: - return - if value == SigningAlg.ED25519: - return - raise ValueError(value) - - @staticmethod - def write(value, buf): - if value == SigningAlg.ES256: - buf.write_i32(1) - if value == SigningAlg.ES384: - buf.write_i32(2) - if value == SigningAlg.ES512: - buf.write_i32(3) - if value == SigningAlg.PS256: - buf.write_i32(4) - if value == SigningAlg.PS384: - buf.write_i32(5) - if value == SigningAlg.PS512: - buf.write_i32(6) - if value == SigningAlg.ED25519: - buf.write_i32(7) - - - - - -class SignerCallback(typing.Protocol): - def sign(self, data: "bytes"): - raise NotImplementedError -# Magic number for the Rust proxy to call using the same mechanism as every other method, -# to free the callback once it's dropped by Rust. -_UNIFFI_IDX_CALLBACK_FREE = 0 -# Return codes for callback calls -_UNIFFI_CALLBACK_SUCCESS = 0 -_UNIFFI_CALLBACK_ERROR = 1 -_UNIFFI_CALLBACK_UNEXPECTED_ERROR = 2 - -class _UniffiCallbackInterfaceFfiConverter: - _handle_map = _UniffiHandleMap() - - @classmethod - def lift(cls, handle): - return cls._handle_map.get(handle) - - @classmethod - def read(cls, buf): - handle = buf.read_u64() - cls.lift(handle) - - @classmethod - def check_lower(cls, cb): - pass - - @classmethod - def lower(cls, cb): - handle = cls._handle_map.insert(cb) - return handle - - @classmethod - def write(cls, cb, buf): - buf.write_u64(cls.lower(cb)) - -# Put all the bits inside a class to keep the top-level namespace clean -class _UniffiTraitImplSignerCallback: - # For each method, generate a callback function to pass to Rust - - @_UNIFFI_CALLBACK_INTERFACE_SIGNER_CALLBACK_METHOD0 - def sign( - uniffi_handle, - data, - uniffi_out_return, - uniffi_call_status_ptr, - ): - uniffi_obj = _UniffiConverterCallbackInterfaceSignerCallback._handle_map.get(uniffi_handle) - def make_call(): - args = (_UniffiConverterBytes.lift(data), ) - method = uniffi_obj.sign - return method(*args) - - - def write_return_value(v): - uniffi_out_return[0] = _UniffiConverterBytes.lower(v) - _uniffi_trait_interface_call_with_error( - uniffi_call_status_ptr.contents, - make_call, - write_return_value, - Error, - _UniffiConverterTypeError.lower, - ) - - @_UNIFFI_CALLBACK_INTERFACE_FREE - def _uniffi_free(uniffi_handle): - _UniffiConverterCallbackInterfaceSignerCallback._handle_map.remove(uniffi_handle) - - # Generate the FFI VTable. This has a field for each callback interface method. - _uniffi_vtable = _UniffiVTableCallbackInterfaceSignerCallback( - sign, - _uniffi_free - ) - # Send Rust a pointer to the VTable. Note: this means we need to keep the struct alive forever, - # or else bad things will happen when Rust tries to access it. - _UniffiLib.uniffi_c2pa_fn_init_callback_vtable_signercallback(ctypes.byref(_uniffi_vtable)) - -# The _UniffiConverter which transforms the Callbacks in to Handles to pass to Rust. -_UniffiConverterCallbackInterfaceSignerCallback = _UniffiCallbackInterfaceFfiConverter() - - - -class Stream(typing.Protocol): - def read_stream(self, length: "int"): - raise NotImplementedError - def seek_stream(self, pos: "int",mode: "SeekMode"): - raise NotImplementedError - def write_stream(self, data: "bytes"): - raise NotImplementedError - - -# Put all the bits inside a class to keep the top-level namespace clean -class _UniffiTraitImplStream: - # For each method, generate a callback function to pass to Rust - - @_UNIFFI_CALLBACK_INTERFACE_STREAM_METHOD0 - def read_stream( - uniffi_handle, - length, - uniffi_out_return, - uniffi_call_status_ptr, - ): - uniffi_obj = _UniffiConverterCallbackInterfaceStream._handle_map.get(uniffi_handle) - def make_call(): - args = (_UniffiConverterUInt64.lift(length), ) - method = uniffi_obj.read_stream - return method(*args) - - - def write_return_value(v): - uniffi_out_return[0] = _UniffiConverterBytes.lower(v) - _uniffi_trait_interface_call_with_error( - uniffi_call_status_ptr.contents, - make_call, - write_return_value, - Error, - _UniffiConverterTypeError.lower, - ) - - @_UNIFFI_CALLBACK_INTERFACE_STREAM_METHOD1 - def seek_stream( - uniffi_handle, - pos, - mode, - uniffi_out_return, - uniffi_call_status_ptr, - ): - uniffi_obj = _UniffiConverterCallbackInterfaceStream._handle_map.get(uniffi_handle) - def make_call(): - args = (_UniffiConverterInt64.lift(pos), _UniffiConverterTypeSeekMode.lift(mode), ) - method = uniffi_obj.seek_stream - return method(*args) - - - def write_return_value(v): - uniffi_out_return[0] = _UniffiConverterUInt64.lower(v) - _uniffi_trait_interface_call_with_error( - uniffi_call_status_ptr.contents, - make_call, - write_return_value, - Error, - _UniffiConverterTypeError.lower, - ) - - @_UNIFFI_CALLBACK_INTERFACE_STREAM_METHOD2 - def write_stream( - uniffi_handle, - data, - uniffi_out_return, - uniffi_call_status_ptr, - ): - uniffi_obj = _UniffiConverterCallbackInterfaceStream._handle_map.get(uniffi_handle) - def make_call(): - args = (_UniffiConverterBytes.lift(data), ) - method = uniffi_obj.write_stream - return method(*args) - - - def write_return_value(v): - uniffi_out_return[0] = _UniffiConverterUInt64.lower(v) - _uniffi_trait_interface_call_with_error( - uniffi_call_status_ptr.contents, - make_call, - write_return_value, - Error, - _UniffiConverterTypeError.lower, - ) - - @_UNIFFI_CALLBACK_INTERFACE_FREE - def _uniffi_free(uniffi_handle): - _UniffiConverterCallbackInterfaceStream._handle_map.remove(uniffi_handle) - - # Generate the FFI VTable. This has a field for each callback interface method. - _uniffi_vtable = _UniffiVTableCallbackInterfaceStream( - read_stream, - seek_stream, - write_stream, - _uniffi_free - ) - # Send Rust a pointer to the VTable. Note: this means we need to keep the struct alive forever, - # or else bad things will happen when Rust tries to access it. - _UniffiLib.uniffi_c2pa_fn_init_callback_vtable_stream(ctypes.byref(_uniffi_vtable)) - -# The _UniffiConverter which transforms the Callbacks in to Handles to pass to Rust. -_UniffiConverterCallbackInterfaceStream = _UniffiCallbackInterfaceFfiConverter() - - - -class _UniffiConverterOptionalString(_UniffiConverterRustBuffer): - @classmethod - def check_lower(cls, value): - if value is not None: - _UniffiConverterString.check_lower(value) - - @classmethod - def write(cls, value, buf): - if value is None: - buf.write_u8(0) - return - - buf.write_u8(1) - _UniffiConverterString.write(value, buf) - - @classmethod - def read(cls, buf): - flag = buf.read_u8() - if flag == 0: - return None - elif flag == 1: - return _UniffiConverterString.read(buf) - else: - raise InternalError("Unexpected flag byte for optional type") - -# Async support - -def sdk_version() -> "str": - return _UniffiConverterString.lift(_uniffi_rust_call(_UniffiLib.uniffi_c2pa_fn_func_sdk_version,)) - - -def version() -> "str": - return _UniffiConverterString.lift(_uniffi_rust_call(_UniffiLib.uniffi_c2pa_fn_func_version,)) - - -__all__ = [ - "InternalError", - "Error", - "SeekMode", - "SigningAlg", - "sdk_version", - "version", - "Builder", - "CallbackSigner", - "Reader", - "SignerCallback", - "Stream", -] - From 9b9363938dd4c32a4bd7627e85110e6138a0a0b3 Mon Sep 17 00:00:00 2001 From: Tania Mathern Date: Wed, 13 Nov 2024 22:35:12 -0800 Subject: [PATCH 11/25] WIP --- .gitignore | 2 +- c2pa/c2pa/.gitkeep | 0 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 c2pa/c2pa/.gitkeep diff --git a/.gitignore b/.gitignore index 79539b6c..f66cc772 100644 --- a/.gitignore +++ b/.gitignore @@ -22,7 +22,7 @@ __pycache__/ .pytest_cache/ dist -c2pa/c2pa/libuniffi_c2pa.* +c2pa/c2pa # Mac OS X files .DS_Store diff --git a/c2pa/c2pa/.gitkeep b/c2pa/c2pa/.gitkeep deleted file mode 100644 index e69de29b..00000000 From eaa293bc6c1d583daf3a4dad2a91b582f5cf7de3 Mon Sep 17 00:00:00 2001 From: Tania Mathern Date: Wed, 13 Nov 2024 22:53:47 -0800 Subject: [PATCH 12/25] Fix version for build --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 5f092533..77cfd509 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["maturin>=1.7.4,<2.0","uniffi_bindgen>=0.24,<0.25"] +requires = ["maturin>=1.7.4,<2.0","uniffi_bindgen>=0.28,<0.25"] build-backend = "maturin" [project] From 41d0040030a2316df8f88bfdf49b4b59887db097 Mon Sep 17 00:00:00 2001 From: Tania Mathern Date: Wed, 13 Nov 2024 23:14:29 -0800 Subject: [PATCH 13/25] WIP --- src/lib.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index ca14148d..8355f6e8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,6 +49,18 @@ pub struct Reader { reader: RwLock, } +impl From for Reader { + fn from(reader: c2pa::Reader) -> Self { + Self { reader: RwLock::new(reader) } + } +} + +impl Into for Reader { + fn into(self) -> c2pa::Reader { + self.reader.into_inner().unwrap() + } +} + impl Default for Reader { fn default() -> Self { Self::new() From 5975f67ff81416c845df2211d02197b5ae0e7db7 Mon Sep 17 00:00:00 2001 From: Tania Mathern Date: Wed, 13 Nov 2024 23:27:52 -0800 Subject: [PATCH 14/25] Name change --- Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 7de7353f..fe27156d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,6 @@ authors = ["Gavin Peacock Date: Thu, 14 Nov 2024 09:06:11 -0800 Subject: [PATCH 15/25] Update .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f66cc772..c96c5aa5 100644 --- a/.gitignore +++ b/.gitignore @@ -22,7 +22,7 @@ __pycache__/ .pytest_cache/ dist -c2pa/c2pa +c2pa/c2pa/ # Mac OS X files .DS_Store From 824e93964940d79b8670facadec51293ac6bd6ca Mon Sep 17 00:00:00 2001 From: tmathern <60901087+tmathern@users.noreply.github.com> Date: Thu, 14 Nov 2024 09:06:51 -0800 Subject: [PATCH 16/25] Update lib.rs --- src/lib.rs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 8355f6e8..ca14148d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,18 +49,6 @@ pub struct Reader { reader: RwLock, } -impl From for Reader { - fn from(reader: c2pa::Reader) -> Self { - Self { reader: RwLock::new(reader) } - } -} - -impl Into for Reader { - fn into(self) -> c2pa::Reader { - self.reader.into_inner().unwrap() - } -} - impl Default for Reader { fn default() -> Self { Self::new() From 427790c16b39cecaca14b8d0aa17ef6dd2b7e6b3 Mon Sep 17 00:00:00 2001 From: tmathern <60901087+tmathern@users.noreply.github.com> Date: Thu, 14 Nov 2024 09:07:29 -0800 Subject: [PATCH 17/25] Update Makefile --- Makefile | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index fbd5bb41..2a6f2f71 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,7 @@ # Start from clean env: Delete `.venv`, then `python3 -m venv .venv` # Pre-requisite: Python virtual environment is active (source .venv/bin/activate) build-python: release - python3 -m venv .venv - source .venv/bin/activate - python3 -m pip install -r requirements.txt - python3 -m pip install -r requirements-dev.txt - maturin develop + python3 -m venv .venv + source .venv/bin/activate + python3 -m pip install -r requirements.txt + maturin develop From 1eeb95ff9f45aa922ce67c6fece958bc169de254 Mon Sep 17 00:00:00 2001 From: Tania Mathern Date: Thu, 14 Nov 2024 09:09:09 -0800 Subject: [PATCH 18/25] Reexport Signer --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index ca14148d..d84e7b8b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,7 +14,7 @@ use std::env; use std::sync::RwLock; -pub use c2pa::SigningAlg; +pub use c2pa::{Signer, SigningAlg}; /// these all need to be public so that the uniffi macro can see them mod error; From 83170e0fdeb0792cd0f449a7b8aa3f4a1c66792d Mon Sep 17 00:00:00 2001 From: Tania Mathern Date: Thu, 14 Nov 2024 09:21:15 -0800 Subject: [PATCH 19/25] Fix pyproject build --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 77cfd509..5d973f29 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["maturin>=1.7.4,<2.0","uniffi_bindgen>=0.28,<0.25"] +requires = ["maturin>=1.7.4,<2.0","uniffi_bindgen>=0.28,<0.30"] build-backend = "maturin" [project] From 6058f951cf133075a221bbf381f8e6f3932023c3 Mon Sep 17 00:00:00 2001 From: Tania Mathern Date: Thu, 14 Nov 2024 11:44:32 -0800 Subject: [PATCH 20/25] Fix --- c2pa/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/c2pa/__init__.py b/c2pa/__init__.py index d4036af3..9832e6e9 100644 --- a/c2pa/__init__.py +++ b/c2pa/__init__.py @@ -12,6 +12,6 @@ # each license. from .c2pa_api import Reader, Builder, create_signer, create_remote_signer, sign_ps256 -from .c2pa import Error, SigningAlg, CallbackSigner, sdk_version, version +from .c2pa import Error, SigningAlg, CallbackSigner, sdk_version, version, _UniffiConverterTypeSigningAlg, _UniffiRustBuffer -__all__ = ['Reader', 'Builder', 'CallbackSigner', 'create_signer', 'sign_ps256', 'Error', 'SigningAlg', 'sdk_version', 'version', 'create_remote_signer'] \ No newline at end of file +__all__ = ['Reader', 'Builder', 'CallbackSigner', 'create_signer', 'sign_ps256', 'Error', 'SigningAlg', 'sdk_version', 'version', 'create_remote_signer', '_UniffiConverterTypeSigningAlg', '_UniffiRustBuffer'] \ No newline at end of file From 42fe14ea117d431e9e90b27b2ef0a91917588e5e Mon Sep 17 00:00:00 2001 From: tmathern <60901087+tmathern@users.noreply.github.com> Date: Thu, 14 Nov 2024 13:52:06 -0800 Subject: [PATCH 21/25] Update __init__.py --- c2pa/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/c2pa/__init__.py b/c2pa/__init__.py index 9832e6e9..3a25a80c 100644 --- a/c2pa/__init__.py +++ b/c2pa/__init__.py @@ -12,6 +12,7 @@ # each license. from .c2pa_api import Reader, Builder, create_signer, create_remote_signer, sign_ps256 -from .c2pa import Error, SigningAlg, CallbackSigner, sdk_version, version, _UniffiConverterTypeSigningAlg, _UniffiRustBuffer +from .c2pa import Error, SigningAlg, CallbackSigner, sdk_version, version +from .c2pa.c2pa import _UniffiConverterTypeSigningAlg, _UniffiRustBuffer -__all__ = ['Reader', 'Builder', 'CallbackSigner', 'create_signer', 'sign_ps256', 'Error', 'SigningAlg', 'sdk_version', 'version', 'create_remote_signer', '_UniffiConverterTypeSigningAlg', '_UniffiRustBuffer'] \ No newline at end of file +__all__ = ['Reader', 'Builder', 'CallbackSigner', 'create_signer', 'sign_ps256', 'Error', 'SigningAlg', 'sdk_version', 'version', 'create_remote_signer', '_UniffiConverterTypeSigningAlg', '_UniffiRustBuffer'] From 4ffae83e1285b1ae1d10aaff48f9df60c8df18d7 Mon Sep 17 00:00:00 2001 From: Tania Mathern Date: Thu, 14 Nov 2024 15:11:29 -0800 Subject: [PATCH 22/25] Make file --- Makefile | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 2a6f2f71..0e087b2b 100644 --- a/Makefile +++ b/Makefile @@ -2,8 +2,9 @@ # Start from clean env: Delete `.venv`, then `python3 -m venv .venv` # Pre-requisite: Python virtual environment is active (source .venv/bin/activate) -build-python: release - python3 -m venv .venv - source .venv/bin/activate - python3 -m pip install -r requirements.txt - maturin develop +build-python: + python3 -m venv .venv + python3 -m pip uninstall maturin + python3 -m pip uninstall uniffi + python3 -m pip install -r requirements.txt + maturin develop From 0e318e2efc5130aabccff6c7fcb6e3df1ff3539c Mon Sep 17 00:00:00 2001 From: Tania Mathern Date: Thu, 14 Nov 2024 15:13:37 -0800 Subject: [PATCH 23/25] One more change --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 0e087b2b..035e1819 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ # Pre-requisite: Python virtual environment is active (source .venv/bin/activate) build-python: python3 -m venv .venv + rm -rf c2pa/c2pa python3 -m pip uninstall maturin python3 -m pip uninstall uniffi python3 -m pip install -r requirements.txt From 1e3c05e2f51f3649a578f9aa4da17b6d7d9a3d46 Mon Sep 17 00:00:00 2001 From: Tania Mathern Date: Thu, 14 Nov 2024 15:15:32 -0800 Subject: [PATCH 24/25] venv --- Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile b/Makefile index 035e1819..786bd247 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,6 @@ # Start from clean env: Delete `.venv`, then `python3 -m venv .venv` # Pre-requisite: Python virtual environment is active (source .venv/bin/activate) build-python: - python3 -m venv .venv rm -rf c2pa/c2pa python3 -m pip uninstall maturin python3 -m pip uninstall uniffi From 8763a4c0f17c2af2c55edfc10b1a7c19c035120a Mon Sep 17 00:00:00 2001 From: Tania Mathern Date: Thu, 14 Nov 2024 15:22:32 -0800 Subject: [PATCH 25/25] Auto-ok uninstall --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 786bd247..c8749d97 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ # Pre-requisite: Python virtual environment is active (source .venv/bin/activate) build-python: rm -rf c2pa/c2pa - python3 -m pip uninstall maturin - python3 -m pip uninstall uniffi + python3 -m pip uninstall -y maturin + python3 -m pip uninstall -y uniffi python3 -m pip install -r requirements.txt maturin develop