mirror of
https://github.com/realm/SwiftLint.git
synced 2026-05-07 20:12:49 +00:00
a6c4fd98bc
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.
25 lines
597 B
Swift
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
|