From 7234d134697a84d202bcfb53e8a5b17ce64b3dd9 Mon Sep 17 00:00:00 2001 From: Tiago Nascimento Date: Wed, 11 Sep 2024 13:14:45 -0300 Subject: [PATCH] Format/lint files Signed-off-by: Tiago Nascimento --- Package.resolved | 4 +-- Sources/MobileSdk/OID4VCI.swift | 58 ++++++++++++++++----------------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/Package.resolved b/Package.resolved index 82f273c..54421ad 100644 --- a/Package.resolved +++ b/Package.resolved @@ -5,8 +5,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/spruceid/mobile-sdk-rs.git", "state" : { - "revision" : "e8a1b7056989e4cb471281b464c1aeac298be97f", - "version" : "0.0.29" + "revision" : "b1e729b2adc97415019925c873b976648a2331cb", + "version" : "0.0.30" } }, { diff --git a/Sources/MobileSdk/OID4VCI.swift b/Sources/MobileSdk/OID4VCI.swift index 1fc1fbb..ef06ab0 100644 --- a/Sources/MobileSdk/OID4VCI.swift +++ b/Sources/MobileSdk/OID4VCI.swift @@ -2,12 +2,12 @@ import Foundation import SpruceIDMobileSdkRs -public class Oid4vciSyncHttpClient : SyncHttpClient { +public class Oid4vciSyncHttpClient: SyncHttpClient { public func httpClient(request: HttpRequest) throws -> HttpResponse { guard let url = URL(string: request.url) else { throw HttpClientError.Other(error: "failed to construct URL") } - + let session = URLSession.shared var req = URLRequest(url: url, cachePolicy: .useProtocolCachePolicy, @@ -15,14 +15,14 @@ public class Oid4vciSyncHttpClient : SyncHttpClient { req.httpMethod = request.method req.httpBody = request.body req.allHTTPHeaderFields = request.headers - + // Semaphore used to wait for the callback to complete let semaphore = DispatchSemaphore(value: 0) var data: Data? var response: URLResponse? var error: Error? - + let dataTask = session.dataTask(with: req) { data = $0 response = $1 @@ -37,35 +37,35 @@ public class Oid4vciSyncHttpClient : SyncHttpClient { // Blocking wait for the callback to signal back _ = semaphore.wait(timeout: .distantFuture) - + if let error { throw HttpClientError.Other(error: "failed to execute request: \(error)") } - + guard let response = response as? HTTPURLResponse else { throw HttpClientError.Other(error: "failed to parse response") } - + guard let data = data else { throw HttpClientError.Other(error: "failed to parse response data") } - + guard let statusCode = UInt16(exactly: response.statusCode) else { throw HttpClientError.Other(error: "failed to parse response status code") } - - let headers = try response.allHeaderFields.map({ (k, v) in - guard let k = k as? String else { + + let headers = try response.allHeaderFields.map({ (key, value) in + guard let key = key as? String else { throw HttpClientError.HeaderParse } - - guard let v = v as? String else { + + guard let value = value as? String else { throw HttpClientError.HeaderParse } - - return (k, v) + + return (key, value) }) - + return HttpResponse( statusCode: statusCode, headers: Dictionary(uniqueKeysWithValues: headers), @@ -73,12 +73,12 @@ public class Oid4vciSyncHttpClient : SyncHttpClient { } } -public class Oid4vciAsyncHttpClient : AsyncHttpClient { +public class Oid4vciAsyncHttpClient: AsyncHttpClient { public func httpClient(request: HttpRequest) async throws -> HttpResponse { guard let url = URL(string: request.url) else { throw HttpClientError.Other(error: "failed to construct URL") } - + let session = URLSession.shared var req = URLRequest(url: url, cachePolicy: .useProtocolCachePolicy, @@ -86,7 +86,7 @@ public class Oid4vciAsyncHttpClient : AsyncHttpClient { req.httpMethod = request.method req.httpBody = request.body req.allHTTPHeaderFields = request.headers - + let data: Data let response: URLResponse do { @@ -94,27 +94,27 @@ public class Oid4vciAsyncHttpClient : AsyncHttpClient { } catch { throw HttpClientError.Other(error: "failed to execute request: \(error)") } - + guard let response = response as? HTTPURLResponse else { throw HttpClientError.Other(error: "failed to parse response") } - + guard let statusCode = UInt16(exactly: response.statusCode) else { throw HttpClientError.Other(error: "failed to parse response status code") } - - let headers = try response.allHeaderFields.map({ (k, v) in - guard let k = k as? String else { + + let headers = try response.allHeaderFields.map({ (key, value) in + guard let key = key as? String else { throw HttpClientError.HeaderParse } - - guard let v = v as? String else { + + guard let value = value as? String else { throw HttpClientError.HeaderParse } - - return (k, v) + + return (key, value) }) - + return HttpResponse( statusCode: statusCode, headers: Dictionary(uniqueKeysWithValues: headers),