Skip to content

Commit

Permalink
Add Deserialize for Quote3<Vec<u8>> (#379)
Browse files Browse the repository at this point in the history
Previously `Deserialize` was only implemented for `Quote3<&[u8]>`. Now
it's also implemented for the `Quote3<Vec<u8>>` type.

### Motivation

The main
[MobileCoin](https://github.com/mobilecoinfoundation/mobilecoin) repo
passes quotes into and out of the enclave. This requires the owned
`Quote3<Vec<u8>>` version to be serializable as well as the borrowed
`Quote<&[u8]>` version.
  • Loading branch information
nick-mobilecoin authored Jul 27, 2023
2 parents 62912f6 + f3be30c commit bbb7534
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ USER $USERNAME
RUN wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | zsh || true

# Install rust
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y

RUN echo "[ -f /opt/intel/sgxsdk/environment ] && . /opt/intel/sgxsdk/environment" >> ~/.zshenv
25 changes: 25 additions & 0 deletions dcap/types/src/quote3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,18 @@ impl<'de> Deserialize<'de> for Quote3<&'de [u8]> {
}
}

#[cfg(feature = "alloc")]
impl<'de> Deserialize<'de> for Quote3<Vec<u8>> {
fn deserialize<D>(deserializer: D) -> core::result::Result<Self, D::Error>
where
D: Deserializer<'de>,
{
deserializer
.deserialize_bytes(Quote3Visitor)
.map(|q| q.into())
}
}

/// Signature Data
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct SignatureData<'a> {
Expand Down Expand Up @@ -1144,4 +1156,17 @@ mod test {

assert_eq!(quote, new_quote);
}

#[cfg(feature = "alloc")]
#[test]
fn quote_vec_version_can_be_serialized_and_deserialized() {
let hw_quote = include_bytes!("../data/tests/hw_quote.dat").to_vec();
let quote = Quote3::try_from(hw_quote).expect("Failed to parse quote");

let bytes = serde_cbor::to_vec(&quote).expect("Failed to serialize quote");
let new_quote: Quote3<Vec<u8>> =
serde_cbor::from_slice(&bytes).expect("Failed to deserialize qutoe");

assert_eq!(quote, new_quote);
}
}

0 comments on commit bbb7534

Please sign in to comment.