From 919d6275cf0749f666ce446b7979b7d5a05ba685 Mon Sep 17 00:00:00 2001 From: Jacob Date: Tue, 22 Oct 2024 12:48:48 +0100 Subject: [PATCH] StorageManagerInterface is no longer async (#61) No longer needed as Kotlin implementation will be synchronous --- Cargo.lock | 2 +- .../Sources/MobileSdkRs/mobile_sdk_rs.swift | 429 +++++------------- src/local_store.rs | 9 +- src/mdl/holder.rs | 21 +- src/storage_manager.rs | 9 +- src/vdc_collection.rs | 59 +-- 6 files changed, 163 insertions(+), 366 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 97f1f5aa..6898c002 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3439,7 +3439,7 @@ dependencies = [ [[package]] name = "oid4vci" version = "0.1.0" -source = "git+https://github.com/spruceid/oid4vci-rs?rev=8b9acf5#8b9acf54708f361b05e3abe55b333187286702e6" +source = "git+https://github.com/spruceid/oid4vci-rs?rev=d95fe3a#d95fe3aa1ffe59156803ab39c024e8c506c9eee1" dependencies = [ "anyhow", "async-signature", diff --git a/MobileSdkRs/Sources/MobileSdkRs/mobile_sdk_rs.swift b/MobileSdkRs/Sources/MobileSdkRs/mobile_sdk_rs.swift index 7b959e41..7a986611 100644 --- a/MobileSdkRs/Sources/MobileSdkRs/mobile_sdk_rs.swift +++ b/MobileSdkRs/Sources/MobileSdkRs/mobile_sdk_rs.swift @@ -2976,7 +2976,7 @@ public protocol StorageManagerInterface : AnyObject { * key - The key to add * value - The value to add under the key. */ - func add(key: Key, value: Value) async throws + func add(key: Key, value: Value) throws /** * Function: get @@ -2984,14 +2984,14 @@ public protocol StorageManagerInterface : AnyObject { * Callback function pointer to native (kotlin/swift) code for * getting a key. */ - func get(key: Key) async throws -> Value? + func get(key: Key) throws -> Value? /** * Function: list * * Callback function pointer for listing available keys. */ - func list() async throws -> [Key] + func list() throws -> [Key] /** * Function: remove @@ -3001,7 +3001,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) async throws + func remove(key: Key) throws } @@ -3068,21 +3068,12 @@ open class StorageManagerInterfaceImpl: * key - The key to add * value - The value to add under the key. */ -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 - ) +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 + ) +} } /** @@ -3091,21 +3082,12 @@ open func add(key: Key, value: Value)async throws { * Callback function pointer to native (kotlin/swift) code for * getting a key. */ -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 - ) +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 + ) +}) } /** @@ -3113,21 +3095,11 @@ open func get(key: Key)async throws -> Value? { * * Callback function pointer for listing available keys. */ -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 - ) +open func list()throws -> [Key] { + return try FfiConverterSequenceTypeKey.lift(try rustCallWithError(FfiConverterTypeStorageManagerError.lift) { + uniffi_mobile_sdk_rs_fn_method_storagemanagerinterface_list(self.uniffiClonePointer(),$0 + ) +}) } /** @@ -3138,21 +3110,11 @@ open func list()async 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)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 - ) +open func remove(key: Key)throws {try rustCallWithError(FfiConverterTypeStorageManagerError.lift) { + uniffi_mobile_sdk_rs_fn_method_storagemanagerinterface_remove(self.uniffiClonePointer(), + FfiConverterTypeKey.lower(key),$0 + ) +} } @@ -3169,169 +3131,101 @@ fileprivate struct UniffiCallbackInterfaceStorageManagerInterface { uniffiHandle: UInt64, key: RustBuffer, value: RustBuffer, - uniffiFutureCallback: @escaping UniffiForeignFutureCompleteVoid, - uniffiCallbackData: UInt64, - uniffiOutReturn: UnsafeMutablePointer + uniffiOutReturn: UnsafeMutableRawPointer, + uniffiCallStatus: UnsafeMutablePointer ) in let makeCall = { - () async throws -> () in + () throws -> () in guard let uniffiObj = try? FfiConverterTypeStorageManagerInterface.handleMap.get(handle: uniffiHandle) else { throw UniffiInternalError.unexpectedStaleHandle } - return try await uniffiObj.add( + return try uniffiObj.add( key: try FfiConverterTypeKey.lift(key), value: try FfiConverterTypeValue.lift(value) ) } - 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( + + let writeReturn = { () } + uniffiTraitInterfaceCallWithError( + callStatus: uniffiCallStatus, makeCall: makeCall, - handleSuccess: uniffiHandleSuccess, - handleError: uniffiHandleError, + writeReturn: writeReturn, lowerError: FfiConverterTypeStorageManagerError.lower ) - uniffiOutReturn.pointee = uniffiForeignFuture }, get: { ( uniffiHandle: UInt64, key: RustBuffer, - uniffiFutureCallback: @escaping UniffiForeignFutureCompleteRustBuffer, - uniffiCallbackData: UInt64, - uniffiOutReturn: UnsafeMutablePointer + uniffiOutReturn: UnsafeMutablePointer, + uniffiCallStatus: UnsafeMutablePointer ) in let makeCall = { - () async throws -> Value? in + () throws -> Value? in guard let uniffiObj = try? FfiConverterTypeStorageManagerInterface.handleMap.get(handle: uniffiHandle) else { throw UniffiInternalError.unexpectedStaleHandle } - return try await uniffiObj.get( + return try uniffiObj.get( key: try FfiConverterTypeKey.lift(key) ) } - 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( + + let writeReturn = { uniffiOutReturn.pointee = FfiConverterOptionTypeValue.lower($0) } + uniffiTraitInterfaceCallWithError( + callStatus: uniffiCallStatus, makeCall: makeCall, - handleSuccess: uniffiHandleSuccess, - handleError: uniffiHandleError, + writeReturn: writeReturn, lowerError: FfiConverterTypeStorageManagerError.lower ) - uniffiOutReturn.pointee = uniffiForeignFuture }, list: { ( uniffiHandle: UInt64, - uniffiFutureCallback: @escaping UniffiForeignFutureCompleteRustBuffer, - uniffiCallbackData: UInt64, - uniffiOutReturn: UnsafeMutablePointer + uniffiOutReturn: UnsafeMutablePointer, + uniffiCallStatus: UnsafeMutablePointer ) in let makeCall = { - () async throws -> [Key] in + () throws -> [Key] in guard let uniffiObj = try? FfiConverterTypeStorageManagerInterface.handleMap.get(handle: uniffiHandle) else { throw UniffiInternalError.unexpectedStaleHandle } - return try await uniffiObj.list( + return try uniffiObj.list( ) } - 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( + + let writeReturn = { uniffiOutReturn.pointee = FfiConverterSequenceTypeKey.lower($0) } + uniffiTraitInterfaceCallWithError( + callStatus: uniffiCallStatus, makeCall: makeCall, - handleSuccess: uniffiHandleSuccess, - handleError: uniffiHandleError, + writeReturn: writeReturn, lowerError: FfiConverterTypeStorageManagerError.lower ) - uniffiOutReturn.pointee = uniffiForeignFuture }, remove: { ( uniffiHandle: UInt64, key: RustBuffer, - uniffiFutureCallback: @escaping UniffiForeignFutureCompleteVoid, - uniffiCallbackData: UInt64, - uniffiOutReturn: UnsafeMutablePointer + uniffiOutReturn: UnsafeMutableRawPointer, + uniffiCallStatus: UnsafeMutablePointer ) in let makeCall = { - () async throws -> () in + () throws -> () in guard let uniffiObj = try? FfiConverterTypeStorageManagerInterface.handleMap.get(handle: uniffiHandle) else { throw UniffiInternalError.unexpectedStaleHandle } - return try await uniffiObj.remove( + return try uniffiObj.remove( key: try FfiConverterTypeKey.lift(key) ) } - 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( + + let writeReturn = { () } + uniffiTraitInterfaceCallWithError( + callStatus: uniffiCallStatus, makeCall: makeCall, - handleSuccess: uniffiHandleSuccess, - handleError: uniffiHandleError, + writeReturn: writeReturn, lowerError: FfiConverterTypeStorageManagerError.lower ) - uniffiOutReturn.pointee = uniffiForeignFuture }, uniffiFree: { (uniffiHandle: UInt64) -> () in let result = try? FfiConverterTypeStorageManagerInterface.handleMap.remove(handle: uniffiHandle) @@ -3650,32 +3544,32 @@ public protocol VdcCollectionProtocol : AnyObject { /** * Add a credential to the set. */ - func add(credential: Credential) async throws + func add(credential: Credential) throws /** * Get a list of all the credentials. */ - func allEntries() async throws -> [Uuid] + func allEntries() throws -> [Uuid] /** * Get a list of all the credentials that match a specified type. */ - func allEntriesByType(ctype: CredentialType) async throws -> [Uuid] + func allEntriesByType(ctype: CredentialType) throws -> [Uuid] /** * Remove a credential from the store. */ - func delete(id: Uuid) async throws + func delete(id: Uuid) throws /** * Dump the contents of the credential set to the logger. */ - func dump() async + func dump() /** * Get a credential from the store. */ - func get(id: Uuid) async throws -> Credential? + func get(id: Uuid) throws -> Credential? } @@ -3739,122 +3633,62 @@ public convenience init(engine: StorageManagerInterface) { /** * Add a credential to the set. */ -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 - ) +open func add(credential: Credential)throws {try rustCallWithError(FfiConverterTypeVdcCollectionError.lift) { + uniffi_mobile_sdk_rs_fn_method_vdccollection_add(self.uniffiClonePointer(), + FfiConverterTypeCredential.lower(credential),$0 + ) +} } /** * Get a list of all the credentials. */ -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 - ) +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 + ) +}) } /** * Get a list of all the credentials that match a specified type. */ -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 - ) +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 + ) +}) } /** * Remove a credential from the store. */ -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 - ) +open func delete(id: Uuid)throws {try rustCallWithError(FfiConverterTypeVdcCollectionError.lift) { + uniffi_mobile_sdk_rs_fn_method_vdccollection_delete(self.uniffiClonePointer(), + FfiConverterTypeUuid.lower(id),$0 + ) +} } /** * Dump the contents of the credential set to the logger. */ -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 - - ) +open func dump() {try! rustCall() { + uniffi_mobile_sdk_rs_fn_method_vdccollection_dump(self.uniffiClonePointer(),$0 + ) +} } /** * Get a credential from the store. */ -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 - ) +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 + ) +}) } @@ -7871,19 +7705,14 @@ public func handleResponse(state: MdlSessionManager, response: Data)throws -> M * String containing the BLE ident. */ -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 - ) +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 + ) +}) } /** * Begin the mDL presentation process for the holder by passing in the credential @@ -7902,19 +7731,13 @@ public func initializeMdlPresentation(mdocId: Uuid, uuid: Uuid, storageManager: * String containing the BLE ident. */ -public func initializeMdlPresentationFromBytes(mdoc: Mdoc, uuid: Uuid)async throws -> MdlPresentationSession { - return - try await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_mobile_sdk_rs_fn_func_initialize_mdl_presentation_from_bytes(FfiConverterTypeMdoc.lower(mdoc),FfiConverterTypeUuid.lower(uuid) - ) - }, - 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 - ) +public func initializeMdlPresentationFromBytes(mdoc: Mdoc, uuid: Uuid)throws -> MdlPresentationSession { + return try FfiConverterTypeMdlPresentationSession.lift(try rustCallWithError(FfiConverterTypeSessionError.lift) { + uniffi_mobile_sdk_rs_fn_func_initialize_mdl_presentation_from_bytes( + FfiConverterTypeMdoc.lower(mdoc), + FfiConverterTypeUuid.lower(uuid),$0 + ) +}) } public func oid4vciExchangeCredential(session: Oid4vciSession, proofsOfPossession: [String], contextMap: [String: String]?, httpClient: IHttpClient)async throws -> [CredentialResponse] { return @@ -8080,10 +7903,10 @@ 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() != 29387) { + if (uniffi_mobile_sdk_rs_checksum_func_initialize_mdl_presentation() != 53444) { return InitializationResult.apiChecksumMismatch } - if (uniffi_mobile_sdk_rs_checksum_func_initialize_mdl_presentation_from_bytes() != 12482) { + if (uniffi_mobile_sdk_rs_checksum_func_initialize_mdl_presentation_from_bytes() != 26972) { return InitializationResult.apiChecksumMismatch } if (uniffi_mobile_sdk_rs_checksum_func_oid4vci_exchange_credential() != 59343) { @@ -8254,37 +8077,37 @@ private var initializationResult: InitializationResult = { if (uniffi_mobile_sdk_rs_checksum_method_parsedcredential_key_alias() != 52023) { return InitializationResult.apiChecksumMismatch } - if (uniffi_mobile_sdk_rs_checksum_method_storagemanagerinterface_add() != 39162) { + if (uniffi_mobile_sdk_rs_checksum_method_storagemanagerinterface_add() != 60217) { return InitializationResult.apiChecksumMismatch } - if (uniffi_mobile_sdk_rs_checksum_method_storagemanagerinterface_get() != 35430) { + if (uniffi_mobile_sdk_rs_checksum_method_storagemanagerinterface_get() != 64957) { return InitializationResult.apiChecksumMismatch } - if (uniffi_mobile_sdk_rs_checksum_method_storagemanagerinterface_list() != 37678) { + if (uniffi_mobile_sdk_rs_checksum_method_storagemanagerinterface_list() != 22654) { return InitializationResult.apiChecksumMismatch } - if (uniffi_mobile_sdk_rs_checksum_method_storagemanagerinterface_remove() != 24982) { + if (uniffi_mobile_sdk_rs_checksum_method_storagemanagerinterface_remove() != 46691) { return InitializationResult.apiChecksumMismatch } if (uniffi_mobile_sdk_rs_checksum_method_synchttpclient_http_client() != 53085) { return InitializationResult.apiChecksumMismatch } - if (uniffi_mobile_sdk_rs_checksum_method_vdccollection_add() != 42040) { + if (uniffi_mobile_sdk_rs_checksum_method_vdccollection_add() != 43160) { return InitializationResult.apiChecksumMismatch } - if (uniffi_mobile_sdk_rs_checksum_method_vdccollection_all_entries() != 7074) { + if (uniffi_mobile_sdk_rs_checksum_method_vdccollection_all_entries() != 7546) { return InitializationResult.apiChecksumMismatch } - if (uniffi_mobile_sdk_rs_checksum_method_vdccollection_all_entries_by_type() != 232) { + if (uniffi_mobile_sdk_rs_checksum_method_vdccollection_all_entries_by_type() != 7766) { return InitializationResult.apiChecksumMismatch } - if (uniffi_mobile_sdk_rs_checksum_method_vdccollection_delete() != 63691) { + if (uniffi_mobile_sdk_rs_checksum_method_vdccollection_delete() != 26842) { return InitializationResult.apiChecksumMismatch } - if (uniffi_mobile_sdk_rs_checksum_method_vdccollection_dump() != 37372) { + if (uniffi_mobile_sdk_rs_checksum_method_vdccollection_dump() != 14663) { return InitializationResult.apiChecksumMismatch } - if (uniffi_mobile_sdk_rs_checksum_method_vdccollection_get() != 1085) { + if (uniffi_mobile_sdk_rs_checksum_method_vdccollection_get() != 52546) { return InitializationResult.apiChecksumMismatch } if (uniffi_mobile_sdk_rs_checksum_constructor_ihttpclient_new_async() != 55307) { diff --git a/src/local_store.rs b/src/local_store.rs index 6a6b352e..d5143d98 100644 --- a/src/local_store.rs +++ b/src/local_store.rs @@ -26,10 +26,9 @@ impl Default for LocalStore { } } -#[async_trait::async_trait] impl StorageManagerInterface for LocalStore { /// Add a key/value pair to storage. - async fn add(&self, key: Key, value: Value) -> Result<(), StorageManagerError> { + fn add(&self, key: Key, value: Value) -> Result<(), StorageManagerError> { let mut store = self.store.lock().unwrap(); store.insert(key, value); @@ -38,7 +37,7 @@ impl StorageManagerInterface for LocalStore { } /// Retrieve the value associated with a key. - async fn get(&self, key: Key) -> Result, StorageManagerError> { + fn get(&self, key: Key) -> Result, StorageManagerError> { let store = self.store.lock().unwrap(); match store.get(&key) { @@ -48,14 +47,14 @@ impl StorageManagerInterface for LocalStore { } /// List the available key/value pairs. - async fn list(&self) -> Result, StorageManagerError> { + 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. - async fn remove(&self, key: Key) -> Result<(), StorageManagerError> { + 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 75b46568..8352af16 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 async fn initialize_mdl_presentation( +pub fn initialize_mdl_presentation( mdoc_id: Uuid, uuid: Uuid, storage_manager: Arc, @@ -53,7 +53,6 @@ pub async fn initialize_mdl_presentation( let document = vdc_collection .get(mdoc_id) - .await .map_err(|_| SessionError::Generic { value: "Error in VDC Collection".to_string(), })? @@ -110,7 +109,7 @@ pub async fn initialize_mdl_presentation( /// String containing the BLE ident. /// #[uniffi::export] -pub async fn initialize_mdl_presentation_from_bytes( +pub fn initialize_mdl_presentation_from_bytes( mdoc: Arc, uuid: Uuid, ) -> Result { @@ -387,12 +386,10 @@ 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()) - .await - .unwrap(); + let presentation_session = + initialize_mdl_presentation(mdoc, Uuid::new_v4(), smi.clone()).unwrap(); let namespaces: device_request::Namespaces = [( "org.iso.18013.5.1".to_string(), [ @@ -441,7 +438,7 @@ mod tests { .submit_response(signature.to_der().to_vec()) .unwrap(); let res = reader_session_manager.handle_response(&response); - vdc_collection.delete(mdoc).await.unwrap(); + vdc_collection.delete(mdoc).unwrap(); assert_eq!(res.errors, BTreeMap::new()); } @@ -466,12 +463,10 @@ 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()) - .await - .unwrap(); + let presentation_session = + initialize_mdl_presentation(mdoc, Uuid::new_v4(), smi.clone()).unwrap(); let namespaces = [( "org.iso.18013.5.1".to_string(), [ @@ -515,6 +510,6 @@ mod tests { .unwrap(); let _ = crate::reader::handle_response(reader_session_data.state, response).unwrap(); - vdc_collection.delete(mdoc).await.unwrap(); + vdc_collection.delete(mdoc).unwrap(); } } diff --git a/src/storage_manager.rs b/src/storage_manager.rs index 40bbf84b..3ff8dc34 100644 --- a/src/storage_manager.rs +++ b/src/storage_manager.rs @@ -42,7 +42,6 @@ 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::async_trait] pub trait StorageManagerInterface: Send + Sync + Debug { /// Function: add /// @@ -52,18 +51,18 @@ pub trait StorageManagerInterface: Send + Sync + Debug { /// Arguments: /// key - The key to add /// value - The value to add under the key. - async fn add(&self, key: Key, value: Value) -> Result<(), StorageManagerError>; + fn add(&self, key: Key, value: Value) -> Result<(), StorageManagerError>; /// Function: get /// /// Callback function pointer to native (kotlin/swift) code for /// getting a key. - async fn get(&self, key: Key) -> Result, StorageManagerError>; + fn get(&self, key: Key) -> Result, StorageManagerError>; /// Function: list /// /// Callback function pointer for listing available keys. - async fn list(&self) -> Result, StorageManagerError>; + fn list(&self) -> Result, StorageManagerError>; /// Function: remove /// @@ -71,5 +70,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. - async fn remove(&self, key: Key) -> Result<(), StorageManagerError>; + fn remove(&self, key: Key) -> Result<(), StorageManagerError>; } diff --git a/src/vdc_collection.rs b/src/vdc_collection.rs index c613e224..3b732bfb 100644 --- a/src/vdc_collection.rs +++ b/src/vdc_collection.rs @@ -3,8 +3,6 @@ use std::sync::Arc; use crate::common::*; use crate::credential::Credential; use crate::storage_manager::*; -use futures::stream; -use futures::StreamExt; use thiserror::Error; use tracing::info; @@ -52,25 +50,21 @@ impl VdcCollection { } /// Add a credential to the set. - pub async fn add(&self, credential: &Credential) -> Result<(), VdcCollectionError> { + pub 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)) - .await - { + match self.storage.add(Self::id_to_key(credential.id), Value(val)) { Ok(()) => Ok(()), Err(e) => Err(VdcCollectionError::StoreFailed(e)), } } /// Get a credential from the store. - pub async fn get(&self, id: Uuid) -> Result, VdcCollectionError> { - let raw = match self.storage.get(Self::id_to_key(id)).await { + pub fn get(&self, id: Uuid) -> Result, VdcCollectionError> { + let raw = match self.storage.get(Self::id_to_key(id)) { Ok(Some(x)) => x, Ok(None) => return Ok(None), Err(e) => return Err(VdcCollectionError::LoadFailed(e)), @@ -83,32 +77,31 @@ impl VdcCollection { } /// Remove a credential from the store. - pub async fn delete(&self, id: Uuid) -> Result<(), VdcCollectionError> { - match self.storage.remove(Self::id_to_key(id)).await { + pub fn delete(&self, id: Uuid) -> Result<(), VdcCollectionError> { + match self.storage.remove(Self::id_to_key(id)) { Ok(_) => Ok(()), Err(e) => Err(VdcCollectionError::DeleteFailed(e)), } } /// Get a list of all the credentials. - pub async fn all_entries(&self) -> Result, VdcCollectionError> { + pub 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 async fn all_entries_by_type( + pub fn all_entries_by_type( &self, ctype: &CredentialType, ) -> Result, VdcCollectionError> { - let all_entries = self.all_entries().await?; - Ok(stream::iter(all_entries) - .filter_map(|id| async move { self.get(id).await.ok().flatten() }) + let all_entries = self.all_entries()?; + Ok(all_entries + .into_iter() + .filter_map(|id| self.get(id).ok().flatten()) .collect::>() - .await .iter() .filter(|cred| &cred.r#type == ctype) .map(|cred| cred.id) @@ -116,20 +109,17 @@ impl VdcCollection { } /// Dump the contents of the credential set to the logger. - pub async fn dump(&self) { - //let span = info_span!("All Credentials"); - //span.in_scope(async || - match self.all_entries().await { + pub fn dump(&self) { + match self.all_entries() { Ok(list) => { for key in list { - if let Ok(x) = self.get(key).await { + if let Ok(x) = self.get(key) { info!("{:?}", x); } } } Err(e) => info!("Unable to get list: {:?}", e), } - //); } } @@ -160,8 +150,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().await.unwrap() { - vdc.delete(id).await.unwrap(); + for id in vdc.all_entries().unwrap() { + vdc.delete(id).unwrap(); } let payload_1: Vec = "Some random collection of bytes. ⚛".into(); let payload_2: Vec = "Some other random collection of bytes. 📯".into(); @@ -192,42 +182,33 @@ 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().await.unwrap().len() == 3); + assert!(vdc.all_entries().unwrap().len() == 3); vdc.delete(credential_2.id) - .await .expect("Failed to delete the second value."); - assert!(vdc.all_entries().await.unwrap().len() == 2); + assert!(vdc.all_entries().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().await.unwrap().len() == 0); + assert!(vdc.all_entries().unwrap().len() == 0); } }