Skip to content

Commit

Permalink
Always create package digests
Browse files Browse the repository at this point in the history
Remove the signature-meta feature because it's a bit superfluous

closes #105
  • Loading branch information
dralley committed Mar 19, 2023
1 parent 64f1cb0 commit 7937cd4
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 39 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Added `rpmlib()` dependencies to built packages as appropriate
- Ensured that digests are always added to built RPMs. Previously they would not be included unless
the "signature-meta" (or "signature-pgp") features were enabled.

### Breaking Changes

Expand Down
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,11 @@ tokio-util = { version = "0.7.4", features = ["compat"]}
[features]
default = ["signature-pgp"]

signature-pgp = ["signature-meta", "pgp"]
signature-meta = []
signature-pgp = ["pgp"]
async-futures = ["futures"]

# The use of these features implies that async-futures are being used -
# explicitly define this feature.
test-with-podman = ["async-futures", "signature-meta", "tokio-util"]
test-with-podman = ["async-futures", "tokio-util"]
with-file-async-tokio = ["async-futures", "tokio/fs", "tokio-util"]
with-file-async-async-std = ["async-futures", "async-std"]
4 changes: 1 addition & 3 deletions src/compat_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ fn cargo_out_dir() -> std::path::PathBuf {
cargo_manifest_dir().join("target")
}

#[cfg(feature = "signature-meta")]
use signature::{self, Verifying};

#[cfg(feature = "signature-pgp")]
mod pgp {
use super::*;
use futures::io::AsyncWriteExt;
use signature::pgp::{Signer, Verifier};
use signature::{self, Verifying};
use tokio_util::compat::TokioAsyncReadCompatExt;

#[tokio::test]
Expand Down
5 changes: 2 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//!
//! ```rust
//!
//! # #[cfg(feature = "signature-meta")]
//! # #[cfg(feature = "signature-pgp")]
//! use rpm::{
//! signature::pgp::{
//! Signer,
Expand All @@ -17,7 +17,7 @@
//! use std::str::FromStr;
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! # #[cfg(feature = "signature-meta")]
//! # #[cfg(feature = "signature-pgp")]
//! # {
//! let raw_secret_key = std::fs::read("./test_assets/secret_key.asc")?;
//! let pkg = rpm::RPMBuilder::new("test", "1.0.0", "MIT", "x86_64", "some awesome package")
Expand Down Expand Up @@ -70,7 +70,6 @@ pub use crate::errors::*;
pub(crate) mod constants;
pub use crate::constants::*;

#[cfg(feature = "signature-meta")]
mod sequential_cursor;

mod rpm;
Expand Down
7 changes: 0 additions & 7 deletions src/rpm/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ use super::headers::*;
use super::Lead;
use crate::constants::*;

#[cfg(feature = "signature-meta")]
use crate::sequential_cursor::SeqCursor;
#[cfg(feature = "signature-meta")]
use crate::signature;

use crate::RPMPackage;
Expand Down Expand Up @@ -389,7 +387,6 @@ impl RPMBuilder {
let mut header = Vec::with_capacity(128);
header_idx_tag.write(&mut header)?;

#[cfg(feature = "signature-meta")]
let digest_header = {
let header = header;
let (header_digest_sha1, header_and_content_digest_md5) =
Expand All @@ -407,8 +404,6 @@ impl RPMBuilder {
.expect("signature header + signature length must be <4gb"),
)
};
#[cfg(not(feature = "signature-meta"))]
let digest_header = { Header::<IndexSignatureTag>::new_empty() };

let metadata = RPMPackageMetadata {
lead,
Expand All @@ -422,7 +417,6 @@ impl RPMBuilder {
/// use an external signer to sing and build
///
/// See `signature::Signing` for more details.
#[cfg(feature = "signature-meta")]
pub fn build_and_sign<S>(self, signer: S) -> Result<RPMPackage, RPMError>
where
S: signature::Signing<crate::signature::algorithm::RSA>,
Expand Down Expand Up @@ -471,7 +465,6 @@ impl RPMBuilder {
}

/// use prepared data but make sure the signatures are
#[cfg(feature = "signature-meta")]
fn derive_hashes(header: &[u8], content: &[u8]) -> Result<(String, Vec<u8>), RPMError> {
let digest_md5 = {
use md5::Digest;
Expand Down
8 changes: 3 additions & 5 deletions src/rpm/headers/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ where
.ok_or_else(|| RPMError::TagNotFound(tag.to_string()))
}

#[cfg(feature = "signature-meta")]
#[allow(unused)]
pub(crate) fn get_entry_data_as_binary(&self, tag: T) -> Result<&[u8], RPMError> {
let entry = self.find_entry_or_err(&tag)?;
entry
Expand Down Expand Up @@ -308,7 +308,7 @@ impl Header<IndexSignatureTag> {
/// PGP and RSA tags expect signatures according to [RFC2440](https://tools.ietf.org/html/rfc2440)
///
/// Please use the [`builder`](Self::builder()) which has modular and safe API.
#[cfg(feature = "signature-meta")]
#[allow(unused)]
pub(crate) fn new_signature_header(
headers_plus_payload_size: u32,
md5sum: &[u8],
Expand All @@ -322,7 +322,6 @@ impl Header<IndexSignatureTag> {
.build(headers_plus_payload_size)
}

#[cfg(feature = "signature-meta")]
pub fn builder() -> SignatureHeaderBuilder<Empty> {
SignatureHeaderBuilder::<Empty>::new()
}
Expand Down Expand Up @@ -516,7 +515,6 @@ where
mod tests2 {
use super::*;

#[cfg(feature = "signature-meta")]
#[test]
fn signature_header_build() {
let size: u32 = 209_348;
Expand Down Expand Up @@ -959,7 +957,7 @@ impl IndexData {
}
}

#[cfg(feature = "signature-meta")]
#[allow(unused)]
pub(crate) fn as_binary(&self) -> Option<&[u8]> {
match self {
IndexData::Bin(d) => Some(d.as_slice()),
Expand Down
2 changes: 0 additions & 2 deletions src/rpm/headers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ pub use header::*;
pub(crate) use lead::*;
pub use types::*;

#[cfg(feature = "signature-meta")]
mod signature_builder;

#[cfg(feature = "signature-meta")]
pub use signature_builder::*;
1 change: 0 additions & 1 deletion src/rpm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ mod compressor;
mod headers;
mod package;

#[cfg(feature = "signature-meta")]
pub mod signature;

pub use headers::*;
Expand Down
11 changes: 1 addition & 10 deletions src/rpm/package.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::io::BufReader;
use std::io::{BufReader, Seek};
use std::path::{Path, PathBuf};

use chrono::offset::TimeZone;
Expand All @@ -12,14 +12,9 @@ use super::Lead;
use crate::constants::*;
use crate::errors::*;

#[cfg(feature = "signature-meta")]
use crate::sequential_cursor::SeqCursor;
#[cfg(feature = "signature-meta")]
use crate::signature;

#[cfg(feature = "signature-meta")]
use std::io::Seek;

/// A complete rpm file.
///
/// Can either be created using the [`RPMPackageBuilder`](super::builder::RPMPackageBuilder)
Expand Down Expand Up @@ -73,7 +68,6 @@ impl RPMPackage {
// TODO allow passing an external signer/verifier

/// sign all headers (except for the lead) using an external key and store it as the initial header
#[cfg(feature = "signature-meta")]
pub fn sign<S>(&mut self, signer: S) -> Result<(), RPMError>
where
S: signature::Signing<signature::algorithm::RSA, Signature = Vec<u8>>,
Expand Down Expand Up @@ -139,9 +133,6 @@ impl RPMPackage {
}

/// Verify the signature as present within the RPM package.
///
///
#[cfg(feature = "signature-meta")]
pub fn verify_signature<V>(&self, verifier: V) -> Result<(), RPMError>
where
V: signature::Verifying<signature::algorithm::RSA, Signature = Vec<u8>>,
Expand Down
2 changes: 1 addition & 1 deletion src/rpm/signature/traits.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Trait abstractions of signinggraphic operations.
//! Trait abstractions of signing operations.
//!
//! Does not contain hashing! Hashes are fixed by the rpm
//! "spec" to sha1, md5 (yes, that is correct), sha2_256.
Expand Down
7 changes: 3 additions & 4 deletions src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::*;

#[cfg(feature = "signature-meta")]
#[cfg(feature = "signature-pgp")]
use crate::signature::pgp::{Signer, Verifier};

fn test_private_key_path() -> std::path::PathBuf {
Expand Down Expand Up @@ -31,7 +31,7 @@ fn cargo_manifest_dir() -> std::path::PathBuf {
std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
}

#[cfg(feature = "signature-meta")]
#[cfg(feature = "signature-pgp")]
#[test]
fn test_rpm_file_signatures() -> Result<(), Box<dyn std::error::Error>> {
let rpm_file_path = file_signatures_test_rpm_file_path();
Expand All @@ -52,7 +52,7 @@ fn test_rpm_file_signatures() -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}

#[cfg(feature = "signature-meta")]
#[cfg(feature = "signature-pgp")]
#[test]
fn test_rpm_file_signatures_resign() -> Result<(), Box<dyn std::error::Error>> {
let rpm_file_path = file_signatures_test_rpm_file_path();
Expand Down Expand Up @@ -408,7 +408,6 @@ fn test_rpm_header() -> Result<(), Box<dyn std::error::Error>> {
test_rpm_header_base(package)
}

#[cfg(feature = "signature-meta")]
#[test]
fn test_region_tag() -> Result<(), Box<dyn std::error::Error>> {
let region_entry = Header::create_region_tag(IndexSignatureTag::HEADER_SIGNATURES, 2, 400);
Expand Down

0 comments on commit 7937cd4

Please sign in to comment.