Skip to main content

tss_esapi/structures/buffers/
private.rs

1// Copyright 2023 Contributors to the Parsec project.
2// SPDX-License-Identifier: Apache-2.0
3
4use crate::traits::impl_mu_standard;
5use std::mem::size_of;
6use tss_esapi_sys::_PRIVATE;
7
8const TPM2B_PRIVATE_BUFFER_SIZE: usize = size_of::<_PRIVATE>();
9
10buffer_type!(Private, TPM2B_PRIVATE_BUFFER_SIZE, TPM2B_PRIVATE);
11
12impl_mu_standard!(Private, TPM2B_PRIVATE);
13
14cfg_if::cfg_if! {
15    if #[cfg(feature = "serde")] {
16        use crate::traits::{Marshall, UnMarshall};
17        impl serde::Serialize for Private {
18            /// Serialize the [Private] data into it's bytes representation of the TCG
19            /// TPM2B_PRIVATE structure.
20            fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
21            where
22                S: serde::Serializer,
23            {
24                let bytes = self.marshall().map_err(serde::ser::Error::custom)?;
25                serializer.serialize_bytes(&bytes)
26            }
27        }
28
29        impl<'de> serde::Deserialize<'de> for Private {
30            /// Deserialize the [Private] data from it's bytes representation of the TCG
31            /// TPM2B_PRIVATE structure.
32            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
33            where
34                D: serde::Deserializer<'de>,
35            {
36                let bytes = <Vec<u8>>::deserialize(deserializer)?;
37                Self::unmarshall(&bytes).map_err(serde::de::Error::custom)
38            }
39        }
40    }
41}