1 //! *catar* binary format definition
3 //! Please note the all values are stored in little endian ordering.
5 //! The Archive contains a list of items. Each item starts with a
6 //! `CaFormatHeader`, followed by the item data.
10 use siphasher
::sip
::SipHasher24
;
12 pub const CA_FORMAT_ENTRY
: u64 = 0x1396fabcea5bbb51;
13 pub const CA_FORMAT_FILENAME
: u64 = 0x6dbb6ebcb3161f0b;
14 pub const CA_FORMAT_SYMLINK
: u64 = 0x664a6fb6830e0d6c;
15 pub const CA_FORMAT_PAYLOAD
: u64 = 0x8b9e1d93d6dcffc9;
17 pub const CA_FORMAT_GOODBYE
: u64 = 0xdfd35c5e8327c403;
18 /* The end marker used in the GOODBYE object */
19 pub const CA_FORMAT_GOODBYE_TAIL_MARKER
: u64 = 0x57446fa533702943;
21 pub const CA_FORMAT_FEATURE_FLAGS_MAX
: u64 = 0xb000_0001_ffef_fe26; // fixme: ?
24 pub struct CaFormatHeader
{
25 /// The size of the item, including the size of `CaFormatHeader`.
27 /// The item type (see `CA_FORMAT_` constants).
32 pub struct CaFormatEntry
{
33 pub feature_flags
: u64,
42 pub struct CaFormatGoodbyeItem
{
43 /// The offset from the start of the GOODBYE object to the start
44 /// of the matching directory item (point to a FILENAME). The last
45 /// GOODBYE item points to the start of the matching ENTRY
46 /// object. repeats the `size`
48 /// The overall size of the directory item. The last GOODBYE item
49 /// repeats the size of the GOODBYE item.
51 /// SipHash24 of the directory item name. The last GOODBYE item
52 /// uses the special hash value `CA_FORMAT_GOODBYE_TAIL_MARKER`.
57 /// Helper function to extract file names from binary archive.
58 pub fn read_os_string(buffer
: &[u8]) -> std
::ffi
::OsString
{
59 let len
= buffer
.len();
61 use std
::os
::unix
::ffi
::OsStrExt
;
63 let name
= if len
> 0 && buffer
[len
-1] == 0 {
64 std
::ffi
::OsStr
::from_bytes(&buffer
[0..len
-1])
66 std
::ffi
::OsStr
::from_bytes(&buffer
)
72 /// Create SipHash values for goodby tables.
73 //pub fn compute_goodbye_hash(name: &std::ffi::CStr) -> u64 {
74 pub fn compute_goodbye_hash(name
: &[u8]) -> u64 {
76 use std
::hash
::Hasher
;
77 let mut hasher
= SipHasher24
::new_with_keys(0x8574442b0f1d84b3, 0x2736ed30d1c22ec1);