pub fn new(
        tpml_pcr_selections: &TPML_PCR_SELECTION,
        tpml_digests: &TPML_DIGEST,
    ) -> Result<Self> {
        // Check digests
        let digests_count = tpml_digests.count as usize;
        if digests_count > 8 {
            error!("Error: Invalid TPML_DIGEST count(> 8)");
            return Err(Error::local_error(WrapperErrorKind::InvalidParam));
        }
        let digests = &tpml_digests.digests[..digests_count];
        // Check selections
        let selections_count = tpml_pcr_selections.count as usize;
        if selections_count > 16 {
            error!("Error: Invalid TPML_SELECTIONS count(> 16)");
            return Err(Error::local_error(WrapperErrorKind::InvalidParam));
        }
        let pcr_selections = &tpml_pcr_selections.pcrSelections[..selections_count];

        let mut digest_iter = digests.iter();
        let mut data = Vec::<(HashingAlgorithm, PcrBank)>::new();
        for &pcr_selection in pcr_selections {
            // Parse hash algorithm from selection
            let parsed_hash_algorithm =
                HashingAlgorithm::try_from(pcr_selection.hash).map_err(|e| {
                    error!("Error converting hash to a HashingAlgorithm: {}", e);
                    Error::local_error(WrapperErrorKind::InvalidParam)
                })?;
            // Parse pcr slots from selection
            let parsed_pcr_slots: BitFlags<PcrSlot> =
                BitFlags::<PcrSlot>::try_from(u32::from_le_bytes(pcr_selection.pcrSelect))
                    .map_err(|e| {
                        error!("Error parsing pcrSelect to a BitFlags<PcrSlot>: {}", e);
                        Error::local_error(WrapperErrorKind::UnsupportedParam)
                    })?;
            // Create PCR bank by mapping the pcr slots to the pcr values
            let mut parsed_pcr_bank = PcrBank {
                bank: Default::default(),
            };
            for pcr_slot in parsed_pcr_slots.iter() {
                // Make sure there are still data
                let digest = match digest_iter.next() {
                    Some(val) => val,
                    None => {
                        error!("Error number of items in selection does not match number of items in data");
                        return Err(Error::local_error(WrapperErrorKind::InconsistentParams));
                    }
                };
                // Add the value corresponding to the pcr slot.
                if parsed_pcr_bank
                    .bank
                    .insert(pcr_slot, PcrValue::try_from(*digest)?)
                    .is_some()
                {
                    error!("Error trying to insert data into PcrSlot where data have already been inserted");
                    return Err(Error::local_error(WrapperErrorKind::InconsistentParams));
                }
            }
            data.push((parsed_hash_algorithm, parsed_pcr_bank));
        }
        // Make sure all values in the digest have been read.
        if digest_iter.next().is_some() {
            error!("Error not all values in the digest have been handled");
            return Err(Error::local_error(WrapperErrorKind::InconsistentParams));
        }

        Ok(PcrData { data })
    }
/// Contrustctor that creates a PcrData from
/// tss types.
Contrustctor that creates a PcrData from
tss types.
Contrustctor that creates a PcrData from tss types .
pub fn new(
        tpml_pcr_selections: &TPML_PCR_SELECTION,
        tpml_digests: &TPML_DIGEST,
    ) -> Result<Self> {
        // Check digests
        let digests_count = tpml_digests.count as usize;
        if digests_count > 8 {
            error!("Error: Invalid TPML_DIGEST count(> 8)");
            return Err(Error::local_error(WrapperErrorKind::InvalidParam));
        }
        let digests = &tpml_digests.digests[..digests_count];
        // Check selections
        let selections_count = tpml_pcr_selections.count as usize;
        if selections_count > 16 {
            error!("Error: Invalid TPML_SELECTIONS count(> 16)");
            return Err(Error::local_error(WrapperErrorKind::InvalidParam));
        }
        let pcr_selections = &tpml_pcr_selections.pcrSelections[..selections_count];
        let mut digest_iter = digests.iter();
        let mut data = Vec::<(HashingAlgorithm, PcrBank)>::new();
        for &pcr_selection in pcr_selections {
            // Parse hash algorithm from selection
            let parsed_hash_algorithm =
                HashingAlgorithm::try_from(pcr_selection.hash).map_err(|e| {
                    error!("Error converting hash to a HashingAlgorithm: {}", e);
                    Error::local_error(WrapperErrorKind::InvalidParam)
                })?;
            // Parse pcr slots from selection
            let parsed_pcr_slots: BitFlags<PcrSlot> =
                BitFlags::<PcrSlot>::try_from(u32::from_le_bytes(pcr_selection.pcrSelect))
                    .map_err(|e| {
                        error!("Error parsing pcrSelect to a BitFlags<PcrSlot>: {}", e);
                        Error::local_error(WrapperErrorKind::UnsupportedParam)
                    })?;
            // Create PCR bank by mapping the pcr slots to the pcr values
            let mut parsed_pcr_bank = PcrBank {
                bank: Default::default(),
            };
            for pcr_slot in parsed_pcr_slots.iter() {
                // Make sure there are still data
                let digest = match digest_iter.next() {
                    Some(val) => val,
                    None => {
                        error!("Error number of items in selection does not match number of items in data");
                        return Err(Error::local_error(WrapperErrorKind::InconsistentParams));
                    }
                };
                // Add the value corresponding to the pcr slot.
                if parsed_pcr_bank
                    .bank
                    .insert(pcr_slot, PcrValue::try_from(*digest)?)
                    .is_some()
                {
                    error!("Error trying to insert data into PcrSlot where data have already been inserted");
                    return Err(Error::local_error(WrapperErrorKind::InconsistentParams));
                }
            }
            data.push((parsed_hash_algorithm, parsed_pcr_bank));
        }
        // Make sure all values in the digest have been read.
        if digest_iter.next().is_some() {
            error!("Error not all values in the digest have been handled");
            return Err(Error::local_error(WrapperErrorKind::InconsistentParams));
        }
        Ok(PcrData { data })
    }
pub fn new ( tpml_pcr_selections : & TPML_PCR_SELECTION , tpml_digests : & TPML_DIGEST , ) -> Result < Self > { // Check digests let digests_count = tpml_digests . count as usize ; if digests_count > 8 { error ! ( " " ) ; return Err ( Error :: local_error ( WrapperErrorKind :: InvalidParam ) ) ; } let digests = & tpml_digests . digests [ .. digests_count ] ; // Check selections let selections_count = tpml_pcr_selections . count as usize ; if selections_count > 16 { error ! ( " " ) ; return Err ( Error :: local_error ( WrapperErrorKind :: InvalidParam ) ) ; } let pcr_selections = & tpml_pcr_selections . pcrSelections [ .. selections_count ] ; let mut digest_iter = digests . iter ( ) ; let mut data = Vec :: < ( HashingAlgorithm , PcrBank ) > :: new ( ) ; for & pcr_selection in pcr_selections { // Parse hash algorithm from selection let parsed_hash_algorithm = HashingAlgorithm :: try_from ( pcr_selection . hash ) . map_err ( | e | { error ! ( " " e ) ; Error :: local_error ( WrapperErrorKind :: InvalidParam ) } ) ? ; // Parse pcr slots from selection let parsed_pcr_slots : BitFlags < PcrSlot > = BitFlags :: < PcrSlot > :: try_from ( u32 :: from_le_bytes ( pcr_selection . pcrSelect ) ) . map_err ( | e | { error ! ( " " e ) ; Error :: local_error ( WrapperErrorKind :: UnsupportedParam ) } ) ? ; // Create PCR bank by mapping the pcr slots to the pcr values let mut parsed_pcr_bank = PcrBank { bank : Default :: default ( ) , } ; for pcr_slot in parsed_pcr_slots . iter ( ) { // Make sure there are still data let digest = match digest_iter . next ( ) { Some ( val ) => val , None => { error ! ( " " ) ; return Err ( Error :: local_error ( WrapperErrorKind :: InconsistentParams ) ) ; } } ; // Add the value corresponding to the pcr slot. if parsed_pcr_bank . bank . insert ( pcr_slot , PcrValue :: try_from ( * digest ) ? ) . is_some ( ) { error ! ( " " ) ; return Err ( Error :: local_error ( WrapperErrorKind :: InconsistentParams ) ) ; } } data . push ( ( parsed_hash_algorithm , parsed_pcr_bank ) ) ; } // Make sure all values in the digest have been read. if digest_iter . next ( ) . is_some ( ) { error ! ( " " ) ; return Err ( Error :: local_error ( WrapperErrorKind :: InconsistentParams ) ) ; } Ok ( PcrData { data } ) }
Contrustctor that creates a PcrData from
tss types.
Contrustctor that creates a PcrData from tss types .
tpml_pcr_selections
&TPML_PCR_SELECTION
tpml_digests
&TPML_DIGEST
tpml_pcr_selections
&TPML_PCR_SELECTION
tpml_digests
&TPML_DIGEST