Some bug fixes (#8)

This PR contains the work done to fix some bug fixes that were encountered while quickly testing the interactions with the service endpoints. Furthermore, there is also a possible fix to build this library for non-apple platforms.

Reviewed-on: #8
Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
This commit was merged in pull request #8.
This commit is contained in:
2025-10-05 22:05:07 +00:00
committed by Javier Cicchelli
parent d5bd9feb0a
commit a83da81414
7162 changed files with 7199 additions and 7186 deletions
@@ -10,7 +10,13 @@
//
//===----------------------------------------------------------------------===
#if canImport(CriptoKit)
import CryptoKit
#elseif canImport(Crypto)
import Crypto
#else
import CommonCrypto
#endif
import struct Foundation.Data
import struct Foundation.TimeInterval
@@ -51,10 +57,33 @@ struct GenerateHashUseCase {
let stringToHash = timestamp.asString + self.privateKey + self.publicKey
let dataToHash = Data(stringToHash.utf8)
#if canImport(CriptoKit) || canImport(Crypto)
return Insecure.MD5
.hash(data: dataToHash)
.map { String(format: "%02x", $0) }
.map { String(format: .Format.hexadecimal, $0) }
.joined()
#else
return dataToHash
.withUnsafeBytes {
var hash = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
CC_MD5($0.baseAddress, CC_LONG(dataToHash.count), &hash)
return hash
}
.map { String(format: .Format.hexadecimal, $0) }
.joined()
#endif
}
}
// MARK: - Constants
private extension String {
/// A namespace assigned to string format representations.
enum Format {
/// A string format for MD5 hash hexadecimal bytes.
static let hexadecimal = "%02x"
}
}