在 Swift 中使用 CommonCrypto 会生成不安全的扩展警告

Using CommonCrypto in Swift generates not safe for use in extensions warning

我创建了一个简单的库来为 Swift 使用 HMAC 摘要,名为 "SweetHMAC"。这个库非常简单,基本上是 Swift.

中 CommonHMAC.h 的包装器

我可以正确地使用 SweetHMAC 构建和部署任何 iOS 项目,但是,由于某些安全问题,我的方法似乎并不安全。例如,我在 运行 iOS 测试后收到警告。

warning: linking against dylib not safe for use in application extensions

此代码不够安全,无法放入 iOS AppStore,应用可能会被拒绝。对于OSX,没有问题。

我知道,Swift 有 HMAC 端口,但我的挑战是尝试启用 Swift 以安全地使用 CommonCrypto。

我已经使用 this approach 实现了这个项目并且工作正常!

我的问题是,如何在 Swift 框架中为 iOS 安全地创建和使用像 CommonCrypto 这样的模块?

查看 Apple 的文档,针对上述错误的建议是确保选中使用 "Require Only App-Extension-Safe API" 的选项。

To configure an app extension target to use an embedded framework, set the target’s “Require Only App-Extension-Safe API” build setting to Yes. If you don’t, Xcode reminds you to do so by displaying the warning “linking against dylib not safe for use in application extensions”.

Here's the full documentation on extensions

还值得注意的是,根据 this discussion

,CommonCrypto API 的部分内容可能不可用