简体   繁体   中英

Cannot invoke 'CCHmac' with an argument list of type '(UInt32, UnsafePointer<Int8>, UInt, [CChar], Int, UnsafeMutablePointer<CUnsignedChar>)

I updated xCode and/or swift 1.0 to 1.2 and got lots of errors,

I knew some of the methods are updated/Changed in Swift 1.2 hence I started updating my whole project to swift 1.2. I am stuck on this line:

CCHmac(CCHmacAlgorithm(kCCHmacAlgSHA1), cKey, strlen(cKey), str!, strLen, result)

It's throwing error Cannot invoke 'CCHmac' with an argument list of type '(UInt32, UnsafePointer<Int8>, UInt, [CChar], Int, UnsafeMutablePointer<CUnsignedChar>)'

here is my code

.
.
.
 let str = cred.cStringUsingEncoding(NSUTF8StringEncoding)
        let strLen:Int = Int(cred.lengthOfBytesUsingEncoding(NSUTF8StringEncoding))
        let digestLen = Int(CC_SHA1_DIGEST_LENGTH)
        let result = UnsafeMutablePointer<CUnsignedChar>.alloc(digestLen)
        let objcKey = key as NSString
        let keyStr = Key.cStringUsingEncoding(NSUTF8StringEncoding)
        let keyLen:Int = Int(Key.lengthOfBytesUsingEncoding(NSUTF8StringEncoding))

        var st:NSString = dataFromHexadecimalString(Key)!
        let cKey = st.cStringUsingEncoding(NSUTF8StringEncoding)


        CCHmac(CCHmacAlgorithm(kCCHmacAlgSHA1), cKey, strlen(cKey), str!, strLen, result)
.
.
.

Note: I changed keyLen and strLen from Uint to Int but still its throwing the same error.

I solved it just cast the strlen(cKey) to int like Int(strlen(cKey))

whole line look like is

CCHmac(CCHmacAlgorithm(kCCHmacAlgSHA1), cKey, Int(strlen(cKey)), str!, strLen, result)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM