"UnsafePointer< UInt8>"不能转换为"UnsafePointer< _>" [英] 'UnsafePointer<UInt8>' is not convertible to 'UnsafePointer<_>'

查看:201
本文介绍了"UnsafePointer< UInt8>"不能转换为"UnsafePointer< _>"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在执行TripleDES加密和解密.出现此错误:

I'm doing tripleDES encryption and decryption. Getting this error:

UnsafePointer<UInt8>' is not convertible to 'UnsafePointer<_>

UnsafePointer<UInt8>' is not convertible to 'UnsafePointer<_>

我得到错误的代码是:

        let keyString        = "25d1d4cb0a08403e2acbcbe0"
        let keyData = keyString.data(using: .utf8)!
        let message       = pass
        let data = message.data(using: .utf8)!
        let cryptData    = NSMutableData(length: Int(data.count) + kCCBlockSize3DES)!
        let keyLength              = size_t(kCCKeySize3DES)
        let operation: CCOperation = UInt32(kCCEncrypt)
        let algoritm:  CCAlgorithm = UInt32(kCCAlgorithm3DES)
        let options:   CCOptions   = UInt32(kCCOptionECBMode + kCCOptionPKCS7Padding)

        var numBytesEncrypted :size_t = 0

        let cryptStatus = keyData.withUnsafeBytes { (keyBytes: UnsafePointer<UInt8>) in
            data.withUnsafeBytes { (dataBytes: UnsafePointer<UInt8>) in
                cryptData.withUnsafeMutableBytes { (cryptBytes: UnsafeMutablePointer<UInt8>) in
                    CCCrypt(operation,
                            algoritm,
                            options,
                            keyBytes,
                            keyLength,
                            nil,
                            dataBytes,
                            data.count,
                            cryptBytes,
                            cryptData.count,
                            &numBytesEncrypted)
                }
            }
        }

有人可以帮忙吗?

推荐答案

此错误消息是某种编译器错误的结果:编译器无法编译代码,并发出无效且具有误导性的错误消息.另请参见 https://bugs.swift.org/browse/SR-5931

This error message is the result of a sort of compiler bug: the compiler cannot compile the code and emits an invalid and misleading error message. Also see https://bugs.swift.org/browse/SR-5931

在大多数情况下,您可以:

In most cases, you can:

  • 删除类型注释(<UInt8>)以揭示真正原因
  • 解决原因
  • 再次添加类型注释
  • remove the type annotation (<UInt8>) to reveal the real cause
  • fix the cause
  • add the type annotation again

这篇关于"UnsafePointer&lt; UInt8&gt;"不能转换为"UnsafePointer&lt; _&gt;"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆