Skip to content
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

Error trying to "sign" (using the example snippet) #27

Closed
budo76 opened this issue Jul 3, 2020 · 4 comments
Closed

Error trying to "sign" (using the example snippet) #27

budo76 opened this issue Jul 3, 2020 · 4 comments

Comments

@budo76
Copy link

budo76 commented Jul 3, 2020

I just copy pasted the example and I got the error when trying to call "sign":
Unhandled Exception: NoSuchMethodError: The getter 'name' was called on null.
Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)
_PluginKeyDocument.sign. (package:kms_flutter/src/plugin_kms.dart:205:31)
Iterable.singleWhere (dart:core/iterable.dart:618:15)
_PluginKeyDocument.sign (package:kms_flutter/src/plugin_kms.dart:205:10)

From my understanding in "defaultSignatureImplementations" there's a null. I tried to print the content and there's an instance of
'_Ed25519' and a 'null'. You can see this even in the sources that it's a map with two value. The last is null. So the sign method just throw exception while accessing the null.
Sure, at "plugin_kms.dart:205" the "singleWhere" should just find the algorithm Ed25519 and stop before analysing the null ... I don't know why (and this is another issue) but still having that null in "defaultSignatureImplementations" is bad (or at least it should be managed).
Any idea? Why is it not working?
(tried on emulator and real Android device with Oreo)

@budo76 budo76 changed the title Error trying to use (from example) Error trying to "sign" (using the example snippet) Jul 3, 2020
@RimaitosLab
Copy link

Which snippet are you referring to?

@budo76
Copy link
Author

budo76 commented Sep 15, 2020

Which snippet are you referring to?

I tried the snippet in the main README of the "kms" project (2. "use") here:
https://pub.dev/packages/kms
More specifically this was the snippet I used, just to test a signature of a 3-bytes sequence, with Ed22519:

// ...
final kms = flutterKms();
final document = await kms.collection('examples').createKeyPair(
    keyExchangeType: null, // no key exchange.
    signatureType: SignatureType.ed25519,
);
final pk = await document.getPublicKey();
print("Public key: ${pk.bytes}");
// Sign a document
final signature = await document.sign([1,2,3]);

In the call to the sign method I had the error, as I wrote, because in defaultSignatureImplementations (I think it's from the "cryptography" lib) there's a null in the list (don't know why - this is out of my control) and no null-check while using list items with the "singleWhere" statement here:

.singleWhere((c) => c.name == algName);

The desired "ed25519" implementation is the first element of the list, but singleWhere scans all the items in the list (not stopping at first match) so when you access the "name" property of the null item, you have the error. Perhaps just a c?.name would prevent the singleWhere from causing the error but, in my opinion, having a null in the list is still not good.
What do you think? Is there something I'm missing or doing wrong , to prevent the defaultSignatureImplementations from containing a null?

@bkreiser
Copy link

bkreiser commented Dec 9, 2020

I have the same issue. Has there been any workaround to this?

@terrier989
Copy link
Member

The kms package is deprecated for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants