crev_data/
lib.rs

1//! This crate contains only code handling data types
2//! used by `crev`, without getting into details
3//! how actually `crev` works (where and how it manages data).
4#![allow(clippy::default_trait_access)]
5#![allow(clippy::items_after_statements)]
6#![allow(clippy::missing_errors_doc)]
7#![allow(clippy::missing_panics_doc)]
8#![allow(clippy::module_name_repetitions)]
9
10pub mod digest;
11pub mod id;
12pub mod level;
13pub mod proof;
14pub mod url;
15#[macro_use]
16pub mod util;
17use crate::{id::IdError, proof::content::ValidationError};
18pub use semver::Version;
19
20pub use crate::{
21    digest::Digest,
22    id::{Id, PublicId, UnlockedId},
23    level::Level,
24    proof::{
25        review,
26        review::{Rating, Review},
27        trust::TrustLevel,
28    },
29    url::Url,
30};
31
32/// It's just a string. See [`SOURCE_CRATES_IO`]
33pub type RegistrySource<'a> = &'a str;
34
35/// Constant for `source` arguments, indicating
36pub const SOURCE_CRATES_IO: RegistrySource<'static> = "https://crates.io";
37
38#[cfg(test)]
39mod tests;
40
41type Result<T, E = Error> = std::result::Result<T, E>;
42
43#[derive(thiserror::Error, Debug)]
44pub enum Error {
45    #[error("`kind` field missing")]
46    KindFieldMissing,
47
48    #[error("Unexpected `kind` value in a legacy format")]
49    UnexpectedKindValueInALegacyFormat,
50
51    #[error("Parsing error when looking for start of code review proof")]
52    ParsingErrorWhenLookingForStartOfCodeReviewProof,
53
54    #[error("Parsing error: type name mismatch in the signature")]
55    ParsingErrorTypeNameMismatchInTheSignature,
56    #[error("Parsing error: type name mismatch in the footer")]
57    ParsingErrorTypeNameMismatchInTheFooter,
58    #[error("Signature too long")]
59    SignatureTooLong,
60    #[error("Unexpected EOF while parsing")]
61    UnexpectedEOFWhileParsing,
62    #[error("Proof body too long")]
63    ProofBodyTooLong,
64
65    #[error(transparent)]
66    Validation(#[from] ValidationError),
67
68    #[error("YAML formatting: {}", _0)]
69    YAMLFormat(Box<str>),
70
71    #[error(transparent)]
72    Id(#[from] IdError),
73
74    #[error(transparent)]
75    Parse(#[from] ParseError),
76
77    #[error("Unknown level: {}", _0)]
78    UnknownLevel(Box<str>),
79
80    #[error("I/O: {}", _0)]
81    IO(#[from] std::io::Error),
82
83    #[error("Error building proof: {}", _0)]
84    BuildingProof(Box<str>),
85
86    #[error("Error building review: {}", _0)]
87    BuildingReview(Box<str>),
88
89    #[error("Serialized to {} proofs", _0)]
90    SerializedTooManyProofs(usize),
91}
92
93#[derive(Debug, thiserror::Error)]
94pub enum ParseError {
95    #[error("Draft parse error: {}", _0)]
96    Draft(#[source] serde_yaml::Error),
97
98    #[error("Proof parse error: {}", _0)]
99    Proof(#[source] serde_yaml::Error),
100}