Unverified Commit ef5ca540 authored by Jeremy Soller's avatar Jeremy Soller Committed by GitHub
Browse files

Merge pull request #1 from jabedude/master

Fix TODO: calculate DMI table checksum in is_valid method
parents 0cb41837 df986494
......@@ -31,8 +31,15 @@ unsafe impl Plain for Smbios {}
impl Smbios {
pub fn is_valid(&self) -> bool {
//TODO: Checksum
self.anchor == *b"_SM_"
let mut sum: u8 = self.anchor.iter().fold(0,|a, &b| a + b);
sum += self.checksum;
sum += self.length;
sum += self.major_version;
sum += self.minor_version;
sum = sum + (self.max_structure_size as u8);
sum += self.revision;
sum += self.formatted.iter().fold(0,|a, &b| a + b);
sum == 0
}
}
......
extern crate dmi;
#[test]
fn table_checksum_is_valid() {
let s = dmi::Smbios {
anchor: *b"_SM_",
checksum: 0xc2,
length: 0x1f,
major_version: 0x02,
minor_version: 0x07,
max_structure_size: 0xb8,
revision: 0x00,
formatted: [0x00, 0x00, 0x00, 0x00, 0x00],
inter_anchor: *b"_DMI_",
inter_checksum: 0x3e,
table_length: 0x0c15,
table_address: 0x000e92f0,
structure_count: 0x0052,
bcd_revision: 27,
};
assert!(s.is_valid());
}
#[test]
fn table_checksum_is_invalid() {
let s = dmi::Smbios {
anchor: *b"_SM_",
checksum: 0x00,
length: 0x1f,
major_version: 0x02,
minor_version: 0x07,
max_structure_size: 0xb8,
revision: 0x00,
formatted: [0x00, 0x00, 0x00, 0x00, 0x00],
inter_anchor: *b"_DMI_",
inter_checksum: 0x3e,
table_length: 0x0c15,
table_address: 0x000e92f0,
structure_count: 0x0052,
bcd_revision: 27,
};
assert!(!s.is_valid());
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment