Skip to content

Commit dc5d409

Browse files
src/fsverity: split out FsVerityHashValue and impls
Split FsVerityHashValue and its two implementations out to a separate file. Right now it's not a lot of code, but it's going to get substantially larger in the next commit. Signed-off-by: Allison Karlitskaya <[email protected]>
1 parent 7667ec0 commit dc5d409

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed

src/fsverity/hashvalue.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use sha2::{digest::FixedOutputReset, digest::Output, Digest, Sha256, Sha512};
2+
3+
pub trait FsVerityHashValue
4+
where
5+
Self: Eq + AsRef<[u8]> + Clone,
6+
Self: From<Output<Self::Digest>>,
7+
{
8+
type Digest: Digest + FixedOutputReset + std::fmt::Debug;
9+
const ALGORITHM: u8;
10+
const EMPTY: Self;
11+
}
12+
13+
pub type Sha256HashValue = [u8; 32];
14+
15+
impl FsVerityHashValue for Sha256HashValue {
16+
type Digest = Sha256;
17+
const ALGORITHM: u8 = 1;
18+
const EMPTY: Self = [0; 32];
19+
}
20+
21+
pub type Sha512HashValue = [u8; 64];
22+
23+
impl FsVerityHashValue for Sha512HashValue {
24+
type Digest = Sha512;
25+
const ALGORITHM: u8 = 2;
26+
const EMPTY: Self = [0; 64];
27+
}

src/fsverity/mod.rs

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,12 @@
11
mod digest;
2+
mod hashvalue;
23
mod ioctl;
34

45
use std::{io::Error, os::fd::AsFd};
56

6-
use sha2::{digest::FixedOutputReset, digest::Output, Digest, Sha256, Sha512};
77
use thiserror::Error;
88

9-
pub trait FsVerityHashValue
10-
where
11-
Self: Eq + AsRef<[u8]> + Clone,
12-
Self: From<Output<Self::Digest>>,
13-
{
14-
type Digest: Digest + FixedOutputReset + std::fmt::Debug;
15-
const ALGORITHM: u8;
16-
const EMPTY: Self;
17-
}
18-
19-
pub type Sha256HashValue = [u8; 32];
20-
21-
impl FsVerityHashValue for Sha256HashValue {
22-
type Digest = Sha256;
23-
const ALGORITHM: u8 = 1;
24-
const EMPTY: Self = [0; 32];
25-
}
26-
27-
pub type Sha512HashValue = [u8; 64];
28-
29-
impl FsVerityHashValue for Sha512HashValue {
30-
type Digest = Sha512;
31-
const ALGORITHM: u8 = 2;
32-
const EMPTY: Self = [0; 64];
33-
}
9+
pub use hashvalue::{FsVerityHashValue, Sha256HashValue, Sha512HashValue};
3410

3511
/// Measuring fsverity failed.
3612
#[derive(Error, Debug)] // can't derive PartialEq because of std::io::Error

0 commit comments

Comments
 (0)