feat: update version

This commit is contained in:
2023-10-19 23:24:03 +08:00
parent 94a6cf18b3
commit a66babb828
5 changed files with 63 additions and 32 deletions

View File

@@ -7,7 +7,7 @@ use crate::compress;
use crate::consts::{TINY_ENC_COMPRESSED_MAGIC_TAG, TINY_ENC_MAGIC_TAG};
use crate::spec::TinyEncryptMeta;
pub fn write_tiny_encrypt_meta<W: Write>(w: &mut W, meta: &TinyEncryptMeta, compress_meta: bool) -> XResult<usize> {
pub fn write_tiny_encrypt_meta(w: &mut impl Write, meta: &TinyEncryptMeta, compress_meta: bool) -> XResult<usize> {
let tag = iff!(compress_meta, TINY_ENC_COMPRESSED_MAGIC_TAG, TINY_ENC_MAGIC_TAG);
opt_result!(w.write_all(&tag.to_be_bytes()), "Write tag failed: {}");
let mut encrypted_meta_bytes = opt_result!(serde_json::to_vec(&meta), "Generate meta json bytes failed: {}");
@@ -23,13 +23,13 @@ pub fn write_tiny_encrypt_meta<W: Write>(w: &mut W, meta: &TinyEncryptMeta, comp
Ok(encrypted_meta_bytes.len() + 2 + 4)
}
pub fn read_tiny_encrypt_meta_and_normalize<R: Read>(r: &mut R) -> XResult<TinyEncryptMeta> {
pub fn read_tiny_encrypt_meta_and_normalize(r: &mut impl Read) -> XResult<TinyEncryptMeta> {
let mut meta = read_tiny_encrypt_meta(r);
let _ = meta.as_mut().map(|meta| meta.normalize());
meta
}
pub fn read_tiny_encrypt_meta<R: Read>(r: &mut R) -> XResult<TinyEncryptMeta> {
pub fn read_tiny_encrypt_meta(r: &mut impl Read) -> XResult<TinyEncryptMeta> {
let mut tag_buff = [0_u8; 2];
opt_result!(r.read_exact(&mut tag_buff), "Read tag failed: {}");
let tag = u16::from_be_bytes(tag_buff);
@@ -42,7 +42,7 @@ pub fn read_tiny_encrypt_meta<R: Read>(r: &mut R) -> XResult<TinyEncryptMeta> {
let mut length_buff = [0_u8; 4];
opt_result!(r.read_exact(&mut length_buff), "Read length failed: {}");
let length = u32::from_be_bytes(length_buff);
if length > 1024 * 1024 {
if length > 100 * 1024 * 1024 {
return simple_error!("Meta too large: {}", length);
}
@@ -53,6 +53,7 @@ pub fn read_tiny_encrypt_meta<R: Read>(r: &mut R) -> XResult<TinyEncryptMeta> {
debugging!("Tiny enc meta compressed: {}", is_compressed_tiny_enc);
if is_compressed_tiny_enc {
meta_buff = opt_result!(compress::decompress(&meta_buff), "Decompress meta failed: {}");
debugging!("Encrypted meta decompressed: {} byte(s) -> {} byte(s)", length, meta_buff.len());
}
debugging!("Encrypted meta: {}", String::from_utf8_lossy(&meta_buff));