pushEx abstract method
- required Stream<
SecretStreamPlainMessage> messageStream, - required SecureKey key,
Provides crypto_secretstream_xchacha20poly1305_(init_)push.
Transforms the messageStream
of plaintext messages to an encrypted
stream using crypto_secretstream_xchacha20poly1305_push with the given
key
.
Unlike the C API, which requires manual state management etc., this API
combines all the required parts into a single, simple dart stream. As a
first step, crypto_secretstream_xchacha20poly1305_init_push is used to
generate the stream state from the key
and the created header is sent
as the first message of the returned SecretExStream. After that, any
plain message (optionally with additional data and a tag) that is passed
in via messageStream
is encrypted with
crypto_secretstream_xchacha20poly1305_push.
The stream also handles it's internal state gracefully and can react to tags and problems with the encryption, if the occur. It is also possible to explicitly rekey the stream via SecretExStream.rekey.
Note: If you want to gracefully end a push stream, the last message
needs to have the SecretStreamMessageTag.finalPush tag. After that, you
must not send any other messages and close the messageStream
. If you
close the stream without the tag, an empty message is automatically
created and sent before the returned stream gets closed.
This method is basically a shortcut for createPushEx.bind(). Check the documentation of createPushEx if you need a transformer instead of a stream.
See https://libsodium.gitbook.io/doc/secret-key_cryptography/secretstream#encryption
Implementation
SecretExStream<SecretStreamCipherMessage> pushEx({
required Stream<SecretStreamPlainMessage> messageStream,
required SecureKey key,
});