1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
#![forbid(unsafe_code)]
#![deny(missing_docs)]
//! This crate provides the reference implementation of the forensic file format ZFF.\
//! ZFF is a new file format for forensic images, as an alternative to EWF and AFF.\
//! ZFF is focused on speed and security.
//! If you want to learn more about ZFF, visit <https://github.com/ph0llux/zff>.
//! # Create a zff file
//! To create a zff file, you can easily use the [ZffWriter](crate::ZffWriter)-struct.
//! To create a [ZffWriter](crate::ZffWriter), you also need a [MainHeader](crate::header::MainHeader),
//! to create a [MainHeader](crate::header::MainHeader), you need a lot of other header and so on.
//! This documentation will show you a very little minimal example to create all the needed stuff.
//!
//! ##### building a CompressionHeader
//! We will start to set the compression abilities by building a [CompressionHeader](crate::header::CompressionHeader):
//! ```
//! use zff::header::*;
//! use zff::{
//! CompressionAlgorithm,
//! DEFAULT_HEADER_VERSION_COMPRESSION_HEADER,
//! };
//!
//! fn build_compression_header() -> CompressionHeader {
//! let algorithm = CompressionAlgorithm::Zstd;
//! let compression_level = 3;
//! let compression_threshold = 1.05;
//! let compression_header = CompressionHeader::new(DEFAULT_HEADER_VERSION_COMPRESSION_HEADER, algorithm, compression_level, compression_threshold);
//! compression_header
//! }
//! ```
//! ##### building a DescriptionHeader
//! Next, we will set all the describing information about our image file(s) by building a [DescriptionHeader](crate::header::DescriptionHeader):
//! ```
//! use std::time::{SystemTime, UNIX_EPOCH};
//! use zff::header::*;
//! use zff::{
//! DEFAULT_HEADER_VERSION_DESCRIPTION_HEADER
//! };
//!
//! fn build_description_header() -> DescriptionHeader {
//! let examiner = "ph0llux";
//! let start_date = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs();
//!
//! let mut description_header = DescriptionHeader::new_empty(DEFAULT_HEADER_VERSION_DESCRIPTION_HEADER);
//! description_header.set_examiner_name(examiner);
//! description_header.set_acquisition_start(start_date);
//! description_header
//! }
//! ```
//! ##### building a HashHeader
//! The last "subheader" of the MainHeader, we will build in this little guide is the [HashHeader](crate::header::HashHeader),
//! which contains several information about the used hash algorithms in this image.
//! ```
//! use zff::header::*;
//! use zff::{
//! HashType,
//! DEFAULT_HEADER_VERSION_HASH_VALUE_HEADER,
//! DEFAULT_HEADER_VERSION_HASH_HEADER
//! };
//!
//! fn build_hash_header() -> HashHeader {
//! let mut hash_values = Vec::new();
//! hash_values.push(HashValue::new_empty(DEFAULT_HEADER_VERSION_HASH_VALUE_HEADER, HashType::Blake2b512));
//! hash_values.push(HashValue::new_empty(DEFAULT_HEADER_VERSION_HASH_VALUE_HEADER, HashType::SHA256));
//!
//! let hash_header = HashHeader::new(DEFAULT_HEADER_VERSION_HASH_HEADER, hash_values);
//! hash_header
//! }
//! ```
//! ##### building the MainHeader
//! With the previous built [CompressionHeader](crate::header::CompressionHeader),
//! [DescriptionHeader](crate::header::DescriptionHeader) and [HashHeader](crate::header::HashHeader), and some
//! additional information we will now generate a [MainHeader](crate::header::MainHeader).
//! ```compile_fail
//! use zff::header::*;
//! use zff::{
//! DEFAULT_HEADER_VERSION_MAIN_HEADER,
//! DEFAULT_CHUNK_SIZE,
//! };
//!
//! fn build_main_header() -> MainHeader {
//! let version = DEFAULT_HEADER_VERSION_MAIN_HEADER;
//! let ch = build_compression_header();
//! let dh = build_description_header();
//! let hh = build_hash_header();
//! let chunk_size = DEFAULT_CHUNK_SIZE;
//! let sig_flag = 0; // we trust everything in this world and won't sign the image file. ;)
//! let seg_size = u64::MAX; // we won't split the image into segments.
//! let no_of_segments = 0;
//! let unique_identifier = 1;
//! let len_of_data = 0; //initial value, will be overwritten automatically by ZffWriter
//!
//! let main_header = MainHeader::new(
//! version,
//! None, //we won't set an encryption header yet.
//! ch,
//! dh,
//! hh,
//! chunk_size,
//! sig_flag,
//! seg_size,
//! no_of_segments,
//! unique_identifier,
//! len_of_data);
//! main_header
//! }
//! ```
//! ##### building the ZffWriter and write data to files
//! In the last step, we will create a [ZffWriter](crate::ZffWriter) and dump the input data to the output file(s):
//! ```compile_fail
//! use std::fs::File;
//! use zff::{Result, ZffWriter};
//!
//! fn main() -> Result<()> {
//! let main_header = build_main_header();
//! let input_file = File::open("/tmp/myTestfile.dd")?; //could also be e.g. '/dev/sda'.
//!
//! //this is some special: you will only give the name-scheme of the output file(s). In this example, the name-scheme is
//! // '/tmp/zff_output_file', so the segments of the image will be generated and the appropriate
//! // file extension will be added automatically; in this example to '/tmp/zff_output_file.z01'.
//! let output_filename_scheme = "/tmp/zff_output_file";
//!
//! // We pass the following information to the ZffWriter: The MainHeader, the input file, the output filename scheme,
//! // None for "No signature key", None for "No encryption key" and false for "No, we won't want to encrypt the header".
//! let zff_writer = ZffWriter::new(main_header, input_file, output_filename_scheme, None, None, false);
//!
//! //create/write the image file(s)
//! zff_writer.generate_files()
//! }
//! ```
// - modules
mod error;
mod constants;
mod traits;
mod compression;
mod encryption;
mod file_extension;
mod io;
mod hashing;
mod signatures;
mod segment;
pub mod header;
pub mod footer;
// - re-exports
pub use error::*;
pub use constants::*;
pub use traits::*;
pub use compression::*;
pub use encryption::*;
pub use file_extension::*;
pub use io::*;
pub use hashing::*;
pub use signatures::*;
pub use segment::*;
// - types
/// Result for std::result::Result<T, ZffError>.
pub type Result<T> = std::result::Result<T, ZffError>;