(&mut self, bytes: &mut BytesMut)
| 296 | } |
| 297 | |
| 298 | pub fn dec(&mut self, bytes: &mut BytesMut) -> Result<(), Error> { |
| 299 | if bytes.len() <= 1 { |
| 300 | return Ok(()); |
| 301 | } |
| 302 | self.2 += 1; |
| 303 | let nonce = FramedStream::get_nonce(self.2); |
| 304 | match secretbox::open(bytes, &nonce, &self.0) { |
| 305 | Ok(res) => { |
| 306 | bytes.clear(); |
| 307 | bytes.put_slice(&res); |
| 308 | Ok(()) |
| 309 | } |
| 310 | Err(()) => Err(Error::new(ErrorKind::Other, "decryption error")), |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | pub fn enc(&mut self, data: &[u8]) -> Vec<u8> { |
| 315 | self.1 += 1; |