]> git.proxmox.com Git - proxmox-backup.git/blob - pbs-datastore/src/file_formats.rs
add pbs-datastore module
[proxmox-backup.git] / pbs-datastore / src / file_formats.rs
1 use endian_trait::Endian;
2
3 // WARNING: PLEASE DO NOT MODIFY THOSE MAGIC VALUES
4
5 // openssl::sha::sha256(b"Proxmox Backup Catalog file v1.0")[0..8]
6 pub const PROXMOX_CATALOG_FILE_MAGIC_1_0: [u8; 8] = [145, 253, 96, 249, 196, 103, 88, 213];
7
8 // openssl::sha::sha256(b"Proxmox Backup uncompressed blob v1.0")[0..8]
9 pub const UNCOMPRESSED_BLOB_MAGIC_1_0: [u8; 8] = [66, 171, 56, 7, 190, 131, 112, 161];
10
11 //openssl::sha::sha256(b"Proxmox Backup zstd compressed blob v1.0")[0..8]
12 pub const COMPRESSED_BLOB_MAGIC_1_0: [u8; 8] = [49, 185, 88, 66, 111, 182, 163, 127];
13
14 // openssl::sha::sha256(b"Proxmox Backup encrypted blob v1.0")[0..8]
15 pub const ENCRYPTED_BLOB_MAGIC_1_0: [u8; 8] = [123, 103, 133, 190, 34, 45, 76, 240];
16
17 // openssl::sha::sha256(b"Proxmox Backup zstd compressed encrypted blob v1.0")[0..8]
18 pub const ENCR_COMPR_BLOB_MAGIC_1_0: [u8; 8] = [230, 89, 27, 191, 11, 191, 216, 11];
19
20 // openssl::sha::sha256(b"Proxmox Backup fixed sized chunk index v1.0")[0..8]
21 pub const FIXED_SIZED_CHUNK_INDEX_1_0: [u8; 8] = [47, 127, 65, 237, 145, 253, 15, 205];
22
23 // openssl::sha::sha256(b"Proxmox Backup dynamic sized chunk index v1.0")[0..8]
24 pub const DYNAMIC_SIZED_CHUNK_INDEX_1_0: [u8; 8] = [28, 145, 78, 165, 25, 186, 179, 205];
25
26 /// Data blob binary storage format
27 ///
28 /// The format start with a 8 byte magic number to identify the type,
29 /// followed by a 4 byte CRC. This CRC is used on the server side to
30 /// detect file corruption (computed when upload data), so there is
31 /// usually no need to compute it on the client side.
32 ///
33 /// Unencrypted blobs simply contain the CRC, followed by the
34 /// (compressed) data.
35 ///
36 /// (MAGIC || CRC32 || Data)
37 ///
38 /// This is basically the same format we use for chunks, but
39 /// with other magic numbers so that we can distinguish them.
40 #[derive(Endian)]
41 #[repr(C,packed)]
42 pub struct DataBlobHeader {
43 pub magic: [u8; 8],
44 pub crc: [u8; 4],
45 }
46
47 /// Encrypted data blob binary storage format
48 ///
49 /// The ``DataBlobHeader`` for encrypted blobs additionally contains
50 /// a 16 byte IV, followed by a 16 byte Authenticated Encyrypten (AE)
51 /// tag, followed by the encrypted data:
52 ///
53 /// (MAGIC || CRC32 || IV || TAG || EncryptedData).
54 #[derive(Endian)]
55 #[repr(C,packed)]
56 pub struct EncryptedDataBlobHeader {
57 pub head: DataBlobHeader,
58 pub iv: [u8; 16],
59 pub tag: [u8; 16],
60 }
61
62 /// Header size for different file types
63 ///
64 /// Panics on unknown magic numbers.
65 pub fn header_size(magic: &[u8; 8]) -> usize {
66 match *magic {
67 UNCOMPRESSED_BLOB_MAGIC_1_0 => std::mem::size_of::<DataBlobHeader>(),
68 COMPRESSED_BLOB_MAGIC_1_0 => std::mem::size_of::<DataBlobHeader>(),
69 ENCRYPTED_BLOB_MAGIC_1_0 => std::mem::size_of::<EncryptedDataBlobHeader>(),
70 ENCR_COMPR_BLOB_MAGIC_1_0 => std::mem::size_of::<EncryptedDataBlobHeader>(),
71 _ => panic!("unknown blob magic"),
72 }
73 }