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, offset_size_for, to_bytes, to_text, to_text_unannotated,
52    tuple_field_from_bytes, write_offset,
53};
54
55#[cfg(test)]
56mod tests {
57    use ostrya_gvariant::{GvType, Type};
58
59    use crate::{Checksum, Commit, DirMeta, DirTree, FileHeader};
60
61    /// The hand-stated `ALIGNMENT`/`FIXED_SIZE` of an object type must equal
62    /// what its signature implies, so the two cannot silently drift.
63    fn assert_pinned<T: GvType>() {
64        let ty = Type::parse(T::SIGNATURE).unwrap();
65        assert_eq!(
66            T::ALIGNMENT,
67            ty.alignment(),
68            "alignment for {}",
69            T::SIGNATURE
70        );
71        assert_eq!(
72            T::FIXED_SIZE,
73            ty.fixed_size(),
74            "fixed size for {}",
75            T::SIGNATURE
76        );
77    }
78
79    #[test]
80    fn object_constants_match_their_signatures() {
81        assert_pinned::<Checksum>();
82        assert_pinned::<FileHeader>();
83        assert_pinned::<DirMeta>();
84        assert_pinned::<DirTree>();
85        assert_pinned::<Commit>();
86    }
87}