Skip to content

Instantly share code, notes, and snippets.

@iosdevzone
Last active August 29, 2015 14:06
Show Gist options
  • Save iosdevzone/67fd71d4416dfd69e316 to your computer and use it in GitHub Desktop.
Save iosdevzone/67fd71d4416dfd69e316 to your computer and use it in GitHub Desktop.
/*
CommonHMac defines the following enumeration
enum {
kCCHmacAlgSHA1,
kCCHmacAlgMD5,
kCCHmacAlgSHA256,
kCCHmacAlgSHA384,
kCCHmacAlgSHA512,
kCCHmacAlgSHA224
};
typedef uint32_t CCHmacAlgorithm;
So we would like to be able to say:
enum HMacAlgorithm : CCHmacAlgorithm
{
case SHA1 = kCCHmacAlgSHA1
case MD5 = kCCHmacAlgMD5
case SHA224 = kCCHmacAlgSHA224
case SHA256 = kCCHmacAlgSHA256
case SHA384 = kCCHmacAlgSHA384
case SHA512 = kCCHmacAlgSHA512
}
but does not work. Error is "Raw value for enum case must be a literal."
So we have to do:
*/
enum HMACAlgorithm
{
case SHA1, MD5, SHA224, SHA256, SHA384, SHA512
func nativeValue() -> CCHmacAlgorithm {
switch self {
case .SHA1:
return CCHmacAlgorithm(kCCHmacAlgSHA1)
case .MD5:
return CCHmacAlgorithm(kCCHmacAlgMD5)
case .SHA224:
return CCHmacAlgorithm(kCCHmacAlgSHA224)
case .SHA256:
return CCHmacAlgorithm(kCCHmacAlgSHA256)
case .SHA384:
return CCHmacAlgorithm(kCCHmacAlgSHA384)
case .SHA512:
return CCHmacAlgorithm(kCCHmacAlgSHA512)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment