#![allow(missing_docs)]
pub use crate::archive::format::{parse_fca_header, parse_manifest_bytes};
pub use crate::archive::model::{ArchiveEntry, ArchiveEntryKind, FcaHeader, Manifest};
pub use crate::archive::path::{ascii_case_collision_key, validate_fca_path};
pub use crate::crypto::kdf::{KDF_PARAMS_SIZE, KdfParams};
pub use crate::crypto::tlv::validate_tlv;
pub use crate::key::private::PrivateKeyHeader;
pub use crate::key::public::RECIPIENT_STRING_LEN_LOCAL_CAP_DEFAULT;
pub use crate::recipient::native::x25519::validate_private_key_shape;
pub use crate::HeaderReadLimits;
pub fn read_encrypted_header<R: std::io::Read>(
reader: &mut R,
limits: HeaderReadLimits,
) -> Result<(), crate::CryptoError> {
crate::container::read_encrypted_header(reader, limits).map(|_| ())
}
pub fn validate_no_known_critical(
bytes: &[u8],
max_region_len: u32,
max_value_len: u32,
) -> Result<(), crate::CryptoError> {
crate::crypto::tlv::validate_no_known_critical(bytes, max_region_len, max_value_len)
}
pub fn decode_recipient_string(s: &str, local_max_chars: usize) -> Result<(), crate::CryptoError> {
crate::key::public::decode_recipient_string(s, local_max_chars).map(|_| ())
}
pub fn serialize_manifest(
manifest: &Manifest,
limits: crate::ArchiveLimits,
) -> Result<Vec<u8>, crate::CryptoError> {
crate::archive::format::serialize_manifest(manifest, limits)
}
pub fn archive_for_fuzz(input_path: &std::path::Path) -> Result<Vec<u8>, crate::CryptoError> {
crate::archive::archive(input_path, Vec::new(), crate::ArchiveLimits::default())
.map(|(_root_name, bytes)| bytes)
}
fn fuzz_payload_key() -> crate::crypto::keys::PayloadKey {
crate::crypto::keys::PayloadKey::from_bytes_for_tests(
[0x42; crate::crypto::keys::ENCRYPTION_KEY_SIZE],
)
}
const FUZZ_STREAM_NONCE: [u8; crate::crypto::stream::STREAM_NONCE_SIZE] =
[0x24; crate::crypto::stream::STREAM_NONCE_SIZE];
pub fn decrypt_stream_for_fuzz(ciphertext: &[u8]) -> Result<Vec<u8>, crate::CryptoError> {
use std::io::Read as _;
let mut reader = crate::crypto::stream::payload_decryptor(
&fuzz_payload_key(),
&FUZZ_STREAM_NONCE,
ciphertext,
);
let mut plaintext = Vec::new();
reader.read_to_end(&mut plaintext)?;
Ok(plaintext)
}
pub fn encrypt_stream_for_fuzz(plaintext: &[u8]) -> Result<Vec<u8>, crate::CryptoError> {
use std::io::Write as _;
let mut writer = crate::crypto::stream::payload_encryptor(
&fuzz_payload_key(),
&FUZZ_STREAM_NONCE,
Vec::new(),
);
writer.write_all(plaintext)?;
writer.finish()
}
pub use crate::archive::IncompleteOutputPolicy;
pub fn unarchive_for_fuzz(
bytes: &[u8],
output_dir: &std::path::Path,
limits: crate::ArchiveLimits,
) -> Result<std::path::PathBuf, crate::CryptoError> {
use std::io::Cursor;
crate::archive::unarchive(
Cursor::new(bytes),
output_dir,
limits,
IncompleteOutputPolicy::DeleteOnError,
)
}