Skip to content

Commit bf02f62

Browse files
committed
check signatures for all directories
Signed-off-by: Daniel Maslowski <[email protected]>
1 parent 14ba11c commit bf02f62

File tree

2 files changed

+48
-16
lines changed

2 files changed

+48
-16
lines changed

src/main.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,15 @@ fn main() {
192192
fpt.header.checksum
193193
);
194194
}
195-
match &me.fpt_area.check_ftpr_sig() {
196-
Ok(()) => println!("FTPR signature is valid"),
197-
Err(e) => println!("FTPR signature error: {e:}"),
195+
match &me.fpt_area.check_ftpr_presence() {
196+
Ok(()) => println!("FTPR exists"),
197+
Err(e) => println!("FTPR error: {e:}"),
198+
}
199+
for (n, r) in me.fpt_area.check_dir_sigs() {
200+
match r {
201+
Ok(()) => println!(" {n}: signature is valid"),
202+
Err(e) => println!(" {n}: signature error: {e}"),
203+
}
198204
}
199205
return;
200206
}

src/me.rs

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ use crate::dir::{
1313
gen3::{CPD_MAGIC_BYTES, CodePartitionDirectory},
1414
};
1515
use crate::part::fpt::FTPR;
16+
use crate::part::gen2::DirPartition;
17+
use crate::part::gen3::CPDPartition;
1618
use crate::part::part::Partition;
1719
use crate::part::{
1820
fpt::{FPT, MIN_FPT_SIZE},
@@ -69,26 +71,50 @@ impl FPTArea {
6971
}
7072
}
7173

72-
pub fn check_ftpr_sig(&self) -> Result<(), String> {
74+
pub fn check_dir_sigs(&self) -> Vec<(String, Result<(), String>)> {
7375
match &self.partitions {
7476
Partitions::Gen2(parts) => {
75-
if let Some(ftpr) = parts.iter().find(|p| p.entry().name() == FTPR) {
76-
match ftpr {
77-
Gen2Partition::Dir(dir) => dir.check_signature(),
78-
_ => Err("FTPR partition not recognized as directory".into()),
79-
}
77+
let dirs = parts
78+
.iter()
79+
.filter_map(|p| match p {
80+
Gen2Partition::Dir(d) => Some(d.clone()),
81+
_ => None,
82+
})
83+
.collect::<Vec<DirPartition>>();
84+
dirs.iter()
85+
.map(|d| (d.entry.name(), d.check_signature()))
86+
.collect()
87+
}
88+
Partitions::Gen3(parts) => {
89+
let dirs = parts
90+
.iter()
91+
.filter_map(|p| match p {
92+
Gen3Partition::Dir(d) => Some(d.clone()),
93+
_ => None,
94+
})
95+
.collect::<Vec<CPDPartition>>();
96+
dirs.iter()
97+
.map(|d| (d.entry.name(), d.check_signature()))
98+
.collect()
99+
}
100+
_ => vec![],
101+
}
102+
}
103+
104+
pub fn check_ftpr_presence(&self) -> Result<(), String> {
105+
match &self.partitions {
106+
Partitions::Gen2(parts) => {
107+
if parts.iter().find(|p| p.entry().name() == FTPR).is_some() {
108+
Ok(())
80109
} else {
81-
Err("FTPR partition not found".into())
110+
Err("not found".into())
82111
}
83112
}
84113
Partitions::Gen3(parts) => {
85-
if let Some(ftpr) = parts.iter().find(|p| p.entry().name() == FTPR) {
86-
match ftpr {
87-
Gen3Partition::Dir(dir) => dir.check_signature(),
88-
_ => Err("FTPR partition not recognized as directory".into()),
89-
}
114+
if parts.iter().find(|p| p.entry().name() == FTPR).is_some() {
115+
Ok(())
90116
} else {
91-
Err("FTPR partition not found".into())
117+
Err("not found".into())
92118
}
93119
}
94120
_ => Err("not recognized as ME generation 2 or 3".into()),

0 commit comments

Comments
 (0)