MCPcopy Create free account
hub / github.com/Recordscript/recordscript / dec

Method dec

libs/hbb_common/src/tcp.rs:298–312  ·  view source on GitHub ↗
(&mut self, bytes: &mut BytesMut)

Source from the content-addressed store, hash-verified

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;

Callers 1

nextMethod · 0.80

Calls 1

clearMethod · 0.80

Tested by

no test coverage detected