Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

remove #[derive(Default)] in bitflags data structure #89

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion spdmlib/src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1445,14 +1445,19 @@ impl Default for ManagedBuffer12Sign {
}

bitflags! {
#[derive(Default)]
pub struct SpdmMeasurementContentChanged: u8 {
const NOT_SUPPORTED = 0b0000_0000;
const DETECTED_CHANGE = 0b0001_0000;
const NO_CHANGE = 0b0010_0000;
}
}

impl Default for SpdmMeasurementContentChanged {
fn default() -> Self {
Self::NOT_SUPPORTED
}
}

#[derive(Debug, Clone, Default)]
#[cfg(not(feature = "hashed-transcript-data"))]
pub struct SpdmRuntimeInfo {
Expand Down
9 changes: 8 additions & 1 deletion spdmlib/src/common/opaque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,13 +656,20 @@ impl SpdmOpaqueStruct {
}

bitflags! {
#[derive(Default)]
pub struct SpdmOpaqueSupport: u8 {
const OPAQUE_DATA_FMT_DISABLED = 0b0000_0000;
const OPAQUE_DATA_FMT0 = 0b0000_0000;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be 1.

const OPAQUE_DATA_FMT1 = 0b0000_0010;
const VALID_MASK = Self::OPAQUE_DATA_FMT1.bits;
}
}

impl Default for SpdmOpaqueSupport {
fn default() -> Self {
Self::OPAQUE_DATA_FMT_DISABLED
}
}

impl Codec for SpdmOpaqueSupport {
fn encode(&self, bytes: &mut Writer) -> Result<usize, codec::EncodeErr> {
self.bits().encode(bytes)
Expand Down
4 changes: 2 additions & 2 deletions spdmlib/src/message/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl SpdmCodec for SpdmNegotiateAlgorithmsRequestPayload {
SpdmOpaqueSupport::read(r)?
} else {
u8::read(r)?;
SpdmOpaqueSupport::default()
SpdmOpaqueSupport::empty()
};

let base_asym_algo = SpdmBaseAsymAlgo::read(r)?;
Expand Down Expand Up @@ -322,7 +322,7 @@ impl SpdmCodec for SpdmAlgorithmsResponsePayload {
SpdmOpaqueSupport::read(r)?
} else {
u8::read(r)?;
SpdmOpaqueSupport::default()
SpdmOpaqueSupport::empty()
};
if !other_params_selection.is_no_more_than_one_selected() {
return None;
Expand Down
2 changes: 1 addition & 1 deletion spdmlib/src/message/capability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl SpdmCodec for SpdmGetCapabilitiesRequestPayload {
u8::read(r)?; // param2

let mut ct_exponent = 0;
let mut flags = SpdmRequestCapabilityFlags::default();
let mut flags = SpdmRequestCapabilityFlags::empty();
if context.negotiate_info.spdm_version_sel >= SpdmVersion::SpdmVersion11 {
u8::read(r)?; // reserved
ct_exponent = u8::read(r)?;
Expand Down
8 changes: 7 additions & 1 deletion spdmlib/src/message/challenge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,18 @@ impl SpdmCodec for SpdmChallengeRequestPayload {
}

bitflags! {
#[derive(Default)]
pub struct SpdmChallengeAuthAttribute: u8 {
const BASIC_MUT_AUTH_DISABLED = 0b0000_0000;
const BASIC_MUT_AUTH_REQ = 0b10000000;
}
}

impl Default for SpdmChallengeAuthAttribute {
fn default() -> Self {
Self::BASIC_MUT_AUTH_DISABLED
}
}

#[derive(Debug, Clone, Default)]
pub struct SpdmChallengeAuthResponsePayload {
pub slot_id: u8,
Expand Down
7 changes: 6 additions & 1 deletion spdmlib/src/message/end_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ use crate::{common, error::SpdmStatus};
use codec::{Codec, Reader, Writer};

bitflags! {
#[derive(Default)]
pub struct SpdmEndSessionRequestAttributes: u8 {
const PRESERVE_NEGOTIATED_STATE = 0b00000001;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 should be supported.

}
}

impl Default for SpdmEndSessionRequestAttributes {
fn default() -> Self {
Self::PRESERVE_NEGOTIATED_STATE
}
}

impl Codec for SpdmEndSessionRequestAttributes {
fn encode(&self, bytes: &mut Writer) -> Result<usize, codec::EncodeErr> {
self.bits().encode(bytes)
Expand Down
7 changes: 6 additions & 1 deletion spdmlib/src/message/finish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@ use crate::protocol::{
use codec::{Codec, Reader, Writer};

bitflags! {
#[derive(Default)]
pub struct SpdmFinishRequestAttributes: u8 {
const SIGNATURE_INCLUDED = 0b00000001;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 should be supported

}
}

impl Default for SpdmFinishRequestAttributes {
fn default() -> Self {
Self::SIGNATURE_INCLUDED
}
}

impl Codec for SpdmFinishRequestAttributes {
fn encode(&self, bytes: &mut Writer) -> Result<usize, codec::EncodeErr> {
self.bits().encode(bytes)
Expand Down
8 changes: 7 additions & 1 deletion spdmlib/src/message/key_exchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,20 @@ impl SpdmCodec for SpdmKeyExchangeRequestPayload {
}

bitflags! {
#[derive(Default)]
pub struct SpdmKeyExchangeMutAuthAttributes: u8 {
const MUT_AUTH_DISABLED = 0b00000000;
const MUT_AUTH_REQ = 0b00000001;
const MUT_AUTH_REQ_WITH_ENCAP_REQUEST = 0b00000010;
const MUT_AUTH_REQ_WITH_GET_DIGESTS = 0b00000100;
}
}

impl Default for SpdmKeyExchangeMutAuthAttributes {
fn default() -> Self {
Self::MUT_AUTH_DISABLED
}
}

impl Codec for SpdmKeyExchangeMutAuthAttributes {
fn encode(&self, bytes: &mut Writer) -> Result<usize, codec::EncodeErr> {
self.bits().encode(bytes)
Expand Down
7 changes: 6 additions & 1 deletion spdmlib/src/message/measurement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ pub const MEASUREMENT_RESPONDER_PARAM2_SLOT_ID_MASK: u8 = 0b0000_1111;
pub const MEASUREMENT_RESPONDER_PARAM2_CONTENT_CHANGED_MASK: u8 = 0b0011_0000;

bitflags! {
#[derive(Default)]
pub struct SpdmMeasurementAttributes: u8 {
const SIGNATURE_REQUESTED = 0b00000001;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 should be supported.

const RAW_BIT_STREAM_REQUESTED = 0b0000_0010;
}
}

impl Default for SpdmMeasurementAttributes {
fn default() -> Self {
Self::SIGNATURE_REQUESTED
}
}

impl Codec for SpdmMeasurementAttributes {
fn encode(&self, bytes: &mut Writer) -> Result<usize, codec::EncodeErr> {
self.bits().encode(bytes)
Expand Down
56 changes: 48 additions & 8 deletions spdmlib/src/protocol/algo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,18 @@ pub const SPDM_MAX_AEAD_IV_SIZE: usize = 12;
pub const SPDM_MAX_HKDF_OKM_SIZE: usize = SPDM_MAX_HASH_SIZE;

bitflags! {
#[derive(Default)]
pub struct SpdmMeasurementSpecification: u8 {
const DMTF = 0b0000_0001;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 is supported.

const VALID_MASK = Self::DMTF.bits;
}
}

impl Default for SpdmMeasurementSpecification {
fn default() -> Self {
Self::DMTF
}
}

impl Codec for SpdmMeasurementSpecification {
fn encode(&self, bytes: &mut Writer) -> Result<usize, codec::EncodeErr> {
self.bits().encode(bytes)
Expand Down Expand Up @@ -103,7 +108,6 @@ impl SpdmMeasurementSpecification {
}

bitflags! {
#[derive(Default)]
pub struct SpdmMeasurementHashAlgo: u32 {
const RAW_BIT_STREAM = 0b0000_0001;
const TPM_ALG_SHA_256 = 0b0000_0010;
Expand All @@ -124,6 +128,12 @@ bitflags! {
}
}

impl Default for SpdmMeasurementHashAlgo {
fn default() -> Self {
Self::TPM_ALG_SHA_384
}
}

impl SpdmMeasurementHashAlgo {
pub fn get_size(&self) -> u16 {
match *self {
Expand Down Expand Up @@ -168,7 +178,6 @@ impl Codec for SpdmMeasurementHashAlgo {
}

bitflags! {
#[derive(Default)]
pub struct SpdmBaseAsymAlgo: u32 {
const TPM_ALG_RSASSA_2048 = 0b0000_0001;
const TPM_ALG_RSAPSS_2048 = 0b0000_0010;
Expand All @@ -189,6 +198,12 @@ bitflags! {
}
}

impl Default for SpdmBaseAsymAlgo {
fn default() -> Self {
Self::TPM_ALG_ECDSA_ECC_NIST_P384
}
}

impl SpdmBaseAsymAlgo {
pub fn prioritize(&mut self, peer: SpdmBaseAsymAlgo) {
let prio_table = [
Expand Down Expand Up @@ -255,7 +270,6 @@ impl Codec for SpdmBaseAsymAlgo {
}

bitflags! {
#[derive(Default)]
pub struct SpdmBaseHashAlgo: u32 {
const TPM_ALG_SHA_256 = 0b0000_0001;
const TPM_ALG_SHA_384 = 0b0000_0010;
Expand All @@ -266,6 +280,12 @@ bitflags! {
}
}

impl Default for SpdmBaseHashAlgo {
fn default() -> Self {
Self::TPM_ALG_SHA_256
}
}

impl SpdmBaseHashAlgo {
pub fn prioritize(&mut self, peer: SpdmBaseHashAlgo) {
let prio_table = [
Expand Down Expand Up @@ -338,7 +358,6 @@ enum_builder! {
}

bitflags! {
#[derive(Default)]
pub struct SpdmDheAlgo: u16 {
const SECP_256_R1 = 0b0000_1000;
const SECP_384_R1 = 0b0001_0000;
Expand All @@ -347,6 +366,12 @@ bitflags! {
}
}

impl Default for SpdmDheAlgo {
fn default() -> Self {
Self::SECP_384_R1
}
}

impl SpdmDheAlgo {
pub fn prioritize(&mut self, peer: SpdmDheAlgo) {
let prio_table = [SpdmDheAlgo::SECP_384_R1, SpdmDheAlgo::SECP_256_R1];
Expand Down Expand Up @@ -398,7 +423,6 @@ impl Codec for SpdmDheAlgo {
}

bitflags! {
#[derive(Default)]
pub struct SpdmAeadAlgo: u16 {
const AES_128_GCM = 0b0000_0001;
const AES_256_GCM = 0b0000_0010;
Expand All @@ -409,6 +433,12 @@ bitflags! {
}
}

impl Default for SpdmAeadAlgo {
fn default() -> Self {
Self::AES_256_GCM
}
}

impl SpdmAeadAlgo {
pub fn prioritize(&mut self, peer: SpdmAeadAlgo) {
let prio_table = [
Expand Down Expand Up @@ -485,7 +515,6 @@ impl Codec for SpdmAeadAlgo {
}

bitflags! {
#[derive(Default)]
pub struct SpdmReqAsymAlgo: u16 {
const TPM_ALG_RSASSA_2048 = 0b0000_0001;
const TPM_ALG_RSAPSS_2048 = 0b0000_0010;
Expand All @@ -506,6 +535,12 @@ bitflags! {
}
}

impl Default for SpdmReqAsymAlgo {
fn default() -> Self {
Self::TPM_ALG_ECDSA_ECC_NIST_P384
}
}

impl SpdmReqAsymAlgo {
pub fn prioritize(&mut self, peer: SpdmReqAsymAlgo) {
let prio_table = [
Expand Down Expand Up @@ -572,13 +607,18 @@ impl Codec for SpdmReqAsymAlgo {
}

bitflags! {
#[derive(Default)]
pub struct SpdmKeyScheduleAlgo: u16 {
const SPDM_KEY_SCHEDULE = 0b0000_0001;
const VALID_MASK = Self::SPDM_KEY_SCHEDULE.bits;
}
}

impl Default for SpdmKeyScheduleAlgo {
fn default() -> Self {
Self::SPDM_KEY_SCHEDULE
}
}

impl SpdmKeyScheduleAlgo {
pub fn prioritize(&mut self, peer: SpdmKeyScheduleAlgo) {
let prio_table = [SpdmKeyScheduleAlgo::SPDM_KEY_SCHEDULE];
Expand Down
14 changes: 12 additions & 2 deletions spdmlib/src/protocol/capability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use codec::{Codec, Reader, Writer};

bitflags! {
#[derive(Default)]
pub struct SpdmRequestCapabilityFlags: u32 {
const CERT_CAP = 0b0000_0010;
const CHAL_CAP = 0b0000_0100;
Expand Down Expand Up @@ -38,6 +37,12 @@ bitflags! {
}
}

impl Default for SpdmRequestCapabilityFlags {
fn default() -> Self {
Self::VALID_MASK
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think MASK should be default.

}
}

impl Codec for SpdmRequestCapabilityFlags {
fn encode(&self, bytes: &mut Writer) -> Result<usize, codec::EncodeErr> {
self.bits().encode(bytes)
Expand All @@ -51,7 +56,6 @@ impl Codec for SpdmRequestCapabilityFlags {
}

bitflags! {
#[derive(Default)]
pub struct SpdmResponseCapabilityFlags: u32 {
const CACHE_CAP = 0b0000_0001;
const CERT_CAP = 0b0000_0010;
Expand Down Expand Up @@ -100,6 +104,12 @@ bitflags! {
}
}

impl Default for SpdmResponseCapabilityFlags {
fn default() -> Self {
Self::VALID_MASK
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think MASK should be default.

}
}

impl Codec for SpdmResponseCapabilityFlags {
fn encode(&self, bytes: &mut Writer) -> Result<usize, codec::EncodeErr> {
self.bits().encode(bytes)
Expand Down