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
//! This crate contains only code handling data types
//! used by `crev`, without getting into details
//! how actually `crev` works (where and how it manages data).
#![allow(clippy::default_trait_access)]
#![allow(clippy::items_after_statements)]
#![allow(clippy::missing_errors_doc)]
#![allow(clippy::missing_panics_doc)]
#![allow(clippy::module_name_repetitions)]

pub mod digest;
pub mod id;
pub mod level;
pub mod proof;
pub mod url;
#[macro_use]
pub mod util;
use crate::{id::IdError, proof::content::ValidationError};
pub use semver::Version;

pub use crate::{
    digest::Digest,
    id::{Id, PublicId, UnlockedId},
    level::Level,
    proof::{
        review,
        review::{Rating, Review},
        trust::TrustLevel,
    },
    url::Url,
};

/// It's just a string. See [`SOURCE_CRATES_IO`]
pub type RegistrySource<'a> = &'a str;

/// Constant for `source` arguments, indicating
pub const SOURCE_CRATES_IO: RegistrySource<'static> = "https://crates.io";

#[cfg(test)]
mod tests;

type Result<T, E = Error> = std::result::Result<T, E>;

#[derive(thiserror::Error, Debug)]
pub enum Error {
    #[error("`kind` field missing")]
    KindFieldMissing,

    #[error("Unexpected `kind` value in a legacy format")]
    UnexpectedKindValueInALegacyFormat,

    #[error("Parsing error when looking for start of code review proof")]
    ParsingErrorWhenLookingForStartOfCodeReviewProof,

    #[error("Parsing error: type name mismatch in the signature")]
    ParsingErrorTypeNameMismatchInTheSignature,
    #[error("Parsing error: type name mismatch in the footer")]
    ParsingErrorTypeNameMismatchInTheFooter,
    #[error("Signature too long")]
    SignatureTooLong,
    #[error("Unexpected EOF while parsing")]
    UnexpectedEOFWhileParsing,
    #[error("Proof body too long")]
    ProofBodyTooLong,

    #[error(transparent)]
    Validation(#[from] ValidationError),

    #[error("YAML formatting: {}", _0)]
    YAMLFormat(Box<str>),

    #[error(transparent)]
    Id(#[from] IdError),

    #[error(transparent)]
    Parse(#[from] ParseError),

    #[error("Unknown level: {}", _0)]
    UnknownLevel(Box<str>),

    #[error("I/O: {}", _0)]
    IO(#[from] std::io::Error),

    #[error("Error building proof: {}", _0)]
    BuildingProof(Box<str>),

    #[error("Error building review: {}", _0)]
    BuildingReview(Box<str>),

    #[error("Serialized to {} proofs", _0)]
    SerializedTooManyProofs(usize),
}

#[derive(Debug, thiserror::Error)]
pub enum ParseError {
    #[error("Draft parse error: {}", _0)]
    Draft(#[source] serde_yaml::Error),

    #[error("Proof parse error: {}", _0)]
    Proof(#[source] serde_yaml::Error),
}