ilap / pinenacl-dart

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

Second constructor for EncryptedMessage #3

Closed MarcelGarus closed 4 years ago

MarcelGarus commented 4 years ago

Hi 😄 I'm using your package and it's been fun so far. I'm doing a networking application, where Uint8Lists are sent back and forth, containing data encrypted by your SecretBox. Because EncryptedMessage extends ByteList, which in turn implements Uint8List, it's really easy to encrypt data and send it. On the other side though, some boilerplate is necessary to convert a received Uint8List to an EncryptedMessage in order to decrypt it. That means, I manually have to do the following, which seems hacky because I need to know the underlying implementation details of the EncryptedMessage:

final encrypted = EncryptedMessage(
  nonce: encryptedBytes.sublist(0, TweetNaCl.nonceLength),
  cipherText: encryptedBytes.sublist(TweetNaCl.nonceLength),
);
return SecretBox(key).decrypt(encrypted);

It would be really helpful if EncryptedMessage had a constructor that simply took a Uint8List.

ilap commented 4 years ago

Hi,

Glad to hear that.

So, similar constructor would do, but should need some checks before apply.

  EncryptedMessage.fromList({List<int> list})
      : super.fromList(list, nonceLength /* nonceLength as min length */);
ilap commented 4 years ago

Fixed and package also uploaded. So use the v0.1.3.-dev.1 one.

Cheers