diff --git a/secio/src/codec/secure_stream.rs b/secio/src/codec/secure_stream.rs index ebbf4b21..5fcb5908 100644 --- a/secio/src/codec/secure_stream.rs +++ b/secio/src/codec/secure_stream.rs @@ -22,7 +22,7 @@ enum RecvBuf { } impl RecvBuf { - fn copy_to(&mut self, buf: &mut [u8], size: usize) { + fn drain_to(&mut self, buf: &mut [u8], size: usize) { match self { RecvBuf::Vec(ref mut b) => { buf[..size].copy_from_slice(b.drain(..size).as_slice()); @@ -142,7 +142,7 @@ where let n = ::std::cmp::min(buf.len(), self.recv_buf.len()); // Copy data to the output buffer - self.recv_buf.copy_to(buf, n); + self.recv_buf.drain_to(buf, n); n } diff --git a/secio/src/crypto/mod.rs b/secio/src/crypto/mod.rs index 660a0ed4..4959558a 100644 --- a/secio/src/crypto/mod.rs +++ b/secio/src/crypto/mod.rs @@ -27,7 +27,7 @@ pub trait StreamCipher { false } /// Feeds data from input through the cipher, in place decrypted. - fn decrypt_in_place(&mut self, _input: &mut bytes::BytesMut) -> Result<(), SecioError> { + fn decrypt_in_place(&mut self, _input: &mut [u8]) -> Result<(), SecioError> { Err(SecioError::InvalidProposition( "don't support in place decrypted", )) diff --git a/secio/src/crypto/ring_impl.rs b/secio/src/crypto/ring_impl.rs index 4e28c876..1ed48f7a 100644 --- a/secio/src/crypto/ring_impl.rs +++ b/secio/src/crypto/ring_impl.rs @@ -104,10 +104,7 @@ impl RingAeadCipher { buf.copy_from_slice(input); if let RingAeadCryptoVariant::Open(ref mut key) = self.cipher { - match key.open_in_place(Aad::empty(), &mut buf) { - Ok(_) => (), - Err(e) => return Err(e.into()), - } + key.open_in_place(Aad::empty(), &mut buf)?; } else { unreachable!("encrypt is called on a non-open cipher") } @@ -115,17 +112,14 @@ impl RingAeadCipher { Ok(buf) } - pub fn decrypt_in_place(&mut self, input: &mut bytes::BytesMut) -> Result<(), SecioError> { + pub fn decrypt_in_place(&mut self, input: &mut [u8]) -> Result<(), SecioError> { let output_len = input .len() .checked_sub(self.cipher_type.tag_size()) .ok_or(SecioError::FrameTooShort)?; if let RingAeadCryptoVariant::Open(ref mut key) = self.cipher { - match key.open_in_place(Aad::empty(), input) { - Ok(_) => (), - Err(e) => return Err(e.into()), - } + key.open_in_place(Aad::empty(), input)?; } else { unreachable!("encrypt is called on a non-open cipher") } @@ -148,7 +142,7 @@ impl StreamCipher for RingAeadCipher { true } - fn decrypt_in_place(&mut self, input: &mut bytes::BytesMut) -> Result<(), SecioError> { + fn decrypt_in_place(&mut self, input: &mut [u8]) -> Result<(), SecioError> { self.decrypt_in_place(input) } }