Skip to content

Commit

Permalink
assert bytes written in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sokorototo committed Feb 10, 2025
1 parent 502bdc5 commit 1e759b2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion crates/c-bindings/src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub extern "C" fn dump_archive_to_buffer(

// write
match dump(target, leaves, config, wrapper) {
Ok(bytes_written) => bytes_written,
Ok(written) => written,
Err(e) => errors::v_error_to_id::<()>(error_p, e) as _,
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/vach/src/crypto_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub fn read_public_key<T: Read>(mut handle: T) -> InternalResult<crypto::Verifyi
handle.read_exact(&mut keypair_bytes)?;
crypto::VerifyingKey::from_bytes(&keypair_bytes).map_err(|err| InternalError::ParseError(err.to_string()))
}

/// Read and parse a secret key from a read stream
pub fn read_secret_key<T: Read>(mut handle: T) -> InternalResult<crypto::SigningKey> {
let mut secret_bytes = [0; crate::SECRET_KEY_LENGTH];
Expand Down
1 change: 0 additions & 1 deletion crates/vach/src/global/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ impl ArchiveConfig {
#[cfg_attr(docsrs, doc(cfg(feature = "crypto")))]
pub fn load_public_key<T: Read>(&mut self, handle: T) -> InternalResult {
use crate::crypto_utils::read_public_key;

self.public_key = Some(read_public_key(handle)?);
Ok(())
}
Expand Down
20 changes: 8 additions & 12 deletions crates/vach/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ fn flags_set_intersects() {
#[test]
#[cfg(all(feature = "compression", feature = "builder"))]
fn builder_no_signature() {
use std::fs::OpenOptions;

let build_config = BuilderConfig::default();

let mut poem_flags = Flags::default();
Expand All @@ -127,8 +125,10 @@ fn builder_no_signature() {
Leaf::new(b"Hello, Cassandra!" as &[u8], "greeting").compress(CompressMode::Never),
];

let mut target = OpenOptions::new().write(true).create(true).read(true).open(SIMPLE_TARGET).unwrap();
dump(&mut target, &mut leaves, &build_config, None).unwrap();
let mut target = File::open(SIMPLE_TARGET).unwrap();
let written = dump(&mut target, &mut leaves, &build_config, None).unwrap();

assert_eq!(target.metadata().unwrap().len(), written);
}

#[test]
Expand Down Expand Up @@ -161,11 +161,9 @@ fn builder_with_signature() -> InternalResult {
leaves.push(Leaf::new(b"Don't forget to recite your beatitudes!" as &[u8], "signed").sign(true));

let mut target = File::create(SIGNED_TARGET)?;
println!(
"Number of bytes written: {}, into signed archive.",
dump(&mut target, leaves.as_mut_slice(), &build_config, None)?
);
let written = dump(&mut target, leaves.as_mut_slice(), &build_config, None)?;

assert_eq!(target.metadata().unwrap().len(), written);
Ok(())
}

Expand Down Expand Up @@ -230,11 +228,9 @@ fn builder_with_encryption() -> InternalResult {
);

let mut target = File::create(ENCRYPTED_TARGET)?;
println!(
"Number of bytes written: {}, into encrypted and fully compressed archive.",
dump(&mut target, leaves.as_mut_slice(), &build_config, None)?
);
let written = dump(&mut target, leaves.as_mut_slice(), &build_config, None)?;

assert_eq!(target.metadata().unwrap().len(), written);
Ok(())
}

Expand Down

0 comments on commit 1e759b2

Please sign in to comment.