【发布时间】:2021-01-12 02:25:43
【问题描述】:
Swift 5、iOS 14
试图理解其他人的代码我需要一些帮助,因为但我不确定我是否清楚地理解了 SHA1_UPDATE SHA1_FINAL 函数。
这是在做什么——
private func computeHash() -> Data {
let identifierData = getDeviceIdentifier()
var ctx = SHA_CTX()
SHA1_Init(&ctx)
// 它创建标识符字节的 sha-1 哈希并将它们放入 &CTX 内存中
let identifierBytes: [UInt8] = .init(identifierData)
SHA1_Update(&ctx, identifierBytes, identifierData.count)
// 然后它创建 opaqueBytes 的 sha-1 哈希,然后将它们添加到? &CTX 内存?
let opaqueBytes: [UInt8] = .init(opaqueData!)
SHA1_Update(&ctx, opaqueBytes, opaqueData!.count)
// 再次执行此操作,创建 bundleBytes 的 sha-1 哈希,然后将它们添加到 &CTX 内存中
let bundleBytes: [UInt8] = .init(bundleIdData!)
SHA1_Update(&ctx, bundleBytes, bundleIdData!.count)
// 然后用数据再创建一个?
var hash: [UInt8] = .init(repeating: 0, count: 20)
SHA1_Final(&hash, &ctx)
return Data(bytes: hash, count: 20)
}
【问题讨论】: