From 903bfcd7c435736f662743bd6826f75be6e1063f Mon Sep 17 00:00:00 2001 From: Avril Date: Fri, 20 Aug 2021 21:24:59 +0100 Subject: [PATCH] Added `from_parts()`, as counterpart to `into_parts()`. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fortune for chacha20stream's current commit: Half blessing − 半吉 --- Cargo.toml | 2 +- src/stream/sink.rs | 9 +++++++++ src/stream/source.rs | 8 ++++++++ src/stream_async/sink.rs | 10 ++++++++++ src/stream_async/source.rs | 11 +++++++++++ 5 files changed, 39 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 6027a18..fb23873 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "chacha20stream" -version = "2.1.0" +version = "2.2.0" keywords = ["chacha20_poly1305", "stream", "wrapper", "encryption", "decryption"] description = "A writable wrapper stream for encryption and decryption with the stream cipher chacha20_poly1305" homepage = "https://git.flanchan.moe/flanchan/chacha20stream" diff --git a/src/stream/sink.rs b/src/stream/sink.rs index 50383af..cd54366 100644 --- a/src/stream/sink.rs +++ b/src/stream/sink.rs @@ -144,6 +144,15 @@ where W: Write { (self.stream, self.crypter) } + + /// Create a sink from a stream and a crypter + /// + /// The counterpart to `into_parts()`. + #[inline] pub fn from_parts(stream: W, crypter: Crypter) -> Self + { + Self::new(stream, crypter) + } + } diff --git a/src/stream/source.rs b/src/stream/source.rs index 583ca23..68121ff 100644 --- a/src/stream/source.rs +++ b/src/stream/source.rs @@ -242,6 +242,14 @@ where R: Read { (self.stream, self.crypter) } + + /// Create a source from a stream and a crypter + /// + /// The counterpart to `into_parts()`. + #[inline] pub fn from_parts(stream: R, crypter: Crypter) -> Self + { + Self::new(stream, crypter) + } } diff --git a/src/stream_async/sink.rs b/src/stream_async/sink.rs index b4eded4..e77de16 100644 --- a/src/stream_async/sink.rs +++ b/src/stream_async/sink.rs @@ -108,6 +108,16 @@ impl Sink { (self.stream, self.crypter) } + + /// Create a sink from a stream and a crypter + /// + /// The counterpart to `into_parts()`. + #[inline] pub fn from_parts(stream: W, crypter: Crypter) -> Self + { + Self { + stream, crypter + } + } /// The crypter of this instance #[inline] pub fn crypter(&self) -> &Crypter diff --git a/src/stream_async/source.rs b/src/stream_async/source.rs index c74aab1..fe4cd72 100644 --- a/src/stream_async/source.rs +++ b/src/stream_async/source.rs @@ -74,6 +74,17 @@ impl Source (self.stream, self.crypter) } + /// Create a source from a stream and a crypter + /// + /// The counterpart to `into_parts()`. + #[inline] pub fn from_parts(stream: R, crypter: Crypter) -> Self + { + Self { + stream, crypter + } + } + + /// The crypter of this instance #[inline] pub fn crypter(&self) -> &Crypter {