Skip to content

Commit

Permalink
Clean up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dralley committed Jul 6, 2023
1 parent cb82cb2 commit ef4921f
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 228 deletions.
1 change: 1 addition & 0 deletions src/rpm/headers/signature_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ mod test {
.is_ok());
}

// @todo: this test is kind of duplicative, probably not necessary?
#[cfg(feature = "signature-meta")]
#[test]
fn signature_header_build() {
Expand Down
41 changes: 3 additions & 38 deletions src/rpm/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ use num_traits::FromPrimitive;

use crate::{constants::*, errors::*, CompressionType};

#[cfg(feature = "signature-meta")]
use crate::{signature, Timestamp};
#[cfg(feature = "signature-pgp")]
use crate::signature::pgp::Verifier;
#[cfg(feature = "signature-meta")]
use crate::{signature, Timestamp};
#[cfg(feature = "signature-meta")]
use std::{fmt::Debug, io::Read};

use super::headers::*;
Expand Down Expand Up @@ -178,7 +178,7 @@ impl RPMPackage {
Ok(())
}

/// Return the key id (issuer) of the signature
/// Return the key id (issuer) of the signature as a hexadecimal string
#[cfg(feature = "signature-pgp")]
pub fn signature_key_id(&self) -> Result<Option<String>, RPMError> {
let rsa_sig = &self
Expand Down Expand Up @@ -264,41 +264,6 @@ impl RPMPackage {
verifier.verify(header_bytes.as_slice(), signature_header_only)?;
}

// match verifier.algorithm() {
// signature::AlgorithmType::RSA => {
// if let Ok(signature_header_and_content) = rpm_v3_sig {
// signature::echo_signature(
// "signature_header(header and content)",
// signature_header_and_content,
// );
// let header_and_content_cursor =
// io::Cursor::new(&header_bytes).chain(io::Cursor::new(&self.content));
// verifier.verify(header_and_content_cursor, signature_header_and_content)?;
// }

// if let Ok(signature_header_only) = rsa_sig {
// signature::echo_signature(
// "signature_header(header only)",
// signature_header_only,
// );
// verifier.verify(header_bytes.as_slice(), signature_header_only)?;
// } else {
// return Err(RPMError::VerificationError { source: (), key_ref: () })
// }
// }
// signature::AlgorithmType::EdDSA => {
// if let Ok(signature_header_only) = eddsa_sig {
// signature::echo_signature(
// "signature_header(header only)",
// signature_header_only,
// );
// verifier.verify(header_bytes.as_slice(), signature_header_only)?;
// } else {
// return Err(RPMError::VerificationError { source: (), key_ref: () })
// }
// }
//}

Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion src/rpm/signature/pgp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,9 @@ pub(crate) mod test {

#[test]
fn verify_pgp_crate() {
use chrono::{TimeZone, Utc};
use pgp::types::{PublicKeyTrait, SecretKeyTrait};
use pgp::Signature;
use chrono::{TimeZone, Utc};

const RPM_SHA2_256: [u8; 32] =
hex!("d92bfe276e311a67fe128768c5df4d06fd461e043afdf872ba4c679d860db81e");
Expand Down
4 changes: 2 additions & 2 deletions src/rpm/signature/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
//! Does not contain hashing! Hashes are fixed by the rpm
//! "spec" to sha1, md5 (yes, that is correct), sha2_256.

use std::io;
use std::fmt::Debug;
use crate::errors::*;
use crate::Timestamp;
use std::fmt::Debug;
use std::io;

#[derive(Clone, Copy, Debug)]
pub enum AlgorithmType {
Expand Down
16 changes: 10 additions & 6 deletions tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,19 @@ pub fn load_asc_keys() -> (Vec<u8>, Vec<u8>) {
}

pub fn load_rsa_keys() -> (Vec<u8>, Vec<u8>) {
let signing_key_path =
(rsa_private_key(), rsa_public_key())
}

pub fn rsa_private_key() -> Vec<u8> {
let private_key =
cargo_manifest_dir().join("test_assets/fixture_packages/signing_keys/secret_rsa4096.asc");
let signing_key = std::fs::read(signing_key_path).unwrap();
std::fs::read(private_key).unwrap()
}

let verification_key_path =
pub fn rsa_public_key() -> Vec<u8> {
let public_key =
cargo_manifest_dir().join("test_assets/fixture_packages/signing_keys/public_rsa4096.asc");
let verification_key = std::fs::read(verification_key_path).unwrap();

(signing_key.to_vec(), verification_key.to_vec())
std::fs::read(public_key).unwrap()
}

pub fn eddsa_private_key() -> Vec<u8> {
Expand Down
Loading

0 comments on commit ef4921f

Please sign in to comment.