diff --git a/MobileSdkRs/Sources/MobileSdkRs/mobile_sdk_rs.swift b/MobileSdkRs/Sources/MobileSdkRs/mobile_sdk_rs.swift index 914c26b9..bf1bb5b9 100644 --- a/MobileSdkRs/Sources/MobileSdkRs/mobile_sdk_rs.swift +++ b/MobileSdkRs/Sources/MobileSdkRs/mobile_sdk_rs.swift @@ -4236,7 +4236,7 @@ public protocol StorageManagerInterface : AnyObject { * key - The key to add * value - The value to add under the key. */ - func add(key: Key, value: Value) throws + func add(key: Key, value: Value) async throws /** * Function: get @@ -4244,14 +4244,14 @@ public protocol StorageManagerInterface : AnyObject { * Callback function pointer to native (kotlin/swift) code for * getting a key. */ - func get(key: Key) throws -> Value? + func get(key: Key) async throws -> Value? /** * Function: list * * Callback function pointer for listing available keys. */ - func list() throws -> [Key] + func list() async throws -> [Key] /** * Function: remove @@ -4261,7 +4261,7 @@ public protocol StorageManagerInterface : AnyObject { * particular, it must treat removing a non-existent key as a normal and * expected circumstance, simply returning () and not an error. */ - func remove(key: Key) throws + func remove(key: Key) async throws } @@ -4328,12 +4328,21 @@ open class StorageManagerInterfaceImpl: * key - The key to add * value - The value to add under the key. */ -open func add(key: Key, value: Value)throws {try rustCallWithError(FfiConverterTypeStorageManagerError.lift) { - uniffi_mobile_sdk_rs_fn_method_storagemanagerinterface_add(self.uniffiClonePointer(), - FfiConverterTypeKey.lower(key), - FfiConverterTypeValue.lower(value),$0 - ) -} +open func add(key: Key, value: Value)async throws { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_mobile_sdk_rs_fn_method_storagemanagerinterface_add( + self.uniffiClonePointer(), + FfiConverterTypeKey.lower(key),FfiConverterTypeValue.lower(value) + ) + }, + pollFunc: ffi_mobile_sdk_rs_rust_future_poll_void, + completeFunc: ffi_mobile_sdk_rs_rust_future_complete_void, + freeFunc: ffi_mobile_sdk_rs_rust_future_free_void, + liftFunc: { $0 }, + errorHandler: FfiConverterTypeStorageManagerError.lift + ) } /** @@ -4342,12 +4351,21 @@ open func add(key: Key, value: Value)throws {try rustCallWithError(FfiConverter * Callback function pointer to native (kotlin/swift) code for * getting a key. */ -open func get(key: Key)throws -> Value? { - return try FfiConverterOptionTypeValue.lift(try rustCallWithError(FfiConverterTypeStorageManagerError.lift) { - uniffi_mobile_sdk_rs_fn_method_storagemanagerinterface_get(self.uniffiClonePointer(), - FfiConverterTypeKey.lower(key),$0 - ) -}) +open func get(key: Key)async throws -> Value? { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_mobile_sdk_rs_fn_method_storagemanagerinterface_get( + self.uniffiClonePointer(), + FfiConverterTypeKey.lower(key) + ) + }, + pollFunc: ffi_mobile_sdk_rs_rust_future_poll_rust_buffer, + completeFunc: ffi_mobile_sdk_rs_rust_future_complete_rust_buffer, + freeFunc: ffi_mobile_sdk_rs_rust_future_free_rust_buffer, + liftFunc: FfiConverterOptionTypeValue.lift, + errorHandler: FfiConverterTypeStorageManagerError.lift + ) } /** @@ -4355,11 +4373,21 @@ open func get(key: Key)throws -> Value? { * * Callback function pointer for listing available keys. */ -open func list()throws -> [Key] { - return try FfiConverterSequenceTypeKey.lift(try rustCallWithError(FfiConverterTypeStorageManagerError.lift) { - uniffi_mobile_sdk_rs_fn_method_storagemanagerinterface_list(self.uniffiClonePointer(),$0 - ) -}) +open func list()async throws -> [Key] { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_mobile_sdk_rs_fn_method_storagemanagerinterface_list( + self.uniffiClonePointer() + + ) + }, + pollFunc: ffi_mobile_sdk_rs_rust_future_poll_rust_buffer, + completeFunc: ffi_mobile_sdk_rs_rust_future_complete_rust_buffer, + freeFunc: ffi_mobile_sdk_rs_rust_future_free_rust_buffer, + liftFunc: FfiConverterSequenceTypeKey.lift, + errorHandler: FfiConverterTypeStorageManagerError.lift + ) } /** @@ -4370,11 +4398,21 @@ open func list()throws -> [Key] { * particular, it must treat removing a non-existent key as a normal and * expected circumstance, simply returning () and not an error. */ -open func remove(key: Key)throws {try rustCallWithError(FfiConverterTypeStorageManagerError.lift) { - uniffi_mobile_sdk_rs_fn_method_storagemanagerinterface_remove(self.uniffiClonePointer(), - FfiConverterTypeKey.lower(key),$0 - ) -} +open func remove(key: Key)async throws { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_mobile_sdk_rs_fn_method_storagemanagerinterface_remove( + self.uniffiClonePointer(), + FfiConverterTypeKey.lower(key) + ) + }, + pollFunc: ffi_mobile_sdk_rs_rust_future_poll_void, + completeFunc: ffi_mobile_sdk_rs_rust_future_complete_void, + freeFunc: ffi_mobile_sdk_rs_rust_future_free_void, + liftFunc: { $0 }, + errorHandler: FfiConverterTypeStorageManagerError.lift + ) } @@ -4391,101 +4429,169 @@ fileprivate struct UniffiCallbackInterfaceStorageManagerInterface { uniffiHandle: UInt64, key: RustBuffer, value: RustBuffer, - uniffiOutReturn: UnsafeMutableRawPointer, - uniffiCallStatus: UnsafeMutablePointer + uniffiFutureCallback: @escaping UniffiForeignFutureCompleteVoid, + uniffiCallbackData: UInt64, + uniffiOutReturn: UnsafeMutablePointer ) in let makeCall = { - () throws -> () in + () async throws -> () in guard let uniffiObj = try? FfiConverterTypeStorageManagerInterface.handleMap.get(handle: uniffiHandle) else { throw UniffiInternalError.unexpectedStaleHandle } - return try uniffiObj.add( + return try await uniffiObj.add( key: try FfiConverterTypeKey.lift(key), value: try FfiConverterTypeValue.lift(value) ) } - - let writeReturn = { () } - uniffiTraitInterfaceCallWithError( - callStatus: uniffiCallStatus, + let uniffiHandleSuccess = { (returnValue: ()) in + uniffiFutureCallback( + uniffiCallbackData, + UniffiForeignFutureStructVoid( + callStatus: RustCallStatus() + ) + ) + } + let uniffiHandleError = { (statusCode, errorBuf) in + uniffiFutureCallback( + uniffiCallbackData, + UniffiForeignFutureStructVoid( + callStatus: RustCallStatus(code: statusCode, errorBuf: errorBuf) + ) + ) + } + let uniffiForeignFuture = uniffiTraitInterfaceCallAsyncWithError( makeCall: makeCall, - writeReturn: writeReturn, + handleSuccess: uniffiHandleSuccess, + handleError: uniffiHandleError, lowerError: FfiConverterTypeStorageManagerError.lower ) + uniffiOutReturn.pointee = uniffiForeignFuture }, get: { ( uniffiHandle: UInt64, key: RustBuffer, - uniffiOutReturn: UnsafeMutablePointer, - uniffiCallStatus: UnsafeMutablePointer + uniffiFutureCallback: @escaping UniffiForeignFutureCompleteRustBuffer, + uniffiCallbackData: UInt64, + uniffiOutReturn: UnsafeMutablePointer ) in let makeCall = { - () throws -> Value? in + () async throws -> Value? in guard let uniffiObj = try? FfiConverterTypeStorageManagerInterface.handleMap.get(handle: uniffiHandle) else { throw UniffiInternalError.unexpectedStaleHandle } - return try uniffiObj.get( + return try await uniffiObj.get( key: try FfiConverterTypeKey.lift(key) ) } - - let writeReturn = { uniffiOutReturn.pointee = FfiConverterOptionTypeValue.lower($0) } - uniffiTraitInterfaceCallWithError( - callStatus: uniffiCallStatus, + let uniffiHandleSuccess = { (returnValue: Value?) in + uniffiFutureCallback( + uniffiCallbackData, + UniffiForeignFutureStructRustBuffer( + returnValue: FfiConverterOptionTypeValue.lower(returnValue), + callStatus: RustCallStatus() + ) + ) + } + let uniffiHandleError = { (statusCode, errorBuf) in + uniffiFutureCallback( + uniffiCallbackData, + UniffiForeignFutureStructRustBuffer( + returnValue: RustBuffer.empty(), + callStatus: RustCallStatus(code: statusCode, errorBuf: errorBuf) + ) + ) + } + let uniffiForeignFuture = uniffiTraitInterfaceCallAsyncWithError( makeCall: makeCall, - writeReturn: writeReturn, + handleSuccess: uniffiHandleSuccess, + handleError: uniffiHandleError, lowerError: FfiConverterTypeStorageManagerError.lower ) + uniffiOutReturn.pointee = uniffiForeignFuture }, list: { ( uniffiHandle: UInt64, - uniffiOutReturn: UnsafeMutablePointer, - uniffiCallStatus: UnsafeMutablePointer + uniffiFutureCallback: @escaping UniffiForeignFutureCompleteRustBuffer, + uniffiCallbackData: UInt64, + uniffiOutReturn: UnsafeMutablePointer ) in let makeCall = { - () throws -> [Key] in + () async throws -> [Key] in guard let uniffiObj = try? FfiConverterTypeStorageManagerInterface.handleMap.get(handle: uniffiHandle) else { throw UniffiInternalError.unexpectedStaleHandle } - return try uniffiObj.list( + return try await uniffiObj.list( ) } - - let writeReturn = { uniffiOutReturn.pointee = FfiConverterSequenceTypeKey.lower($0) } - uniffiTraitInterfaceCallWithError( - callStatus: uniffiCallStatus, + let uniffiHandleSuccess = { (returnValue: [Key]) in + uniffiFutureCallback( + uniffiCallbackData, + UniffiForeignFutureStructRustBuffer( + returnValue: FfiConverterSequenceTypeKey.lower(returnValue), + callStatus: RustCallStatus() + ) + ) + } + let uniffiHandleError = { (statusCode, errorBuf) in + uniffiFutureCallback( + uniffiCallbackData, + UniffiForeignFutureStructRustBuffer( + returnValue: RustBuffer.empty(), + callStatus: RustCallStatus(code: statusCode, errorBuf: errorBuf) + ) + ) + } + let uniffiForeignFuture = uniffiTraitInterfaceCallAsyncWithError( makeCall: makeCall, - writeReturn: writeReturn, + handleSuccess: uniffiHandleSuccess, + handleError: uniffiHandleError, lowerError: FfiConverterTypeStorageManagerError.lower ) + uniffiOutReturn.pointee = uniffiForeignFuture }, remove: { ( uniffiHandle: UInt64, key: RustBuffer, - uniffiOutReturn: UnsafeMutableRawPointer, - uniffiCallStatus: UnsafeMutablePointer + uniffiFutureCallback: @escaping UniffiForeignFutureCompleteVoid, + uniffiCallbackData: UInt64, + uniffiOutReturn: UnsafeMutablePointer ) in let makeCall = { - () throws -> () in + () async throws -> () in guard let uniffiObj = try? FfiConverterTypeStorageManagerInterface.handleMap.get(handle: uniffiHandle) else { throw UniffiInternalError.unexpectedStaleHandle } - return try uniffiObj.remove( + return try await uniffiObj.remove( key: try FfiConverterTypeKey.lift(key) ) } - - let writeReturn = { () } - uniffiTraitInterfaceCallWithError( - callStatus: uniffiCallStatus, + let uniffiHandleSuccess = { (returnValue: ()) in + uniffiFutureCallback( + uniffiCallbackData, + UniffiForeignFutureStructVoid( + callStatus: RustCallStatus() + ) + ) + } + let uniffiHandleError = { (statusCode, errorBuf) in + uniffiFutureCallback( + uniffiCallbackData, + UniffiForeignFutureStructVoid( + callStatus: RustCallStatus(code: statusCode, errorBuf: errorBuf) + ) + ) + } + let uniffiForeignFuture = uniffiTraitInterfaceCallAsyncWithError( makeCall: makeCall, - writeReturn: writeReturn, + handleSuccess: uniffiHandleSuccess, + handleError: uniffiHandleError, lowerError: FfiConverterTypeStorageManagerError.lower ) + uniffiOutReturn.pointee = uniffiForeignFuture }, uniffiFree: { (uniffiHandle: UInt64) -> () in let result = try? FfiConverterTypeStorageManagerInterface.handleMap.remove(handle: uniffiHandle) @@ -4982,32 +5088,32 @@ public protocol VdcCollectionProtocol : AnyObject { /** * Add a credential to the set. */ - func add(credential: Credential) throws + func add(credential: Credential) async throws /** * Get a list of all the credentials. */ - func allEntries() throws -> [Uuid] + func allEntries() async throws -> [Uuid] /** * Get a list of all the credentials that match a specified type. */ - func allEntriesByType(ctype: CredentialType) throws -> [Uuid] + func allEntriesByType(ctype: CredentialType) async throws -> [Uuid] /** * Remove a credential from the store. */ - func delete(id: Uuid) throws + func delete(id: Uuid) async throws /** * Dump the contents of the credential set to the logger. */ - func dump() + func dump() async /** * Get a credential from the store. */ - func get(id: Uuid) throws -> Credential? + func get(id: Uuid) async throws -> Credential? } @@ -5071,62 +5177,122 @@ public convenience init(engine: StorageManagerInterface) { /** * Add a credential to the set. */ -open func add(credential: Credential)throws {try rustCallWithError(FfiConverterTypeVdcCollectionError.lift) { - uniffi_mobile_sdk_rs_fn_method_vdccollection_add(self.uniffiClonePointer(), - FfiConverterTypeCredential.lower(credential),$0 - ) -} +open func add(credential: Credential)async throws { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_mobile_sdk_rs_fn_method_vdccollection_add( + self.uniffiClonePointer(), + FfiConverterTypeCredential.lower(credential) + ) + }, + pollFunc: ffi_mobile_sdk_rs_rust_future_poll_void, + completeFunc: ffi_mobile_sdk_rs_rust_future_complete_void, + freeFunc: ffi_mobile_sdk_rs_rust_future_free_void, + liftFunc: { $0 }, + errorHandler: FfiConverterTypeVdcCollectionError.lift + ) } /** * Get a list of all the credentials. */ -open func allEntries()throws -> [Uuid] { - return try FfiConverterSequenceTypeUuid.lift(try rustCallWithError(FfiConverterTypeVdcCollectionError.lift) { - uniffi_mobile_sdk_rs_fn_method_vdccollection_all_entries(self.uniffiClonePointer(),$0 - ) -}) +open func allEntries()async throws -> [Uuid] { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_mobile_sdk_rs_fn_method_vdccollection_all_entries( + self.uniffiClonePointer() + + ) + }, + pollFunc: ffi_mobile_sdk_rs_rust_future_poll_rust_buffer, + completeFunc: ffi_mobile_sdk_rs_rust_future_complete_rust_buffer, + freeFunc: ffi_mobile_sdk_rs_rust_future_free_rust_buffer, + liftFunc: FfiConverterSequenceTypeUuid.lift, + errorHandler: FfiConverterTypeVdcCollectionError.lift + ) } /** * Get a list of all the credentials that match a specified type. */ -open func allEntriesByType(ctype: CredentialType)throws -> [Uuid] { - return try FfiConverterSequenceTypeUuid.lift(try rustCallWithError(FfiConverterTypeVdcCollectionError.lift) { - uniffi_mobile_sdk_rs_fn_method_vdccollection_all_entries_by_type(self.uniffiClonePointer(), - FfiConverterTypeCredentialType.lower(ctype),$0 - ) -}) +open func allEntriesByType(ctype: CredentialType)async throws -> [Uuid] { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_mobile_sdk_rs_fn_method_vdccollection_all_entries_by_type( + self.uniffiClonePointer(), + FfiConverterTypeCredentialType.lower(ctype) + ) + }, + pollFunc: ffi_mobile_sdk_rs_rust_future_poll_rust_buffer, + completeFunc: ffi_mobile_sdk_rs_rust_future_complete_rust_buffer, + freeFunc: ffi_mobile_sdk_rs_rust_future_free_rust_buffer, + liftFunc: FfiConverterSequenceTypeUuid.lift, + errorHandler: FfiConverterTypeVdcCollectionError.lift + ) } /** * Remove a credential from the store. */ -open func delete(id: Uuid)throws {try rustCallWithError(FfiConverterTypeVdcCollectionError.lift) { - uniffi_mobile_sdk_rs_fn_method_vdccollection_delete(self.uniffiClonePointer(), - FfiConverterTypeUuid.lower(id),$0 - ) -} +open func delete(id: Uuid)async throws { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_mobile_sdk_rs_fn_method_vdccollection_delete( + self.uniffiClonePointer(), + FfiConverterTypeUuid.lower(id) + ) + }, + pollFunc: ffi_mobile_sdk_rs_rust_future_poll_void, + completeFunc: ffi_mobile_sdk_rs_rust_future_complete_void, + freeFunc: ffi_mobile_sdk_rs_rust_future_free_void, + liftFunc: { $0 }, + errorHandler: FfiConverterTypeVdcCollectionError.lift + ) } /** * Dump the contents of the credential set to the logger. */ -open func dump() {try! rustCall() { - uniffi_mobile_sdk_rs_fn_method_vdccollection_dump(self.uniffiClonePointer(),$0 - ) -} +open func dump()async { + return + try! await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_mobile_sdk_rs_fn_method_vdccollection_dump( + self.uniffiClonePointer() + + ) + }, + pollFunc: ffi_mobile_sdk_rs_rust_future_poll_void, + completeFunc: ffi_mobile_sdk_rs_rust_future_complete_void, + freeFunc: ffi_mobile_sdk_rs_rust_future_free_void, + liftFunc: { $0 }, + errorHandler: nil + + ) } /** * Get a credential from the store. */ -open func get(id: Uuid)throws -> Credential? { - return try FfiConverterOptionTypeCredential.lift(try rustCallWithError(FfiConverterTypeVdcCollectionError.lift) { - uniffi_mobile_sdk_rs_fn_method_vdccollection_get(self.uniffiClonePointer(), - FfiConverterTypeUuid.lower(id),$0 - ) -}) +open func get(id: Uuid)async throws -> Credential? { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_mobile_sdk_rs_fn_method_vdccollection_get( + self.uniffiClonePointer(), + FfiConverterTypeUuid.lower(id) + ) + }, + pollFunc: ffi_mobile_sdk_rs_rust_future_poll_rust_buffer, + completeFunc: ffi_mobile_sdk_rs_rust_future_complete_rust_buffer, + freeFunc: ffi_mobile_sdk_rs_rust_future_free_rust_buffer, + liftFunc: FfiConverterOptionTypeCredential.lift, + errorHandler: FfiConverterTypeVdcCollectionError.lift + ) } @@ -10962,14 +11128,19 @@ public func handleResponse(state: MdlSessionManager, response: Data)throws -> M * String containing the BLE ident. */ -public func initializeMdlPresentation(mdocId: Uuid, uuid: Uuid, storageManager: StorageManagerInterface)throws -> MdlPresentationSession { - return try FfiConverterTypeMdlPresentationSession.lift(try rustCallWithError(FfiConverterTypeSessionError.lift) { - uniffi_mobile_sdk_rs_fn_func_initialize_mdl_presentation( - FfiConverterTypeUuid.lower(mdocId), - FfiConverterTypeUuid.lower(uuid), - FfiConverterTypeStorageManagerInterface.lower(storageManager),$0 - ) -}) +public func initializeMdlPresentation(mdocId: Uuid, uuid: Uuid, storageManager: StorageManagerInterface)async throws -> MdlPresentationSession { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_mobile_sdk_rs_fn_func_initialize_mdl_presentation(FfiConverterTypeUuid.lower(mdocId),FfiConverterTypeUuid.lower(uuid),FfiConverterTypeStorageManagerInterface.lower(storageManager) + ) + }, + pollFunc: ffi_mobile_sdk_rs_rust_future_poll_pointer, + completeFunc: ffi_mobile_sdk_rs_rust_future_complete_pointer, + freeFunc: ffi_mobile_sdk_rs_rust_future_free_pointer, + liftFunc: FfiConverterTypeMdlPresentationSession.lift, + errorHandler: FfiConverterTypeSessionError.lift + ) } /** * Begin the mDL presentation process for the holder by passing in the credential @@ -11160,7 +11331,7 @@ private var initializationResult: InitializationResult = { if (uniffi_mobile_sdk_rs_checksum_func_handle_response() != 43961) { return InitializationResult.apiChecksumMismatch } - if (uniffi_mobile_sdk_rs_checksum_func_initialize_mdl_presentation() != 53444) { + if (uniffi_mobile_sdk_rs_checksum_func_initialize_mdl_presentation() != 29387) { return InitializationResult.apiChecksumMismatch } if (uniffi_mobile_sdk_rs_checksum_func_initialize_mdl_presentation_from_bytes() != 26972) { @@ -11412,16 +11583,16 @@ private var initializationResult: InitializationResult = { if (uniffi_mobile_sdk_rs_checksum_method_status_purpose() != 51769) { return InitializationResult.apiChecksumMismatch } - if (uniffi_mobile_sdk_rs_checksum_method_storagemanagerinterface_add() != 60217) { + if (uniffi_mobile_sdk_rs_checksum_method_storagemanagerinterface_add() != 39162) { return InitializationResult.apiChecksumMismatch } - if (uniffi_mobile_sdk_rs_checksum_method_storagemanagerinterface_get() != 64957) { + if (uniffi_mobile_sdk_rs_checksum_method_storagemanagerinterface_get() != 35430) { return InitializationResult.apiChecksumMismatch } - if (uniffi_mobile_sdk_rs_checksum_method_storagemanagerinterface_list() != 22654) { + if (uniffi_mobile_sdk_rs_checksum_method_storagemanagerinterface_list() != 37678) { return InitializationResult.apiChecksumMismatch } - if (uniffi_mobile_sdk_rs_checksum_method_storagemanagerinterface_remove() != 46691) { + if (uniffi_mobile_sdk_rs_checksum_method_storagemanagerinterface_remove() != 24982) { return InitializationResult.apiChecksumMismatch } if (uniffi_mobile_sdk_rs_checksum_method_synchttpclient_http_client() != 53085) { @@ -11439,22 +11610,22 @@ private var initializationResult: InitializationResult = { if (uniffi_mobile_sdk_rs_checksum_method_vcdm2sdjwt_type() != 50079) { return InitializationResult.apiChecksumMismatch } - if (uniffi_mobile_sdk_rs_checksum_method_vdccollection_add() != 43160) { + if (uniffi_mobile_sdk_rs_checksum_method_vdccollection_add() != 42040) { return InitializationResult.apiChecksumMismatch } - if (uniffi_mobile_sdk_rs_checksum_method_vdccollection_all_entries() != 7546) { + if (uniffi_mobile_sdk_rs_checksum_method_vdccollection_all_entries() != 7074) { return InitializationResult.apiChecksumMismatch } - if (uniffi_mobile_sdk_rs_checksum_method_vdccollection_all_entries_by_type() != 7766) { + if (uniffi_mobile_sdk_rs_checksum_method_vdccollection_all_entries_by_type() != 232) { return InitializationResult.apiChecksumMismatch } - if (uniffi_mobile_sdk_rs_checksum_method_vdccollection_delete() != 26842) { + if (uniffi_mobile_sdk_rs_checksum_method_vdccollection_delete() != 63691) { return InitializationResult.apiChecksumMismatch } - if (uniffi_mobile_sdk_rs_checksum_method_vdccollection_dump() != 14663) { + if (uniffi_mobile_sdk_rs_checksum_method_vdccollection_dump() != 37372) { return InitializationResult.apiChecksumMismatch } - if (uniffi_mobile_sdk_rs_checksum_method_vdccollection_get() != 52546) { + if (uniffi_mobile_sdk_rs_checksum_method_vdccollection_get() != 1085) { return InitializationResult.apiChecksumMismatch } if (uniffi_mobile_sdk_rs_checksum_constructor_delegatedverifier_new_client() != 15415) { diff --git a/src/local_store.rs b/src/local_store.rs index d5143d98..a36c0413 100644 --- a/src/local_store.rs +++ b/src/local_store.rs @@ -1,3 +1,5 @@ +use async_trait::async_trait; + use crate::common::*; use crate::storage_manager::*; @@ -26,9 +28,10 @@ impl Default for LocalStore { } } +#[async_trait] impl StorageManagerInterface for LocalStore { /// Add a key/value pair to storage. - fn add(&self, key: Key, value: Value) -> Result<(), StorageManagerError> { + async fn add(&self, key: Key, value: Value) -> Result<(), StorageManagerError> { let mut store = self.store.lock().unwrap(); store.insert(key, value); @@ -37,7 +40,7 @@ impl StorageManagerInterface for LocalStore { } /// Retrieve the value associated with a key. - fn get(&self, key: Key) -> Result, StorageManagerError> { + async fn get(&self, key: Key) -> Result, StorageManagerError> { let store = self.store.lock().unwrap(); match store.get(&key) { @@ -47,14 +50,14 @@ impl StorageManagerInterface for LocalStore { } /// List the available key/value pairs. - fn list(&self) -> Result, StorageManagerError> { + async fn list(&self) -> Result, StorageManagerError> { let store = self.store.lock().unwrap(); Ok(store.keys().map(|x| x.to_owned()).collect()) } /// Delete a given key/value pair from storage. - fn remove(&self, key: Key) -> Result<(), StorageManagerError> { + async fn remove(&self, key: Key) -> Result<(), StorageManagerError> { let mut store = self.store.lock().unwrap(); _ = store.remove(&key); diff --git a/src/mdl/holder.rs b/src/mdl/holder.rs index 8352af16..e3f28752 100644 --- a/src/mdl/holder.rs +++ b/src/mdl/holder.rs @@ -44,7 +44,7 @@ use isomdl::{ /// String containing the BLE ident. /// #[uniffi::export] -pub fn initialize_mdl_presentation( +pub async fn initialize_mdl_presentation( mdoc_id: Uuid, uuid: Uuid, storage_manager: Arc, @@ -53,6 +53,7 @@ pub fn initialize_mdl_presentation( let document = vdc_collection .get(mdoc_id) + .await .map_err(|_| SessionError::Generic { value: "Error in VDC Collection".to_string(), })? @@ -386,10 +387,12 @@ mod tests { payload: mdoc_bytes, key_alias: Some(KeyAlias("Testing".to_string())), }) + .await .unwrap(); - let presentation_session = - initialize_mdl_presentation(mdoc, Uuid::new_v4(), smi.clone()).unwrap(); + let presentation_session = initialize_mdl_presentation(mdoc, Uuid::new_v4(), smi.clone()) + .await + .unwrap(); let namespaces: device_request::Namespaces = [( "org.iso.18013.5.1".to_string(), [ @@ -438,7 +441,7 @@ mod tests { .submit_response(signature.to_der().to_vec()) .unwrap(); let res = reader_session_manager.handle_response(&response); - vdc_collection.delete(mdoc).unwrap(); + vdc_collection.delete(mdoc).await.unwrap(); assert_eq!(res.errors, BTreeMap::new()); } @@ -463,10 +466,12 @@ mod tests { payload: mdoc_bytes, key_alias: Some(KeyAlias("Testing".to_string())), }) + .await .unwrap(); - let presentation_session = - initialize_mdl_presentation(mdoc, Uuid::new_v4(), smi.clone()).unwrap(); + let presentation_session = initialize_mdl_presentation(mdoc, Uuid::new_v4(), smi.clone()) + .await + .unwrap(); let namespaces = [( "org.iso.18013.5.1".to_string(), [ @@ -510,6 +515,6 @@ mod tests { .unwrap(); let _ = crate::reader::handle_response(reader_session_data.state, response).unwrap(); - vdc_collection.delete(mdoc).unwrap(); + vdc_collection.delete(mdoc).await.unwrap(); } } diff --git a/src/oid4vp/holder.rs b/src/oid4vp/holder.rs index 85da92b2..6efd69e8 100644 --- a/src/oid4vp/holder.rs +++ b/src/oid4vp/holder.rs @@ -8,6 +8,7 @@ use crate::vdc_collection::VdcCollection; use std::collections::HashMap; use std::sync::Arc; +use futures::StreamExt; use openid4vp::core::authorization_request::parameters::ClientIdScheme; use openid4vp::core::credential_format::{ClaimFormatDesignation, ClaimFormatPayload}; use openid4vp::core::presentation_definition::PresentationDefinition; @@ -216,17 +217,19 @@ impl Holder { Some(credentials) => credentials.to_owned(), None => match &self.vdc_collection { None => vec![], - Some(vdc_collection) => vdc_collection - .all_entries()? - .into_iter() - .filter_map(|id| { - vdc_collection - .get(id) - .ok() - .flatten() - .and_then(|cred| cred.try_into_parsed().ok()) - }) - .collect::>>(), + Some(vdc_collection) => { + futures::stream::iter(vdc_collection.all_entries().await?.into_iter()) + .filter_map(|id| async move { + vdc_collection + .get(id) + .await + .ok() + .flatten() + .and_then(|cred| cred.try_into_parsed().ok()) + }) + .collect::>>() + .await + } }, } .into_iter() diff --git a/src/storage_manager.rs b/src/storage_manager.rs index 3ff8dc34..6f08d31d 100644 --- a/src/storage_manager.rs +++ b/src/storage_manager.rs @@ -1,6 +1,7 @@ use crate::common::*; use std::fmt::Debug; +use async_trait::async_trait; use thiserror::Error; /// Enum: StorageManagerError @@ -42,6 +43,7 @@ pub enum StorageManagerError { /// We use the older callback_interface to keep the required version level of our Android API /// low. #[uniffi::export(with_foreign)] +#[async_trait] pub trait StorageManagerInterface: Send + Sync + Debug { /// Function: add /// @@ -51,18 +53,18 @@ pub trait StorageManagerInterface: Send + Sync + Debug { /// Arguments: /// key - The key to add /// value - The value to add under the key. - fn add(&self, key: Key, value: Value) -> Result<(), StorageManagerError>; + async fn add(&self, key: Key, value: Value) -> Result<(), StorageManagerError>; /// Function: get /// /// Callback function pointer to native (kotlin/swift) code for /// getting a key. - fn get(&self, key: Key) -> Result, StorageManagerError>; + async fn get(&self, key: Key) -> Result, StorageManagerError>; /// Function: list /// /// Callback function pointer for listing available keys. - fn list(&self) -> Result, StorageManagerError>; + async fn list(&self) -> Result, StorageManagerError>; /// Function: remove /// @@ -70,5 +72,5 @@ pub trait StorageManagerInterface: Send + Sync + Debug { /// removing a key. This referenced function MUST be idempotent. In /// particular, it must treat removing a non-existent key as a normal and /// expected circumstance, simply returning () and not an error. - fn remove(&self, key: Key) -> Result<(), StorageManagerError>; + async fn remove(&self, key: Key) -> Result<(), StorageManagerError>; } diff --git a/src/vdc_collection.rs b/src/vdc_collection.rs index c33d9037..63c526a6 100644 --- a/src/vdc_collection.rs +++ b/src/vdc_collection.rs @@ -4,6 +4,7 @@ use crate::common::*; use crate::credential::Credential; use crate::storage_manager::*; +use futures::StreamExt; use thiserror::Error; use tracing::info; @@ -51,21 +52,25 @@ impl VdcCollection { } /// Add a credential to the set. - pub fn add(&self, credential: &Credential) -> Result<(), VdcCollectionError> { + pub async fn add(&self, credential: &Credential) -> Result<(), VdcCollectionError> { let val = match serde_cbor::to_vec(&credential) { Ok(x) => x, Err(_) => return Err(VdcCollectionError::SerializeFailed), }; - match self.storage.add(Self::id_to_key(credential.id), Value(val)) { + match self + .storage + .add(Self::id_to_key(credential.id), Value(val)) + .await + { Ok(()) => Ok(()), Err(e) => Err(VdcCollectionError::StoreFailed(e)), } } /// Get a credential from the store. - pub fn get(&self, id: Uuid) -> Result, VdcCollectionError> { - let raw = match self.storage.get(Self::id_to_key(id)) { + pub async fn get(&self, id: Uuid) -> Result, VdcCollectionError> { + let raw = match self.storage.get(Self::id_to_key(id)).await { Ok(Some(x)) => x, Ok(None) => return Ok(None), Err(e) => return Err(VdcCollectionError::LoadFailed(e)), @@ -78,31 +83,32 @@ impl VdcCollection { } /// Remove a credential from the store. - pub fn delete(&self, id: Uuid) -> Result<(), VdcCollectionError> { - match self.storage.remove(Self::id_to_key(id)) { + pub async fn delete(&self, id: Uuid) -> Result<(), VdcCollectionError> { + match self.storage.remove(Self::id_to_key(id)).await { Ok(_) => Ok(()), Err(e) => Err(VdcCollectionError::DeleteFailed(e)), } } /// Get a list of all the credentials. - pub fn all_entries(&self) -> Result, VdcCollectionError> { + pub async fn all_entries(&self) -> Result, VdcCollectionError> { self.storage .list() + .await .map(|list| list.iter().filter_map(Self::key_to_id).collect()) .map_err(VdcCollectionError::LoadFailed) } /// Get a list of all the credentials that match a specified type. - pub fn all_entries_by_type( + pub async fn all_entries_by_type( &self, ctype: &CredentialType, ) -> Result, VdcCollectionError> { - let all_entries = self.all_entries()?; - Ok(all_entries - .into_iter() - .filter_map(|id| self.get(id).ok().flatten()) + let all_entries = self.all_entries().await?; + Ok(futures::stream::iter(all_entries.into_iter()) + .filter_map(|id| async move { self.get(id).await.ok().flatten() }) .collect::>() + .await .iter() .filter(|cred| &cred.r#type == ctype) .map(|cred| cred.id) @@ -110,11 +116,11 @@ impl VdcCollection { } /// Dump the contents of the credential set to the logger. - pub fn dump(&self) { - match self.all_entries() { + pub async fn dump(&self) { + match self.all_entries().await { Ok(list) => { for key in list { - if let Ok(x) = self.get(key) { + if let Ok(x) = self.get(key).await { info!("{:?}", x); } } @@ -151,8 +157,8 @@ mod tests { async fn test_vdc() { let smi: Arc = Arc::new(LocalStore::new()); let vdc = VdcCollection::new(smi); - for id in vdc.all_entries().unwrap() { - vdc.delete(id).unwrap(); + for id in vdc.all_entries().await.unwrap() { + vdc.delete(id).await.unwrap(); } let payload_1: Vec = "Some random collection of bytes. ⚛".into(); let payload_2: Vec = "Some other random collection of bytes. 📯".into(); @@ -183,33 +189,42 @@ mod tests { }; vdc.add(&credential_1) + .await .expect("Unable to add the first value."); vdc.add(&credential_2) + .await .expect("Unable to add the second value."); vdc.add(&credential_3) + .await .expect("Unable to add the third value."); vdc.get(credential_2.id) + .await .expect("Failed to get the second value"); vdc.get(credential_1.id) + .await .expect("Failed to get the first value"); vdc.get(credential_3.id) + .await .expect("Failed to get the third value"); - assert!(vdc.all_entries().unwrap().len() == 3); + assert!(vdc.all_entries().await.unwrap().len() == 3); vdc.delete(credential_2.id) + .await .expect("Failed to delete the second value."); - assert!(vdc.all_entries().unwrap().len() == 2); + assert!(vdc.all_entries().await.unwrap().len() == 2); vdc.delete(credential_1.id) + .await .expect("Failed to delete the first value."); vdc.delete(credential_3.id) + .await .expect("Failed to delete the third value."); - assert!(vdc.all_entries().unwrap().len() == 0); + assert!(vdc.all_entries().await.unwrap().len() == 0); } } diff --git a/test.jwk b/test.jwk new file mode 100644 index 00000000..fe6cd7cd --- /dev/null +++ b/test.jwk @@ -0,0 +1 @@ +{"kty":"EC","crv":"P-256","x":"WNXXRWQ0bnAkWvH7jKCcpfGUBYWC9je0uxc6mS7x2Ec","y":"OqkRgX2njquQyA85IdAekCegfdt3YYw9HL4YbZxbRLA","d":"T3s-bXxxPFvmwDW1M4OWVXcECRPG2cN3NepQr6H5XWM"}