Closed phimage closed 3 years ago
I make a version with CryptoKit on recent macOS, fallback to commonCrypto then on linux by importing https://github.com/apple/swift-crypto but again this a mess, not same name, need to specify the name in Package.swift... I do not want to import on macOS, so that's I have no committed yet
#if os(Linux)
import Crypto
#else
import CommonCrypto
private extension Data {
func sha1_common() -> Data {
return withUnsafeBytes { [count] ptr in
var hash = [UInt8](repeating: 0, count: Int(CC_SHA1_DIGEST_LENGTH))
if let bytes = ptr.baseAddress?.assumingMemoryBound(to: UInt8.self) {
CC_SHA1(bytes, CC_LONG(count), &hash)
}
return Data(hash)
}
}
}
#if canImport(CryptoKit)
import CryptoKit
#endif
#endif
private extension Data {
func sha1() -> Data {
#if os(Linux)
return Data(Insecure.SHA1.hash(data: self))
#else
#if canImport(CryptoKit)
if #available(OSX 10.15, *) {
return Data(Insecure.SHA1.hash(data: self))
} else {
return sha1_common()
}
#else
return sha1_common()
#endif
#endif
}
}
I keep legacy sha1 using commonCrypto on Mac and find a way to add only for linux the swift-crypto package
package swift file is 5.0; if updated to 5.2 some change must done "use .product() for dependencies"
It's ready for review
Sorry for late response 🙇
There is still an issue with sha1 in LintCache