pub struct VsfBuilder { /* private fields */ }Expand description
Builder for complete VSF files with headers and sections
All VSF files automatically include a BLAKE3 hash for integrity verification.
Implementations§
Source§impl VsfBuilder
impl VsfBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new VSF file builder
Note: Every VSF file automatically includes:
- Creation timestamp (current time as ef5, ~2min precision)
- BLAKE3 hash for integrity verification (computed during
build())
Examples found in repository?
3fn main() {
4 println!("=== VSF Creation Timestamp Demo ===\n");
5
6 // Build a simple VSF file
7 let result = VsfBuilder::new()
8 .add_section(
9 "metadata",
10 vec![
11 ("width".to_string(), VsfType::u(1920, false)),
12 ("height".to_string(), VsfType::u(1080, false)),
13 ("format".to_string(), VsfType::x("RAW".to_string())),
14 ],
15 )
16 .build();
17
18 match result {
19 Ok(bytes) => {
20 println!("✓ Successfully built VSF file: {} bytes\n", bytes.len());
21
22 // Write to file
23 std::fs::write("/tmp/demo.vsf", &bytes).expect("Failed to write file");
24 println!("✓ Written to /tmp/demo.vsf");
25 println!("\nRun: cargo run --bin vsfinfo /tmp/demo.vsf");
26 println!("\nYou should see the creation timestamp in the header!");
27 }
28 Err(e) => {
29 eprintln!("✗ Build error: {}", e);
30 std::process::exit(1);
31 }
32 }
33}Sourcepub fn creation_time_nanos(self, eagle_time: f64) -> Self
pub fn creation_time_nanos(self, eagle_time: f64) -> Self
Set creation time with nanosecond precision (ef6) Use this for protocols that need unique timestamps for replay protection
Sourcepub fn provenance_hash(self, hash: [u8; 32]) -> Self
pub fn provenance_hash(self, hash: [u8; 32]) -> Self
Set a custom provenance hash (immutable content identity)
Use this when the provenance hash has specific meaning in your protocol, such as linking a response to a challenge. The provenance hash will NOT be recomputed during build() - it stays exactly as you set it.
Sourcepub fn signature_ed25519(self, pubkey: [u8; 32], signature: [u8; 64]) -> Self
pub fn signature_ed25519(self, pubkey: [u8; 32], signature: [u8; 64]) -> Self
Add an Ed25519 signature to the header (replaces rolling hash)
The signature should sign the provenance hash. When a signature is present, no rolling hash (hb) is included - the signature provides integrity verification.
Both pubkey (ke) and signature (ge) are included in the header for verification.
Sourcepub fn avatar_hash(self, hash: [u8; 32]) -> Self
pub fn avatar_hash(self, hash: [u8; 32]) -> Self
Add an avatar provenance hash as a header field (davatar_id:hp[hash])
This is the BLAKE3 provenance hash of the sender’s avatar VSF file. Used in ping/pong messages to sync avatar state between peers. Stored as a metadata-only header field with name “avatar_id”.
Sourcepub fn provenance_only(self) -> Self
pub fn provenance_only(self) -> Self
Disable rolling hash - use provenance hash only
Use this for files that don’t need mutable state tracking or signatures. The provenance hash (hp) will still be computed for content identity.
Sourcepub fn add_inline_field(
self,
name: impl Into<String>,
values: Vec<VsfType>,
) -> Self
pub fn add_inline_field( self, name: impl Into<String>, values: Vec<VsfType>, ) -> Self
Add an inline metadata field (header-only, no section body)
Creates a field like (d#{name}:value1,value2,...) in the header.
Unlike sections, inline fields have no offset/size/count - just name + values.
Use for lightweight control packets (e.g., PT acks) where provenance hash provides integrity and inline values carry the metadata.
§Example
VsfBuilder::new()
.provenance_hash(chunk_hash)
.provenance_only()
.add_inline_field("pt_ack", vec![VsfType::u3(seq), VsfType::u3(buf)])
.build()Sourcepub fn add_section(
self,
name: impl Into<String>,
fields: Vec<(String, VsfType)>,
) -> Self
pub fn add_section( self, name: impl Into<String>, fields: Vec<(String, VsfType)>, ) -> Self
Add a structured section with name and items
Examples found in repository?
3fn main() {
4 println!("=== VSF Creation Timestamp Demo ===\n");
5
6 // Build a simple VSF file
7 let result = VsfBuilder::new()
8 .add_section(
9 "metadata",
10 vec![
11 ("width".to_string(), VsfType::u(1920, false)),
12 ("height".to_string(), VsfType::u(1080, false)),
13 ("format".to_string(), VsfType::x("RAW".to_string())),
14 ],
15 )
16 .build();
17
18 match result {
19 Ok(bytes) => {
20 println!("✓ Successfully built VSF file: {} bytes\n", bytes.len());
21
22 // Write to file
23 std::fs::write("/tmp/demo.vsf", &bytes).expect("Failed to write file");
24 println!("✓ Written to /tmp/demo.vsf");
25 println!("\nRun: cargo run --bin vsfinfo /tmp/demo.vsf");
26 println!("\nYou should see the creation timestamp in the header!");
27 }
28 Err(e) => {
29 eprintln!("✗ Build error: {}", e);
30 std::process::exit(1);
31 }
32 }
33}Sourcepub fn add_section_with_meta(
self,
name: impl Into<String>,
fields: Vec<(String, VsfType)>,
meta: SectionMeta,
) -> Self
pub fn add_section_with_meta( self, name: impl Into<String>, fields: Vec<(String, VsfType)>, meta: SectionMeta, ) -> Self
Add a structured section with cryptographic metadata (key)
Use this for sections where the header field needs to indicate:
key: The cryptographic key (ke for Ed25519, kx for X25519)
§Example
let builder = VsfBuilder::new()
.add_section_with_meta(
"encrypted_data",
vec![("payload".to_string(), VsfType::v(b'e', encrypted_bytes))],
SectionMeta::new(VsfType::ke(pubkey.to_vec())),
);Sourcepub fn add_section_direct(self, section: VsfSection) -> Self
pub fn add_section_direct(self, section: VsfSection) -> Self
Add a pre-built VsfSection directly
Use this when you need fields with multiple values (Vec
Sourcepub fn add_section_direct_with_meta(
self,
section: VsfSection,
meta: SectionMeta,
) -> Self
pub fn add_section_direct_with_meta( self, section: VsfSection, meta: SectionMeta, ) -> Self
Add a pre-built VsfSection with cryptographic metadata
Sourcepub fn add_unboxed(self, name: impl Into<String>, data: Vec<u8>) -> Self
pub fn add_unboxed(self, name: impl Into<String>, data: Vec<u8>) -> Self
Add an unboxed data blob (zero-copy section)
Sourcepub fn add_unboxed_with_meta(
self,
name: impl Into<String>,
data: Vec<u8>,
meta: SectionMeta,
) -> Self
pub fn add_unboxed_with_meta( self, name: impl Into<String>, data: Vec<u8>, meta: SectionMeta, ) -> Self
Add an unboxed data blob with cryptographic metadata
Use this for encrypted sections where the header field needs to indicate the encryption key and wrapper type, but the section body is raw bytes.
Sourcepub fn build(self) -> Result<Vec<u8>, String>
pub fn build(self) -> Result<Vec<u8>, String>
Build complete VSF file using Vec<Vec
Examples found in repository?
3fn main() {
4 println!("=== VSF Creation Timestamp Demo ===\n");
5
6 // Build a simple VSF file
7 let result = VsfBuilder::new()
8 .add_section(
9 "metadata",
10 vec![
11 ("width".to_string(), VsfType::u(1920, false)),
12 ("height".to_string(), VsfType::u(1080, false)),
13 ("format".to_string(), VsfType::x("RAW".to_string())),
14 ],
15 )
16 .build();
17
18 match result {
19 Ok(bytes) => {
20 println!("✓ Successfully built VSF file: {} bytes\n", bytes.len());
21
22 // Write to file
23 std::fs::write("/tmp/demo.vsf", &bytes).expect("Failed to write file");
24 println!("✓ Written to /tmp/demo.vsf");
25 println!("\nRun: cargo run --bin vsfinfo /tmp/demo.vsf");
26 println!("\nYou should see the creation timestamp in the header!");
27 }
28 Err(e) => {
29 eprintln!("✗ Build error: {}", e);
30 std::process::exit(1);
31 }
32 }
33}