I try to port a framework written in Swift 5 to Swift 4.2. And encounter syntax error I can't understand.
Code:
Code Block private static func ccAESKeyWrap( rawKey: Data, keyEncryptionKey: Data) -> (data: Data?, status: Int32) { let alg = CCWrappingAlgorithm(kCCWRAPAES) var wrappedKeyLength: size_t = CCSymmetricWrappedSize(alg, rawKey.count) var wrappedKey = Data(count: wrappedKeyLength) let status = wrappedKey.withUnsafeMutableBytes { (wrappedKeyBytes: UnsafeMutablePointer) in rawKey.withUnsafeBytes { (rawKeyBytes: UnsafePointer) in keyEncryptionKey.withUnsafeBytes { (keyEncryptionKeyBytes: UnsafePointer) -> Int32 in guard let wrappedKeyBytes = wrappedKeyBytes.bindMemory(to: UInt8.self).baseAddress, let rawKeyBytes = rawKeyBytes.bindMemory(to: UInt8.self).baseAddress, let keyEncryptionKeyBytes = keyEncryptionKeyBytes.bindMemory(to: UInt8.self).baseAddress else { return Int32(kCCMemoryFailure) } return CCSymmetricKeyWrap( alg, CCrfc3394_iv, CCrfc3394_ivLen, keyEncryptionKeyBytes, keyEncryptionKey.count, rawKeyBytes, rawKey.count, wrappedKeyBytes, &wrappedKeyLength) } } } guard status == kCCSuccess else { return (nil, status) } wrappedKey.removeSubrange(wrappedKeyLength..<wrappedKey.count) return (wrappedKey, status) }
On string
Code Block keyEncryptionKey.withUnsafeBytes { (keyEncryptionKeyBytes: UnsafePointer) -> Int32 in
I got the error:
Cannot convert value of type '(UnsafePointer<>) -> Int32' to expected argument type '(UnsafePointer<>) -> '_
Could anyone tell me what do I do wrong ?