Skip to content

Instantly share code, notes, and snippets.

@baarde
Last active August 29, 2015 14:05
Show Gist options
  • Save baarde/1ea84eeaeddcd4de1f41 to your computer and use it in GitHub Desktop.
Save baarde/1ea84eeaeddcd4de1f41 to your computer and use it in GitHub Desktop.
CommonCryptoTest
#import <CommonCrypto/CommonCrypto.h>
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