[dice] Remove unnecessary trait dice::InputValues
Bug: 267575445
Test: atest diced_utils_test diced_sample_inputs_test \
diced_test diced_vendor_test diced_client_test \
diced_open_dice_cbor_test
Change-Id: I6db68622c3ce1f3de040f9872e69482e3e0b1153
diff --git a/diced/src/sample_inputs.rs b/diced/src/sample_inputs.rs
index 84c4781..0553327 100644
--- a/diced/src/sample_inputs.rs
+++ b/diced/src/sample_inputs.rs
@@ -21,8 +21,7 @@
use anyhow::{Context, Result};
use dice::ContextImpl;
use diced_open_dice_cbor as dice;
-use diced_utils::cbor;
-use diced_utils::InputValues;
+use diced_utils::{cbor, to_dice_input_values};
use keystore2_crypto::ZVec;
use std::convert::TryInto;
use std::io::Write;
@@ -82,7 +81,7 @@
let input_values_vector = get_input_values_vector();
let (cdi_attest, cdi_seal, mut cert) = dice_ctx
- .main_flow(UDS, UDS, &InputValues::from(&input_values_vector[0]))
+ .main_flow(UDS, UDS, &to_dice_input_values(&input_values_vector[0]))
.context("In make_sample_bcc_and_cdis: Trying to run first main flow.")?;
let mut bcc: Vec<u8> = vec![];
@@ -103,7 +102,7 @@
"In make_sample_bcc_and_cdis: Failed to convert cdi_seal to array reference. (1)",
)?,
&bcc,
- &InputValues::from(&input_values_vector[1]),
+ &to_dice_input_values(&input_values_vector[1]),
)
.context("In make_sample_bcc_and_cdis: Trying to run first bcc main flow.")?;
dice_ctx
@@ -115,7 +114,7 @@
"In make_sample_bcc_and_cdis: Failed to convert cdi_seal to array reference. (2)",
)?,
&bcc,
- &InputValues::from(&input_values_vector[2]),
+ &to_dice_input_values(&input_values_vector[2]),
)
.context("In make_sample_bcc_and_cdis: Trying to run second bcc main flow.")
}
diff --git a/diced/src/utils.rs b/diced/src/utils.rs
index 05702ad..3d35ae5 100644
--- a/diced/src/utils.rs
+++ b/diced/src/utils.rs
@@ -19,63 +19,32 @@
Mode::Mode as BinderMode,
};
use anyhow::{Context, Result};
-use dice::{ContextImpl, DiceMode, Hash, Hidden};
+use dice::{ContextImpl, DiceMode};
use diced_open_dice_cbor as dice;
use keystore2_crypto::ZVec;
use std::convert::TryInto;
-/// This new type wraps a reference to BinderInputValues and implements the open dice
-/// InputValues trait.
-#[derive(Debug)]
-pub struct InputValues<'a>(&'a BinderInputValues);
-
-impl<'a> From<&'a BinderInputValues> for InputValues<'a> {
- fn from(input_values: &'a BinderInputValues) -> InputValues<'a> {
- Self(input_values)
+/// Converts the `InputValues` from the binder to the `InputValues` type in `diced_open_dice` crate.
+pub fn to_dice_input_values(input: &BinderInputValues) -> dice::InputValues {
+ if input.authorityDescriptor.is_some() {
+ unimplemented!("Authority descriptor is not yet implemented in the current library.");
}
+ dice::InputValues::new(
+ input.codeHash,
+ dice::Config::Descriptor(input.config.desc.as_slice()),
+ input.authorityHash,
+ to_dice_mode(input.mode),
+ input.hidden,
+ )
}
-impl From<&InputValues<'_>> for BinderInputValues {
- fn from(input_values: &InputValues) -> BinderInputValues {
- input_values.0.clone()
- }
-}
-impl From<InputValues<'_>> for BinderInputValues {
- fn from(input_values: InputValues) -> BinderInputValues {
- input_values.0.clone()
- }
-}
-
-impl dice::InputValues for InputValues<'_> {
- fn code_hash(&self) -> &Hash {
- &self.0.codeHash
- }
-
- fn config(&self) -> dice::Config {
- dice::Config::Descriptor(self.0.config.desc.as_slice())
- }
-
- fn authority_hash(&self) -> &Hash {
- &self.0.authorityHash
- }
-
- fn authority_descriptor(&self) -> Option<&[u8]> {
- self.0.authorityDescriptor.as_deref()
- }
-
- fn mode(&self) -> DiceMode {
- match self.0.mode {
- BinderMode::NOT_INITIALIZED => DiceMode::kDiceModeNotInitialized,
- BinderMode::NORMAL => DiceMode::kDiceModeNormal,
- BinderMode::DEBUG => DiceMode::kDiceModeDebug,
- BinderMode::RECOVERY => DiceMode::kDiceModeMaintenance,
- _ => DiceMode::kDiceModeNotInitialized,
- }
- }
-
- fn hidden(&self) -> &Hidden {
- // If `self` was created using try_from the length was checked and this cannot panic.
- &self.0.hidden
+fn to_dice_mode(binder_mode: BinderMode) -> DiceMode {
+ match binder_mode {
+ BinderMode::NOT_INITIALIZED => DiceMode::kDiceModeNotInitialized,
+ BinderMode::NORMAL => DiceMode::kDiceModeNormal,
+ BinderMode::DEBUG => DiceMode::kDiceModeDebug,
+ BinderMode::RECOVERY => DiceMode::kDiceModeMaintenance,
+ _ => DiceMode::kDiceModeNotInitialized,
}
}
@@ -153,7 +122,7 @@
(cdi_attest, cdi_seal, bcc)
}
- fn execute_step(self, input_values: InputValues) -> Result<Self> {
+ fn execute_step(self, input_values: &BinderInputValues) -> Result<Self> {
let ResidentArtifacts { cdi_attest, cdi_seal, bcc } = self;
let (cdi_attest, cdi_seal, bcc) = dice::OpenDiceCborContext::new()
@@ -165,7 +134,7 @@
format!("Trying to convert cdi_seal. (length: {})", cdi_seal.len())
})?,
&bcc,
- &input_values,
+ &to_dice_input_values(input_values),
)
.context("In ResidentArtifacts::execute_step:")?;
Ok(ResidentArtifacts { cdi_attest, cdi_seal, bcc })
@@ -173,14 +142,13 @@
/// Iterate through the iterator of dice input values performing one
/// BCC main flow step on each element.
- pub fn execute_steps<'a, T, I>(self, input_values: I) -> Result<Self>
+ pub fn execute_steps<'a, I>(self, input_values: I) -> Result<Self>
where
- T: Into<InputValues<'a>>,
- I: IntoIterator<Item = T>,
+ I: IntoIterator<Item = &'a BinderInputValues>,
{
input_values
.into_iter()
- .try_fold(self, |acc, input| acc.execute_step(input.into()))
+ .try_fold(self, |acc, input| acc.execute_step(input))
.context("In ResidentArtifacts::execute_step:")
}
}