voa_openpgp/import/destructured/
error.rs

1//! Error handling for importing destructured [OpenPGP certificates] as [VOA] verifiers.
2//!
3//! [OpenPGP certificates]: https://openpgp.dev/book/certificates.html
4//! [VOA]: https://uapi-group.org/specifications/specs/file_hierarchy_for_the_verification_of_os_artifacts/
5
6use std::path::PathBuf;
7
8use pgp::types::{Fingerprint, Tag};
9
10use crate::import::destructured::{CERTIFICATION_DIR, REVOCATION_DIR};
11
12/// The error that can occur when importing verifiers.
13#[derive(Debug, thiserror::Error)]
14pub enum Error {
15    /// A directory must only contain other directories, but contains a path that is not a
16    /// directory.
17    #[error(
18        "The directory {dir:?} must only contain directories, but the path {path:?} is not a directory."
19    )]
20    DirMustContainDirs {
21        /// The directory that must only contain other directories.
22        dir: PathBuf,
23        /// The path, that does not represent a directory.
24        path: PathBuf,
25    },
26
27    /// A directory is only supposed to contain regular files, but contains a path that is not a
28    /// regular file.
29    #[error(
30        "The directory {dir:?} must only contain regular files, but the path {path:?} is not a regular file."
31    )]
32    DirMustContainRegularFiles {
33        /// The directory that must only contain regular files.
34        dir: PathBuf,
35        /// The path, that does not represent a regular file.
36        path: PathBuf,
37    },
38
39    /// A directory must only contain regular files or directories, but contains a path that
40    /// represents neither.
41    #[error(
42        "The directory {dir:?} must only contain regular files or directories, but the path {path:?} is neither."
43    )]
44    DirMustContainRegularFilesOrDirs {
45        /// The directory that must only contain regular files or other directories.
46        dir: PathBuf,
47        /// The path, that does not represent a regular file or directory.
48        path: PathBuf,
49    },
50
51    /// There is an additional, unwanted OpenPGP certificate.
52    #[error("There is an excess OpenPGP certificate with fingerprint {fingerprint} in {path:?}")]
53    ExcessCertificateInDir {
54        /// The directory path in which OpenPGP packets of more than one OpenPGP certificate are
55        /// present.
56        path: PathBuf,
57        /// The OpenPGP fingerprint of the excess OpenPGP certificate.
58        fingerprint: Fingerprint,
59    },
60
61    /// There is an additional, unwanted OpenPGP packet in a file.
62    #[error("There is an excess {tag:?} OpenPGP packet in file {path:?}")]
63    ExcessPacket {
64        /// The path of the file in which an excess OpenPGP packet is present.
65        path: PathBuf,
66        /// The excess OpenPGP packet.
67        tag: Tag,
68    },
69
70    /// A regular file is empty.
71    #[error("The file {path:?} is empty.")]
72    FileIsEmpty {
73        /// The path of the empty file.
74        path: PathBuf,
75    },
76
77    /// A directory does not have a valid Arch Linux keyring structure.
78    #[error("The import directory {path:?} does not contain a valid Arch Linux keyring structure")]
79    InvalidArchLinuxKeyringStructure {
80        /// The path to the directory that is not a valid Arch Linux keyring structure.
81        path: PathBuf,
82    },
83
84    /// A directory in a User ID directory is not valid
85    #[error(
86        "The directory {path:?} is not a valid component subdirectory ({} and/or {})",
87        CERTIFICATION_DIR,
88        REVOCATION_DIR
89    )]
90    InvalidComponentSubDirectory {
91        /// The path to the directory that is invalid in a User ID directory.
92        path: PathBuf,
93    },
94
95    /// A directory does not have a valid flat structure.
96    #[error("The import directory {path:?} does not contain a valid flat structure")]
97    InvalidFlatStructure {
98        /// The path to the directory that does not contain a flat structure.
99        path: PathBuf,
100    },
101
102    /// There is more than one top-level OpenPGP packet file in a directory.
103    #[error("There is more than one top-level OpenPGP packet file in directory {path:?}")]
104    MultipleTopLevelPackets {
105        /// The path of a directory with more than one top-level OpenPGP packet file.
106        path: PathBuf,
107    },
108
109    /// An OpenPGP certificate cannot be constructed from OpenPGP packets in a directory.
110    #[error("No OpenPGP certificate can be constructed from the directory {path:?}")]
111    NoOpenPgpCertInDir {
112        /// The directory path from which no OpenPGP certificate can be constructed.
113        path: PathBuf,
114    },
115
116    /// There is no OpenPGP packet in a file.
117    #[error("There is no OpenPGP packet in file {path:?}")]
118    NoPacketInFile {
119        /// The path at which no packet
120        path: PathBuf,
121    },
122
123    /// There is no top-level OpenPGP packet file in a directory.
124    #[error("There is no top-level OpenPGP packet file in directory {path:?}")]
125    NoTopLevelPacket {
126        /// The path of a directory in which there is no top-level OpenPGP packet file.
127        path: PathBuf,
128    },
129
130    /// A path is not a directory.
131    #[error("The path {path:?} is not a directory.")]
132    PathIsNotADir {
133        /// The path that is not a directory.
134        path: PathBuf,
135    },
136}