Skip to content

Commit

Permalink
Move md5 string extension to own file
Browse files Browse the repository at this point in the history
  • Loading branch information
jkroepke committed Nov 10, 2020
1 parent e034322 commit ed78502
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 39 deletions.
19 changes: 0 additions & 19 deletions Source/SwiftLintFramework/Extensions/Configuration+Cache.swift
Original file line number Diff line number Diff line change
@@ -1,24 +1,5 @@
#if canImport(CommonCrypto)
import CommonCrypto
#else
import CryptoSwift
#endif
import Foundation

#if canImport(CommonCrypto)
private extension String {
func md5() -> String {
let context = UnsafeMutablePointer<CC_MD5_CTX>.allocate(capacity: 1)
var digest = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
CC_MD5_Init(context)
CC_MD5_Update(context, self, CC_LONG(lengthOfBytes(using: .utf8)))
CC_MD5_Final(&digest, context)
context.deallocate()
return digest.reduce(into: "") { $0.append(String(format: "%02x", $1)) }
}
}
#endif

extension Configuration {
// MARK: Caching Configurations By Path (In-Memory)

Expand Down
20 changes: 20 additions & 0 deletions Source/SwiftLintFramework/Extensions/String+md5.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#if canImport(CommonCrypto)
import CommonCrypto
#else
import CryptoSwift
#endif
import Foundation

#if canImport(CommonCrypto)
extension String {
internal func md5() -> String {
let context = UnsafeMutablePointer<CC_MD5_CTX>.allocate(capacity: 1)
var digest = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
CC_MD5_Init(context)
CC_MD5_Update(context, self, CC_LONG(lengthOfBytes(using: .utf8)))
CC_MD5_Final(&digest, context)
context.deallocate()
return digest.reduce(into: "") { $0.append(String(format: "%02x", $1)) }
}
}
#endif
21 changes: 1 addition & 20 deletions Source/SwiftLintFramework/Reporters/CodeClimateReporter.swift
Original file line number Diff line number Diff line change
@@ -1,26 +1,7 @@
#if canImport(CommonCrypto)
import CommonCrypto
#else
import CryptoSwift
#endif
import Foundation
import SourceKittenFramework

#if canImport(CommonCrypto)
private extension String {
func md5() -> String {
let context = UnsafeMutablePointer<CC_MD5_CTX>.allocate(capacity: 1)
var digest = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
CC_MD5_Init(context)
CC_MD5_Update(context, self, CC_LONG(lengthOfBytes(using: .utf8)))
CC_MD5_Final(&digest, context)
context.deallocate()
return digest.reduce(into: "") { $0.append(String(format: "%02x", $1)) }
}
}
#endif

/// Reports violations as a JSON array.
/// Reports violations as a JSON array in Code Climate format.
public struct CodeClimateReporter: Reporter {
// MARK: - Reporter Conformance

Expand Down

0 comments on commit ed78502

Please sign in to comment.