Re: [PATCH 18/18] lib: rspdm: Support SPDM challenge

From: Dirk Behme

Date: Sun May 17 2026 - 04:10:13 EST


On 08.05.26 05:17, alistair23@xxxxxxxxx wrote:
> From: Alistair Francis <alistair@xxxxxxxxxxxxx>
>
> Support the CHALLENGE SPDM command.
>
> Signed-off-by: Alistair Francis <alistair@xxxxxxxxxxxxx>
> ---
...
> +impl Validate<&mut Unvalidated<KVec<u8>>> for &mut ChallengeRsp {
> + type Err = Error;
> +
> + fn validate(unvalidated: &mut Unvalidated<KVec<u8>>) -> Result<Self, Self::Err> {
> + let raw = unvalidated.raw_mut();
> + if raw.len() < mem::size_of::<ChallengeRsp>() {
> + return Err(EINVAL);
> + }
> +
> + let ptr = raw.as_mut_ptr();
> + // CAST: `ChallengeRsp` only contains integers and has `repr(C)`.
> + let ptr = ptr.cast::<ChallengeRsp>();
> + // SAFETY: `ptr` came from a reference and the cast above is valid.
> + let rsp: &mut ChallengeRsp = unsafe { &mut *ptr };
> +
> + Ok(rsp)
> + }
> +}

Just as reference, there is some discussion about this in

https://lore.kernel.org/rust-for-linux/2026051610-flint-compound-810f@gregkh/

Dirk