-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow SecretBox.easy to also accept user Uint8List key instead of only generated ones #1
Comments
Hi @gabrielpacheco23 - thanks for trying out the library in it's early stages. This is actually something I had on my list for quite a while. I just pushed a commit that adds a However, I am still unsure about how the API should work with the keys. In other languages, I would just overload the methods to accept both, a SecureKey and a Uint8Array, but I can't do that in dart. So, I though about the following alternative approaches. I would like to hear your opinion, if you have one:
|
Thanks for the quick reply! Before seeing your answer I used a workaround with an extension method in the SecretBox class. That's how I made it: extension KeyExt on SecretBox {
SecureKey keyFromBytes(Uint8List rawBytes, DynamicLibrary dylib) {
final sodiumPtr = sodiumffi.SodiumPointer<Uint8>.alloc(
sodiumffi.LibSodiumFFI(dylib),
count: rawBytes.length,
);
sodiumPtr.fill(rawBytes);
return SecureKeyFFI(sodiumPtr);
}
} I dont know if that's a efficient way to fill the memory with the raw bytes but seems to work. For your question, I think that making factory constructors to Anyways, great work on making this library! I was just in need of a libsodium wrapper so this came in handy. |
You are actually quite on point with your implementation, it's basically the same thing the SecureKey classes do internally. I will close this now as the original problem was solved. If you have any other feedback, feel free to create a new one. :) |
The problem is that I can't pass my secret key array (
Uint8List
type) inside the function because it only acceptsSecureKey
instances andSecureKey
objects are only created by this library key generation.The text was updated successfully, but these errors were encountered: