feat: add sync TFTP client/server library

This commit is contained in:
2025-12-21 11:36:07 +01:00
parent 890443fdc2
commit 9ebfdb8cb2
6 changed files with 1206 additions and 12 deletions

View File

@@ -294,8 +294,15 @@ impl fmt::Display for DecodeError {
Self::UnknownMode(mode) => write!(f, "unknown transfer mode {mode:?}"),
Self::UnknownErrorCode(code) => write!(f, "unknown error code {code}"),
Self::OversizeData(n) => write!(f, "DATA payload too large ({n} bytes)"),
Self::InvalidLength { kind, expected, got } => {
write!(f, "{kind} packet has invalid length (expected {expected}, got {got})")
Self::InvalidLength {
kind,
expected,
got,
} => {
write!(
f,
"{kind} packet has invalid length (expected {expected}, got {got})"
)
}
Self::TrailingBytes => write!(f, "trailing bytes after packet"),
}
@@ -339,7 +346,10 @@ mod tests {
Packet::Ack { block: 1 }.encode_into(&mut bytes);
bytes.push(0);
let err = Packet::decode(&bytes).unwrap_err();
assert!(matches!(err, DecodeError::InvalidLength { kind: "ACK", .. }));
assert!(matches!(
err,
DecodeError::InvalidLength { kind: "ACK", .. }
));
}
#[allow(clippy::unwrap_used)]