@@ -8,7 +8,7 @@ use crate::{
88 attributes:: ObjectAttributes ,
99 interface_types:: algorithm:: { HashingAlgorithm , PublicAlgorithm } ,
1010 structures:: { Digest , EccPoint , PublicKeyRsa , SymmetricCipherParameters } ,
11- traits:: { impl_mu_standard, Marshall } ,
11+ traits:: { impl_mu_standard, Marshall , UnMarshall } ,
1212 tss2_esys:: { TPM2B_PUBLIC , TPMT_PUBLIC } ,
1313 Error , Result , ReturnCode , WrapperErrorKind ,
1414} ;
@@ -18,6 +18,7 @@ use keyed_hash::PublicKeyedHashParameters;
1818use rsa:: PublicRsaParameters ;
1919
2020use log:: error;
21+ use serde:: { Deserialize , Deserializer , Serialize , Serializer } ;
2122use std:: convert:: { TryFrom , TryInto } ;
2223use tss_esapi_sys:: { TPMU_PUBLIC_ID , TPMU_PUBLIC_PARMS } ;
2324
@@ -493,6 +494,30 @@ impl TryFrom<TPMT_PUBLIC> for Public {
493494
494495impl_mu_standard ! ( Public , TPMT_PUBLIC ) ;
495496
497+ impl Serialize for Public {
498+ /// Serialise the [Public] data into it's bytes representation of the TCG
499+ /// TPMT_PUBLIC structure.
500+ fn serialize < S > ( & self , serializer : S ) -> std:: result:: Result < S :: Ok , S :: Error >
501+ where
502+ S : Serializer ,
503+ {
504+ let bytes = self . marshall ( ) . map_err ( serde:: ser:: Error :: custom) ?;
505+ serializer. serialize_bytes ( & bytes)
506+ }
507+ }
508+
509+ impl < ' de > Deserialize < ' de > for Public {
510+ /// Deserialise the [Public] data from it's bytes representation of the TCG
511+ /// TPMT_PUBLIC structure.
512+ fn deserialize < D > ( deserializer : D ) -> std:: result:: Result < Self , D :: Error >
513+ where
514+ D : Deserializer < ' de > ,
515+ {
516+ let bytes = <Vec < u8 > >:: deserialize ( deserializer) ?;
517+ Self :: unmarshall ( & bytes) . map_err ( serde:: de:: Error :: custom)
518+ }
519+ }
520+
496521impl TryFrom < TPM2B_PUBLIC > for Public {
497522 type Error = Error ;
498523
0 commit comments