Skip to content

Commit

Permalink
Fixup changelog and other small things
Browse files Browse the repository at this point in the history
  • Loading branch information
dralley committed Oct 27, 2023
1 parent f677ffe commit 36a1a37
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 15 deletions.
12 changes: 7 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Bumped MSRV to 1.67

### Removed

- Removed `Package::get_file_checksums` and `Package::get_file_ima_signatures` functions, the same information is now retrievable using `Package::get_file_entries`.

### Added

- Support for symbolic link in file mode.
- Make file type const `REGULAR_FILE_TYPE` `DIR_FILE_TYPE` `SYMBOLIC_LINK_FILE_TYPE` public, because `FileMode::file_type` is public, sometimes we need this const to determin file type.
- Make file type const `REGULAR_FILE_TYPE` `DIR_FILE_TYPE` `SYMBOLIC_LINK_FILE_TYPE` public, because `FileMode::file_type` is public, sometimes we need this const to determine file type.
- Method `PackageBuilder::new` now takes a `summary` as last parameter, instead
of a `description`. A new method `PackageBuilder::description` can be used to
set a detailed description for a package; if not set, the description defaults
Expand All @@ -24,10 +28,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add method `is_no_replace` to `FileOptionsBuilder`, used to set the
`%config(noreplace)` flag on a file.
- Added the `FileEntry.linkto` field that is a target of a symbolic link.
- Removed `get_file_checksums`, `get_file_ima_signatures` and `get_file_digest_algorithm`
function and the information is accessible via `FileEntry` struct
(`FileEntry::digest_string` and `FileEntry::ima_signature`).
- Function `get_file_entries` returned empty vector for an RPM file without any file.
- Function `Package::get_file_entries` returns an empty vector for an RPM package without any files.
- `FileEntry` structs returned by (`Package::get_file_entries`) now include IMA signature information as well as digests for file entries.

## 0.12.1

Expand Down
32 changes: 29 additions & 3 deletions src/rpm/headers/header.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use md5::Md5;
use nom::{
bytes::complete,
number::complete::{be_i32, be_u16, be_u32, be_u64, be_u8},
};
use std::{fmt, io, marker::PhantomData, path::PathBuf};
use std::{fmt::{self, Display}, io, marker::PhantomData, path::PathBuf, fs::File};

use super::*;
use crate::{constants::*, errors::*, Timestamp};
Expand Down Expand Up @@ -380,10 +381,10 @@ pub struct FileOwnership {
#[derive(Debug, Clone, Hash, Eq, PartialEq)]
pub enum FileDigest {
Md5(Vec<u8>),
Sha2_224(Vec<u8>),
Sha2_256(Vec<u8>),
Sha2_384(Vec<u8>),
Sha2_512(Vec<u8>),
Sha2_224(Vec<u8>),
// @todo unsupported other types for now
}

Expand All @@ -403,6 +404,32 @@ impl FileDigest {
digest_algo => return Err(Error::UnsupportedDigestAlgorithm(digest_algo)),
})
}

pub fn algorithm(&self) -> DigestAlgorithm {
match self {
Self::Md5(_) => DigestAlgorithm::Md5,
Self::Sha2_224(_) => DigestAlgorithm::Sha2_224,
Self::Sha2_256(_) => DigestAlgorithm::Sha2_256,
Self::Sha2_384(_) => DigestAlgorithm::Sha2_384,
Self::Sha2_512(_) => DigestAlgorithm::Sha2_512,
}
}

pub fn as_hex(&self) -> String {
match self {
Self::Md5(d) => hex::encode(d),
Self::Sha2_224(d) => hex::encode(d),
Self::Sha2_256(d) => hex::encode(d),
Self::Sha2_384(d) => hex::encode(d),
Self::Sha2_512(d) => hex::encode(d),
}
}
}

impl Display for FileDigest {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.as_hex())
}
}

/// User facing accessor type for a changelog entry
Expand Down Expand Up @@ -430,7 +457,6 @@ pub struct FileEntry {
pub flags: FileFlags,
// @todo SELinux context? how is that done?
pub digest: Option<FileDigest>,
pub digest_string: String,
/// Defines any capabilities on the file.
pub caps: Option<String>,
/// Defines a target of a symlink (if the file is a symbolic link).
Expand Down
4 changes: 1 addition & 3 deletions src/rpm/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ impl PackageMetadata {
///
/// Note that this is not necessarily the same as the digest
/// used for headers.
fn get_file_digest_algorithm(&self) -> Result<DigestAlgorithm, Error> {
pub fn get_file_digest_algorithm(&self) -> Result<DigestAlgorithm, Error> {
self.header
.get_entry_data_as_u32(IndexTag::RPMTAG_FILEDIGESTALGO)
.and_then(|x| {
Expand Down Expand Up @@ -892,7 +892,6 @@ impl PackageMetadata {
.try_fold::<Vec<FileEntry>, _, Result<_, Error>>(
Vec::with_capacity(n),
|mut acc, (idx, (path, user, group, mode, digest, mtime, size, flags, linkto))| {
let digest_string = digest.to_owned();
let digest = if digest.is_empty() {
None
} else {
Expand All @@ -915,7 +914,6 @@ impl PackageMetadata {
mode: mode.into(),
modified_at: crate::Timestamp(mtime),
digest,
digest_string,
flags: FileFlags::from_bits_retain(flags),
size: size as usize,
caps: cap,
Expand Down
3 changes: 2 additions & 1 deletion src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ fn test_rpm_header() -> Result<(), Box<dyn std::error::Error>> {
let checksums: Vec<_> = metadata
.get_file_entries()?
.iter()
.map(|e| e.digest_string.clone())
.map(|e| e.digest.as_ref().map(|d| d.to_string()))
.map(|d| d.unwrap_or("".to_owned()))
.collect();
assert_eq!(expected_file_checksums, checksums);

Expand Down
6 changes: 3 additions & 3 deletions tests/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ fn test_rpm_file_signatures() -> Result<(), Box<dyn std::error::Error>> {
assert_eq!(
signatures,
[
Some(String::from("0302041adfaa0e004630440220162785458f5d81d1393cc72afc642c86167c15891ea39213e28907b1c4e8dc6c02202fa86ad2f5e474d36c59300f736f52cb5ed24abb55759a71ec224184a7035a78")),
Some(String::from("0302041adfaa0e00483046022100bd940093777b75650980afb656507f2729a05c9b1bc9986993106de9f301a172022100b3384f6ba200a5a80647a0f0727c5b8f3ab01f74996a1550db605b44af3d10bf")),
Some(String::from("0302041adfaa0e00473045022068953626d7a5b65aa4b1f1e79a2223f2d3500ddcb3d75a7050477db0480a13e10221008637cefe8c570044e11ff95fa933c1454fd6aa8793bbf3e87edab2a2624df460")),
Some("0302041adfaa0e004630440220162785458f5d81d1393cc72afc642c86167c15891ea39213e28907b1c4e8dc6c02202fa86ad2f5e474d36c59300f736f52cb5ed24abb55759a71ec224184a7035a78".to_string()),
Some("0302041adfaa0e00483046022100bd940093777b75650980afb656507f2729a05c9b1bc9986993106de9f301a172022100b3384f6ba200a5a80647a0f0727c5b8f3ab01f74996a1550db605b44af3d10bf".to_string()),
Some("0302041adfaa0e00473045022068953626d7a5b65aa4b1f1e79a2223f2d3500ddcb3d75a7050477db0480a13e10221008637cefe8c570044e11ff95fa933c1454fd6aa8793bbf3e87edab2a2624df460".to_string()),
],
);

Expand Down

0 comments on commit 36a1a37

Please sign in to comment.