Closed 5inline closed 5 years ago
Downgrading to XCode 9.x, and using SWIFT_VERSION = '3.2' seems to build successfully.
Thanks for the follow-up. Swift (and Java) interop is a bit of a mess. I'm currently working on a FFI rewrite of flutter_sodium, where both Swift and Java are no longer needed. Dart FFI is currently in preview, and will hopefully be available soon.
yeah, hope to use FFI version of flutter_sodium~
Thanks for the follow-up. Swift (and Java) interop is a bit of a mess. I'm currently working on a FFI rewrite of flutter_sodium, where both Swift and Java are no longer needed. Dart FFI is currently in preview, and will hopefully be available soon.
Thanks for the hard work already. Do you know if there is a way to get it to build in Xcode 10? Seems like app store submissions won't be accepted unless built in Xcode 10...
I have this compiling on Xcode 10 Swift 5.0, made the following changes to the SwiftFlutterSodiumPlugin.swift file, tested cryptoBoxSeal and Open seems to work. The changes to the three functions that were were giving errors are as below
private func crypto_generichash_init(call: FlutterMethodCall) -> Any
{
let args = call.arguments as! NSDictionary
let key: Data? = (args["key"] as? FlutterStandardTypedData)?.data
let outlen = args["outlen"] as! Int
var ret: Int32 = -1
var state = Data(count: crypto_generichash_statebytes())
// Added these two lines
let umBytes = UnsafeMutablePointer
if let key = key {
**// Removed this line: ret = state.withUnsafeMutableBytes { statePtr in**
key.withUnsafeBytes { keyPtr in
**flutter_sodium.crypto_generichash_init(oP, keyPtr, key.count, outlen)
// Old function call: flutter_sodium.crypto_generichash_init(statePtr, keyPtr, key.count, outlen)**
}
**// Removed this bracket: }**
}
else {
ret = state.withUnsafeMutableBytes { statePtr in
**// Old function call: flutter_sodium.crypto_generichash_init(statePtr, nil, 0, outlen)
flutter_sodium.crypto_generichash_init(oP, nil, 0, outlen)**
}
}
return error(ret: ret) ?? FlutterStandardTypedData.init(bytes: state)
}
private func crypto_generichash_update(call: FlutterMethodCall) -> Any { let args = call.arguments as! NSDictionary var state = (args["state"] as! FlutterStandardTypedData).data // Added this line let state2 = args["state"] as! OpaquePointer let i = (args["in"] as! FlutterStandardTypedData).data
let ret = state.withUnsafeMutableBytes { statePtr in
i.withUnsafeBytes { iPtr in
**// Old function call: flutter_sodium.crypto_generichash_update(statePtr, iPtr, CUnsignedLongLong(i.count))
flutter_sodium.crypto_generichash_update(state2, iPtr, CUnsignedLongLong(i.count))**
}
}
return error(ret: ret) ?? FlutterStandardTypedData.init(bytes: state)
}
private func crypto_generichash_final(call: FlutterMethodCall) -> Any { let args = call.arguments as! NSDictionary var state = (args["state"] as! FlutterStandardTypedData).data // Added this line let state2 = args["state"] as! OpaquePointer let outlen = args["outlen"] as! Int
var out = Data(count: outlen)
let ret = state.withUnsafeMutableBytes { statePtr in
out.withUnsafeMutableBytes { outPtr in
**// Old function call: flutter_sodium.crypto_generichash_final(statePtr, outPtr, outlen)
flutter_sodium.crypto_generichash_final(state2, outPtr, outlen)**
}
}
return error(ret: ret) ?? FlutterStandardTypedData.init(bytes: out)
}
I have this compiling on Xcode 10 Swift 5.0, made the following changes to the SwiftFlutterSodiumPlugin.swift file, tested cryptoBoxSeal and Open seems to work. The changes to the three functions that were were giving errors are as below
private func crypto_generichash_init(call: FlutterMethodCall) -> Any { let args = call.arguments as! NSDictionary let key: Data? = (args["key"] as? FlutterStandardTypedData)?.data let outlen = args["outlen"] as! Int var ret: Int32 = -1 var state = Data(count: crypto_generichash_statebytes()) // Added these two lines let umBytes = UnsafeMutablePointer.allocate(capacity: crypto_generichash_statebytes()) let oP = OpaquePointer(umBytes)
if let key = key { **// Removed this line: ret = state.withUnsafeMutableBytes { statePtr in** key.withUnsafeBytes { keyPtr in **flutter_sodium.crypto_generichash_init(oP, keyPtr, key.count, outlen) // Old function call: flutter_sodium.crypto_generichash_init(statePtr, keyPtr, key.count, outlen)** } **// Removed this bracket: }** } else { ret = state.withUnsafeMutableBytes { statePtr in **// Old function call: flutter_sodium.crypto_generichash_init(statePtr, nil, 0, outlen) flutter_sodium.crypto_generichash_init(oP, nil, 0, outlen)** } } return error(ret: ret) ?? FlutterStandardTypedData.init(bytes: state)
}
private func crypto_generichash_update(call: FlutterMethodCall) -> Any { let args = call.arguments as! NSDictionary var state = (args["state"] as! FlutterStandardTypedData).data // Added this line let state2 = args["state"] as! OpaquePointer let i = (args["in"] as! FlutterStandardTypedData).data
let ret = state.withUnsafeMutableBytes { statePtr in i.withUnsafeBytes { iPtr in **// Old function call: flutter_sodium.crypto_generichash_update(statePtr, iPtr, CUnsignedLongLong(i.count)) flutter_sodium.crypto_generichash_update(state2, iPtr, CUnsignedLongLong(i.count))** } } return error(ret: ret) ?? FlutterStandardTypedData.init(bytes: state)
}
private func crypto_generichash_final(call: FlutterMethodCall) -> Any { let args = call.arguments as! NSDictionary var state = (args["state"] as! FlutterStandardTypedData).data // Added this line let state2 = args["state"] as! OpaquePointer let outlen = args["outlen"] as! Int
var out = Data(count: outlen) let ret = state.withUnsafeMutableBytes { statePtr in out.withUnsafeMutableBytes { outPtr in **// Old function call: flutter_sodium.crypto_generichash_final(statePtr, outPtr, outlen) flutter_sodium.crypto_generichash_final(state2, outPtr, outlen)** } } return error(ret: ret) ?? FlutterStandardTypedData.init(bytes: out)
}
same for me. tried this but got
"error:
generic parameter 'Pointee' could not be inferred
let umBytes = UnsafeMutablePointer.allocate(capacity:
crypto_generichash_statebytes())
^
Swift.UnsafeMutablePointer:1:15: note: 'Pointee' declared as parameter
to type 'UnsafeMutablePointer'
public struct UnsafeMutablePointer
any update on this issue?
Hi Claudio,
looks like you have missed the
I have also now added the following two lines before the return in an attempt to ensure that the state ptr is also returned
let bufferPointer = UnsafeRawPointer(umBytes)
state = Data(bytes: bufferPointer, count: crypto_generichash_statebytes())
Ensure that SWIFT_VERSION in your podfile is 5.0, otherwise the compile will throw even more errors !
note of caution: although these changes allow the code to compile I have not thoroughly tested these changes to ensure that these functions continue to work as intended, please test for your use case and use carefully.
the best solution would be an updated solution from the author.
for some reason the submission removes the UInt8 type in angled brackets from the text !
I'll try again, the let should look like this
let umBytes = UnsafeMutablePointer<UInt8>.allocate(capacity: crypto_generichash_statebytes())
This is good feedback. I'll try to update the source asap.
Keep in mind that the current flutter_sodium source will be replaced eventually by an FFI implementation
Version 0.0.10 has just been made available addressing the problems mentioned here.
Created a new Flutter project with
-i swift -a kotlin
options, addedflutter_sodium: ^0.0.9
to pubspec.yaml.During debug build, I get the following errors:
$ flutter doctor
Podfile