Skip to content

Commit c4c41b2

Browse files
committed
pldm: hash transferred data instead of accumulating
We don't do anything with the incoming file data, so just hash instead, and print out an info!() message with the transfer result. Signed-off-by: Jeremy Kerr <[email protected]>
1 parent 4acfe0a commit c4c41b2

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

Cargo.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ categories = ["network-programming", "hardware-support"]
99

1010
[features]
1111
nvme-mi = ["dep:nvme-mi-dev"]
12-
pldm = ["dep:pldm", "dep:pldm-file", "dep:pldm-platform"]
12+
pldm = ["dep:hex", "dep:pldm", "dep:pldm-file", "dep:pldm-platform", "dep:sha2"]
1313

1414
[dependencies]
1515
anyhow = "1.0.86"
@@ -22,6 +22,7 @@ embedded-io-adapters = { version = "0.6", features = [ "futures-03" ] }
2222
embedded-io-async = { version = "0.6" }
2323
futures = "0.3.31"
2424
futures-io = "0.3.30"
25+
hex = { version = "0.4.3", optional = true }
2526
log = "0.4.22"
2627
mctp = "0.2.0"
2728
mctp-estack = { git = "https://github.com/CodeConstruct/mctp-rs", rev = "851360ed19ef78f2e7672daa90900cb4f38ad0b6", package = "mctp-estack" }
@@ -30,6 +31,7 @@ polling = "3.7.4"
3031
pldm = { git = "https://github.com/CodeConstruct/mctp-rs", rev = "851360ed19ef78f2e7672daa90900cb4f38ad0b6", package = "pldm", optional = true }
3132
pldm-file = { git = "https://github.com/CodeConstruct/mctp-rs", rev = "851360ed19ef78f2e7672daa90900cb4f38ad0b6", package = "pldm-file", optional = true }
3233
pldm-platform = { git = "https://github.com/CodeConstruct/mctp-rs", rev = "851360ed19ef78f2e7672daa90900cb4f38ad0b6", package = "pldm-platform", optional = true }
34+
sha2 = {version = "0.10.9", optional = true }
3335
simplelog = "0.12.2"
3436
smol = "2.0.0"
3537
usbredirparser = { git = "https://github.com/CodeConstruct/usbredir-rs", branch = "main", package = "usbredirparser" }

src/pldm.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use anyhow::{bail, Context, Result};
44
use log::{debug, info, warn};
5+
use sha2::{Digest, Sha256};
56

67
use mctp_estack::{control::ControlEvent, router::Router};
78
use pldm::{control::requester::negotiate_transfer_parameters, PldmError};
@@ -63,28 +64,30 @@ async fn pldm_file(
6364

6465
debug!("Open: {fd:?}");
6566

66-
let mut buf = Vec::new();
67+
let mut hash = Sha256::new();
6768
let req_len = size;
69+
let mut cur_len = 0usize;
6870

6971
debug!("Reading...");
7072
let res = df_read_with(chan, fd, 0, req_len, |part| {
71-
debug!(
72-
" {} bytes, {}/{req_len}",
73-
part.len(),
74-
buf.len() + part.len()
75-
);
76-
if buf.len() + part.len() > req_len {
73+
cur_len += part.len();
74+
debug!(" {} bytes, {cur_len}/{req_len}", part.len());
75+
if cur_len > req_len {
7776
warn!(" data overflow!");
7877
Err(PldmError::NoSpace)
7978
} else {
80-
buf.extend_from_slice(part);
79+
hash.update(part);
8180
Ok(())
8281
}
8382
})
8483
.await;
8584

8685
debug!("Read: {res:?}");
8786

87+
let hex = hex::encode(hash.finalize());
88+
89+
info!("Transfer complete. {cur_len} bytes, sha256 {hex}");
90+
8891
let attrs = DfCloseAttributes::empty();
8992
let res = df_close(chan, fd, attrs).await;
9093

0 commit comments

Comments
 (0)