Last active
August 29, 2015 14:05
-
-
Save baarde/1ea84eeaeddcd4de1f41 to your computer and use it in GitHub Desktop.
CommonCryptoTest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <CommonCrypto/CommonCrypto.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol Digestible { | |
func sha1Digest() -> [UInt8] | |
} | |
extension Array : Digestible { | |
func sha1Digest() -> [UInt8] { | |
return self.withUnsafeBufferPointer { (arrayBuffer) -> [UInt8] in | |
var hash = Array<UInt8>(count: Int(CC_SHA1_DIGEST_LENGTH), repeatedValue: 0) | |
CC_SHA1(unsafeBitCast(arrayBuffer, UnsafePointer<Void>.self), UInt32(self.count * sizeof(T)), &hash) | |
return hash | |
} | |
} | |
} | |
let array : [Double] = [0, 1, 2, 3, 4, 5, 6] | |
println(array.sha1Digest()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment