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
//! A byte-exact writer of composefs EROFS images, with an fs-verity hasher.
//!
//! A caller builds a tree of directories, symlinks, and regular files. The
//! crate writes the EROFS image of the tree and returns the fs-verity digest of
//! the image. The image is byte-identical to the composefs image of the
//! `ostree` command, format version 0. The crate is synchronous and does not
//! read a repository.
//!
//! # Entry points
//!
//! - [`Directory`] is the root of a tree, and [`Node`] is one entry of it.
//! - [`Metadata`] holds the mode, the owner, the mtime, and the xattrs of a node.
//! - [`Content`] is the content of a [`Regular`] file: empty or a loose object.
//! - [`build_image`] writes the image into an [`Image`] in memory.
//! - [`write_image_to`] writes the image through a sink and does not keep it.
//! - [`FsVerityHasher`] calculates an fs-verity digest of a byte stream.
//! - [`Error`] is the error of the two image writers.
//!
//! # Examples
//!
//! ```
//! use ostrya_composefs::{Content, Directory, FsVerityHasher, Metadata, Node, Regular};
//!
//! let mut root = Directory::new(Metadata { mode: 0o755, ..Metadata::default() });
//! let meta = Metadata { mode: 0o644, ..Metadata::default() };
//! root.insert("empty", Node::Regular(Regular { meta, content: Content::Empty }));
//!
//! let image = ostrya_composefs::build_image(&root)?;
//! assert_eq!(FsVerityHasher::hash(&image.bytes), image.fs_verity);
//!
//! // The streaming writer writes the same bytes and returns the same digest.
//! let mut sink = Vec::new();
//! assert_eq!(ostrya_composefs::write_image_to(&root, &mut sink)?, image.fs_verity);
//! assert_eq!(sink, image.bytes);
//! # Ok::<(), ostrya_composefs::Error>(())
//! ```
// tests/golden.rs compares the output byte for byte with images that the
// `ostree` command wrote.
use fmt;
pub use FsVerityHasher;
pub use ;
pub use write_image_to;
pub use ;
/// The error of [`build_image`] and [`write_image_to`].
/// A composefs EROFS image in memory, with its fs-verity digest.
/// Writes the composefs EROFS image of the tree at `root` into memory.
///
/// The bytes and the digest are the same as the result of [`write_image_to`].
/// [Image format](write_image_to#image-format) gives the layout of the image.
///
/// # Errors
///
/// - [`Error::Unsupported`] if a child name is empty, is `.` or `..`, holds
/// `/`, or is longer than 255 bytes. [`Directory::children`] gives the
/// rules.
/// - [`Error::Unsupported`] if a symlink target is too long for its inode
/// block. [`Symlink::target`] gives the limit.
///
/// # Panics
///
/// Panics if an xattr name, an xattr value, or the xattr area of one node is
/// larger than the limits on [`Metadata::xattrs`].