deb 0.5.20

Utilities for working with files and formats commonly found when working with Debian's project tooling, or infrastructure.
Documentation
// {{{ Copyright (c) Paul R. Tagliamonte <paultag@debian.org>, 2024
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. }}}

use super::{CommonSourceControl, PackageList};
use crate::control::{FileDigestMd5, FileDigestSha1, FileDigestSha256, PriorityParseError};

#[cfg(feature = "serde")]
use ::serde::{Deserialize, Serialize};

// TODO:
//   - format enum
//   - validation of optional fields that are contextually required

/// Error conditions which may be encountered when working with a [Dsc]
/// file.
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum DscParseError {
    /// This is, unfortunately, a very generic and generally unhelpful
    /// error. This is returned if *something* wasn't as expected with the
    /// file.
    ///
    /// There are a few cases where a [DscParseError::Malformed] is returned
    /// where something else would have been more helpful. A lot of places
    /// that return a `Malformed` today are likely to change error cases
    /// in the future.
    Malformed,

    /// The provided `Priority` value was invalid in some delightful hard
    /// to understand way.
    InvalidPriority(PriorityParseError),
}
crate::errors::error_enum!(DscParseError);

/// When preparing a package upload for Debian, the source package's
/// manifest is generated in the form of a `.dsc`.
///
/// These fields are clearsigned with a specific Developer or buildd
/// machine's OpenPGP key.
///
/// There's a lot more information `dsc(5)`, and some of the
/// fields in this struct contain text written in that manpage.
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "PascalCase"))]
pub struct Dsc {
    /// The value of this field declares the format version of the source
    /// package.  The field value is used by programs acting on a source
    /// package to interpret the list of files in the source package and
    /// determine how to unpack it. The syntax of the field value is a
    /// numeric major revision (`0-9`), a period (`.`), a numeric minor
    /// revision (`0-9`), and then an optional subtype after whitespace
    /// (` \t`), which if specified is a lowercase alphanumeric (`a-z0-9`)
    /// word in parentheses (`()`). The subtype is optional in the syntax but
    /// may be mandatory for particular source format revisions.
    ///
    /// The source formats currently supported by `dpkg` are `1.0`, `2.0`,
    /// `3.0 (native)`, `3.0 (quilt)`, `3.0 (git)`, `3.0 (bzr)` and
    /// `3.0 (custom)`. See dpkg-source(1) for their description.
    pub format: String,

    /// The value of this field determines the package name, and is used to
    /// generate file names by most installation tools.
    pub source: String,

    /// Source control information
    #[cfg_attr(feature = "serde", serde(flatten))]
    pub control: CommonSourceControl,

    /// list of binary packages generated by this source package.
    #[cfg_attr(feature = "serde", serde(rename = "Package-List"))]
    pub package_list: Option<Vec<PackageList>>,

    /// Files contains a list of files with an md5sum, size, section and
    /// priority for each one.
    ///
    /// Each line consists of space-separated entries describing the
    /// file: the md5sum, the file size, the file section, the file priority,
    /// and the file name.
    ///
    /// This field lists all files that make up the upload. The list of files
    /// in this field must match the list of files in the other related
    /// Digests fields.
    ///
    /// Note: The MD5 checksum is considered weak, and should never be assumed
    /// to be sufficient for secure verification, but this field cannot be
    /// omitted as it provides metadata not available anywhere else.
    pub files: Vec<FileDigestMd5>,

    /// Each line consists of space-separated entries describing the file:
    /// the checksum, the file size, and the file name.
    ///
    /// These fields list all files that make up the upload. The list of files
    /// in these fields must match the list of files in the Files field and
    /// the other related Digests fields.
    ///
    /// Note: The SHA-1 checksum is considered weak, and should never be
    /// assumed to be sufficient for secure verification.
    #[cfg_attr(feature = "serde", serde(rename = "Checksums-Sha1"))]
    pub checksum_sha1: Option<Vec<FileDigestSha1>>,

    /// Each line consists of space-separated entries describing the file:
    /// the checksum, the file size, and the file name.
    ///
    /// These fields list all files that make up the upload. The list of files
    /// in these fields must match the list of files in the Files field and
    /// the other related Digests fields.
    #[cfg_attr(feature = "serde", serde(rename = "Checksums-Sha256"))]
    pub checksum_sha256: Vec<FileDigestSha256>,
}

// vim: foldmethod=marker