Skip to content

Commit

Permalink
swift6
Browse files Browse the repository at this point in the history
Signed-off-by: Nikhil Nigade <[email protected]>
  • Loading branch information
dezinezync committed Jul 9, 2024
1 parent 139ce0e commit a8532ce
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Sources/DZNetworking/Core/DZOAuthSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

enum OAuthError: LocalizedError {
enum OAuthError: LocalizedError, Sendable {
/// an auth session is already in progress
case activeAuthState
/// an invalid or no state token was received in the oauth verification callback
Expand Down
12 changes: 12 additions & 0 deletions Sources/DZNetworking/Core/DZURLSession+Codable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ extension DZURLSession {
throw PublicError.expectedData
}

if data.isEmpty {
return (nil, response)
}

let decoder = decoder ?? DZURLSession.decoder
let object = try decoder.decode(T.self, from: data)
return (object, response)
Expand All @@ -48,6 +52,10 @@ extension DZURLSession {
throw PublicError.expectedData
}

if data.isEmpty {
return (nil, response)
}

let decoder = decoder ?? DZURLSession.decoder
let object = try decoder.decode(T.self, from: data)
return (object, response)
Expand All @@ -68,6 +76,10 @@ extension DZURLSession {
throw PublicError.expectedData
}

if data.isEmpty {
return (nil, response)
}

let decoder = decoder ?? DZURLSession.decoder
let object = try decoder.decode(T.self, from: data)
return (object, response)
Expand Down
40 changes: 33 additions & 7 deletions Sources/DZNetworking/HTTPURLRQ/HTTPURLRQ.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import AppKit
#endif

/// This is Swift port OMGHTTPURLRQ
struct HTTPURLRQ {
struct HTTPURLRQ: Sendable {
static let userAgent: String = {
var ua = ""
let info = Bundle.main.infoDictionary
Expand All @@ -28,13 +28,39 @@ struct HTTPURLRQ {

#if canImport(UIKit)
#if os(watchOS)
let scale = 2.0
let device = WKInterfaceDevice.current().model
let systemVersion = WKInterfaceDevice.current().systemVersion
let scale: CGFloat = 2.0
var device: String
var systemVersion: String

if Thread.isMainThread {
device = WKInterfaceDevice.current().model
systemVersion = WKInterfaceDevice.current().systemVersion
}
else {
DispatchQueue.main.sync {
device = WKInterfaceDevice.current().model
systemVersion = WKInterfaceDevice.current().systemVersion
}
}
#else
let scale = UIScreen.main.scale
let device = UIDevice.current.model
let systemVersion = UIDevice.current.systemVersion
var scale: CGFloat = 2.0
var device: String = ""
var systemVersion: String = ""

if Thread.isMainThread {
MainActor.assumeIsolated {
scale = UIScreen.main.scale
device = UIDevice.current.model
systemVersion = UIDevice.current.systemVersion
}
}
else {
DispatchQueue.main.sync {
scale = UIScreen.main.scale
device = UIDevice.current.model
systemVersion = UIDevice.current.systemVersion
}
}
#endif

#if os(tvOS)
Expand Down
16 changes: 8 additions & 8 deletions Sources/DZNetworking/Utilities/DZS3CredentialsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@
import Foundation
import CommonCrypto

public enum DZS3Error: LocalizedError {
public enum DZS3Error: LocalizedError, Sendable {
case incompleteParamters
}

/// The Access-Control-List used for the uploaded object. Can be `public` or `private`, defaults to `public`.
public enum DZACL: String {
public enum DZACL: String, Sendable {
case `private`
case `public`
}

/// The S3 at-rest encryption used for the uploaded object. `none` by default.
public enum DZS3Encryption: String {
public enum DZS3Encryption: String, Sendable {
case `none`
case AES256
}

/// Credentials manager for S3 operations
public struct DZS3CredentialsManager {
public struct DZS3CredentialsManager: Sendable {
/// the `AWSAccessKey`
public let key: String
/// the `AWSSecretKey`
Expand Down Expand Up @@ -174,9 +174,9 @@ public struct DZS3CredentialsManager {
}
}

private extension String {
extension String {

func sha256() -> String {
public func sha256() -> String {
guard let data = self.data(using: .utf8) else { return "" }
var hash = [UInt8](repeating: 0, count: Int(CC_SHA256_DIGEST_LENGTH))
data.withUnsafeBytes {
Expand Down Expand Up @@ -204,8 +204,8 @@ private extension String {
}
}

private extension Data {
func toHexString() -> String {
extension Data {
public func toHexString() -> String {
let hexString = self.map{ String(format:"%02x", $0) }.joined()
return hexString
}
Expand Down

0 comments on commit a8532ce

Please sign in to comment.