Skip to main content

ostrya_core/
lib.rs

1#![forbid(unsafe_code)]
2
3//! ostree object model, checksums, and on-disk format primitives.
4//!
5//! Builds on the ostrya-gvariant codec to serialize and parse commits,
6//! dirtrees, dirmeta, and file headers, and provides the checksum type, LEB128
7//! varint, loose-path derivation, `ostree.sizes` packing, and xattr
8//! canonicalization.
9//!
10//! This crate covers phases 2 and 3 of the port plan (see
11//! `docs/port-plan.md`): the format primitives (checksum, varint, loose
12//! paths, sizes, xattrs, keyfile) and the typed object structs (commit,
13//! dirtree, dirmeta, file headers) with their borrowed read-path views.
14
15pub mod base64;
16mod be;
17mod checksum;
18mod commit;
19mod dirmeta;
20mod dirtree;
21mod error;
22pub mod filehdr;
23mod keyfile;
24mod loosepath;
25mod mode;
26mod objname;
27mod objtype;
28pub mod sizes;
29mod valiter;
30pub mod varint;
31mod xattr;
32
33pub use checksum::Checksum;
34pub use commit::Commit;
35pub use dirmeta::{DirMeta, DirMetaRef};
36pub use dirtree::{DirTree, DirTreeRef};
37pub use error::{Error, Result};
38pub use filehdr::{ContentHasher, FileHeader};
39pub use keyfile::KeyFile;
40pub use loosepath::loose_path;
41pub use mode::RepoMode;
42pub use objname::ObjectName;
43pub use objtype::ObjectType;
44pub use xattr::{Xattrs, XattrsRef};
45
46// The dynamic GVariant value tree and its codec entry points. `Commit::metadata`
47// is a `Value`, so consuming crates need these to inspect, load, and serialize
48// arbitrary metadata dicts without depending on `ostrya-gvariant` directly.
49pub use ostrya_gvariant::{
50    ArrayIter, DictBuilder, GvDecode, GvType, Span, TextError, Type, Value, choose_offset_size,
51    from_bytes, from_text, to_bytes, to_text, to_text_unannotated, write_offset,
52};
53
54#[cfg(test)]
55mod tests {
56    use ostrya_gvariant::{GvType, Type};
57
58    use crate::{Checksum, Commit, DirMeta, DirTree, FileHeader};
59
60    /// The hand-stated `ALIGNMENT`/`FIXED_SIZE` of an object type must equal
61    /// what its signature implies, so the two cannot silently drift.
62    fn assert_pinned<T: GvType>() {
63        let ty = Type::parse(T::SIGNATURE).unwrap();
64        assert_eq!(
65            T::ALIGNMENT,
66            ty.alignment(),
67            "alignment for {}",
68            T::SIGNATURE
69        );
70        assert_eq!(
71            T::FIXED_SIZE,
72            ty.fixed_size(),
73            "fixed size for {}",
74            T::SIGNATURE
75        );
76    }
77
78    #[test]
79    fn object_constants_match_their_signatures() {
80        assert_pinned::<Checksum>();
81        assert_pinned::<FileHeader>();
82        assert_pinned::<DirMeta>();
83        assert_pinned::<DirTree>();
84        assert_pinned::<Commit>();
85    }
86}