whatever
This commit is contained in:
+9
-9
@@ -1,10 +1,10 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use chacha20poly1305::{aead::stream, KeyInit, XChaCha20Poly1305};
|
||||
use rand::{rngs::OsRng, RngCore};
|
||||
use chacha20poly1305::{KeyInit, XChaCha20Poly1305, aead::stream};
|
||||
use rand::{RngCore, rngs::OsRng};
|
||||
|
||||
use crate::error::*;
|
||||
use crate::reader::ReadInfo;
|
||||
use crate::reader::ReadInfoChunk;
|
||||
use crate::utils::BUFSIZE;
|
||||
use crate::utils::*;
|
||||
|
||||
@@ -32,7 +32,7 @@ pub fn encrypt<S: AsRef<str>>(
|
||||
let read_result = f_plain.read_ahead(&mut buf)?;
|
||||
|
||||
match read_result {
|
||||
ReadInfo::NormalChunk(n) => {
|
||||
ReadInfoChunk::Normal(n) => {
|
||||
assert_eq!(n, BUFSIZE);
|
||||
assert_eq!(buf.len(), BUFSIZE);
|
||||
eprintln!("[encrypt]: read normal chunk");
|
||||
@@ -42,14 +42,14 @@ pub fn encrypt<S: AsRef<str>>(
|
||||
// we shrink it to the BUFSIZE in order to read the correct size
|
||||
buf.truncate(BUFSIZE);
|
||||
}
|
||||
ReadInfo::LastChunk(n) => {
|
||||
ReadInfoChunk::Last(n) => {
|
||||
eprintln!("[encrypt]: read last chunk");
|
||||
buf.truncate(n);
|
||||
stream_encryptor.encrypt_last_in_place(&[], &mut buf)?;
|
||||
f_encrypted.write_all(&buf)?;
|
||||
break;
|
||||
}
|
||||
ReadInfo::EmptyChunk => {
|
||||
ReadInfoChunk::Empty => {
|
||||
eprintln!("[encrypt]: read empty chunk");
|
||||
panic!("[ERROR] Empty Chunk while reading");
|
||||
}
|
||||
@@ -79,21 +79,21 @@ pub fn decrypt<S: AsRef<str>>(
|
||||
let read_result = f_encrypted.read_ahead(&mut buf)?;
|
||||
|
||||
match read_result {
|
||||
ReadInfo::NormalChunk(n) => {
|
||||
ReadInfoChunk::Normal(n) => {
|
||||
assert_eq!(n, BUFSIZE + 16);
|
||||
eprintln!("[decrypt]: read normal chunk");
|
||||
stream_decryptor.decrypt_next_in_place(&[], &mut buf)?;
|
||||
f_plain.write_all(&buf)?;
|
||||
buf.resize(BUFSIZE + 16, 0);
|
||||
}
|
||||
ReadInfo::LastChunk(n) => {
|
||||
ReadInfoChunk::Last(n) => {
|
||||
eprintln!("[decrypt]: read last chunk");
|
||||
buf.truncate(n);
|
||||
stream_decryptor.decrypt_last_in_place(&[], &mut buf)?;
|
||||
f_plain.write_all(&buf)?;
|
||||
break;
|
||||
}
|
||||
ReadInfo::EmptyChunk => {
|
||||
ReadInfoChunk::Empty => {
|
||||
eprintln!("[decrypt]: read empty chunk");
|
||||
panic!("Empty Chunk while reading");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user