Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
redox-os
dmi
Commits
ef5ca540
Unverified
Commit
ef5ca540
authored
Apr 12, 2018
by
Jeremy Soller
Committed by
GitHub
Apr 12, 2018
Browse files
Merge pull request
#1
from jabedude/master
Fix TODO: calculate DMI table checksum in is_valid method
parents
0cb41837
df986494
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/lib.rs
View file @
ef5ca540
...
...
@@ -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
}
}
...
...
tests/tests.rs
0 → 100644
View file @
ef5ca540
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
());
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment