ilap / pinenacl-dart

The Dart implementation of the PyNaCl API with the TweetNaCl cryptographic library
MIT License
36 stars 4 forks source link

LateInitializationError: Field 'prefixLength' has not been initialized - take 2 #18

Closed reaster closed 2 years ago

reaster commented 2 years ago

PublicKey, PrivateKey and VerifyKey still don't have a prefixLength getter. Neither the compiler nor runtime seem to catch this until prefixLength is accessed. If you make this change:

mixin Suffix on ByteList {
  // late final int prefixLength; - silently breaks Dart's null safety
  int get prefixLength;
  ByteList get prefix => ByteList(take(prefixLength), prefixLength);
  ByteList get suffix => ByteList(skip(prefixLength), length - prefixLength);
}  

The compiler picks up the problem. Or you can add

  assert(publicKey.prefixLength == 32);
  assert(publicKey == verifyKey);  

to signature.dart.

ilap commented 2 years ago

Hi,

Thank you.

I think those type of keys should not have any prefix and suffix implemented. Also, assert would not work in production code. So, I made Suffix mixin more specific to only the relevant classes and removed from unnecessary ones.

I will commit and close it soon.

Cheers,

Pal

ilap commented 2 years ago

Updated the pub.dev package.

reaster commented 2 years ago

Hi Pal, Thanks for the quick turnaround! Unfortunately, I can't use it with the latest bip32-ed25519-dart due to a few breaking changes. Any chance I could cajole you into doing an update on that project? Warm regards, Richard

ilap commented 2 years ago

Hi,

The bip32-ed25519-dart is updated to v0.3.1 to be compatible with the pinenacl v0.3.5

Cheers,

Pal

reaster commented 2 years ago

Looking good on my end. Thanks again!