Files
s390-tools/rust/pv_core/src/uvattest.rs
Steffen Eiden 4d57ff046d rust: Prepare Cargo.toml for crates.io
Renames pv crate to s390_pv and pv_core to s390_pv_core. pv was already
taken on crates.io.

Bump the versions of all crates to 0.10.0. From now on we follow Semver
compatibility rules when it comes to updates. patch-level updates will
not introduce any backwards incompatible changes. For now all crates in
this directory will have the same version number. A version update may,
therefore, not add any new things.

Library users in this repository still use the non prefixed names and
rename the crate in the Cargo.toml. Doc-tests have to use the new name
however.

Add some Cargo metadata to the Cargo.toml.

Acked-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:53:57 +02:00

62 lines
1.5 KiB
Rust

// SPDX-License-Identifier: MIT
//
// Copyright IBM Corp. 2024
use crate::{request::MagicValue, Error};
use byteorder::{BigEndian, ByteOrder};
use zerocopy::U32;
/// The magic value used to identify an attestation request
///
/// The magic value is ASCII:
/// ```rust
/// # use s390_pv_core::attest::AttestationMagic;
/// # use s390_pv_core::request::MagicValue;
/// # fn main() {
/// # let magic = &
/// [0u8; 8]
/// # ;
/// # assert!(AttestationMagic::starts_with_magic(magic));
/// # }
/// ```
#[derive(Debug)]
pub struct AttestationMagic;
impl MagicValue<8> for AttestationMagic {
const MAGIC: [u8; 8] = [0; 8];
}
/// Identifier for the used measurement algorithm
#[repr(u32)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AttestationMeasAlg {
/// Use HMAC with SHA512 as measurement algorithm
HmacSha512 = 1,
}
impl AttestationMeasAlg {
/// Report the expected size for a given measurement algorithm
pub const fn exp_size(&self) -> u32 {
match self {
AttestationMeasAlg::HmacSha512 => 64,
}
}
}
impl<E: ByteOrder> TryFrom<U32<E>> for AttestationMeasAlg {
type Error = Error;
fn try_from(value: U32<E>) -> Result<Self, Self::Error> {
if value.get() == AttestationMeasAlg::HmacSha512 as u32 {
Ok(Self::HmacSha512)
} else {
Err(Error::BinArcbInvAlgorithm(value.get()))
}
}
}
impl From<AttestationMeasAlg> for U32<BigEndian> {
fn from(value: AttestationMeasAlg) -> Self {
(value as u32).into()
}
}