ilap/pinenacl-dart

Second constructor for EncryptedMessage

Closed this issue ยท 2 comments

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

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

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

Cheers