Files
Danny Mösch a6c4fd98bc Move files from SwiftLintCore to SwiftLintFramework
Ideally, SwiftLintCore would some day only contain components
that are needed to define rules. Consequently, it would be the
only bundle required to import for (external) rule development.
2024-12-23 12:51:43 +01:00

25 lines
597 B
Swift

#if canImport(CommonCrypto)
import CommonCrypto
import Foundation
extension Data {
internal func sha256() -> Data {
withUnsafeBytes { bytes in
var hash = [UInt8](repeating: 0, count: Int(CC_SHA256_DIGEST_LENGTH))
_ = CC_SHA256(bytes.baseAddress, CC_LONG(count), &hash)
return Data(hash)
}
}
internal func toHexString() -> String {
reduce(into: "") { $0.append(String(format: "%02x", $1)) }
}
}
extension String {
internal func sha256() -> String {
data(using: .utf8)!.sha256().toHexString()
}
}
#endif