I am trying to use async await / Promise. I have a function like this:
extension DemoWebCrypto {
class func runWEC(password: String, encrypted: Data) {
let crypto = WebCrypto()
crypto.decrypt(data: encrypted,
password: password,
callback: { (decrypted: Data?, error: Error?) in
print("Error:", error)
let text = String(data: decrypted!, encoding: .utf8)
print("decrypt:", text)
})
}
}
Normally we call this function like this
let enc1 = "......."
let password = "....."
let data1 = Data(base64Encoded: enc1, options: .ignoreUnknownCharacters)!
DemoWebCrypto.runEC(password: password, encrypted: data1) {
}
So I want to remove this trailing closure implementation via AwaitKit i.e. want to replace via async await way.
How I do that so I can get the string? Something like
let result = try await(DemoWebCrypto.runWEC(password: ..., encrypted: ...))
print(result) // the decrypt text