@@ -113,9 +113,8 @@ pub enum Error {
113113 } ,
114114 /// Failed to decode some hex
115115 CouldNotDecodeHex ( qos_hex:: HexError ) ,
116- /// Failed to deserialize something from borsh.
117- #[ allow( clippy:: enum_variant_names) ]
118- BorshError ,
116+ /// Failed to deserialize something from borsh or json
117+ Deserialize ,
119118 FailedToReadDrKey ( qos_p256:: P256Error ) ,
120119 QosAttest ( String ) ,
121120 /// Pivot file
@@ -141,9 +140,15 @@ pub enum Error {
141140 SecretDoesNotMatch ,
142141}
143142
143+ impl From < serde_json:: Error > for Error {
144+ fn from ( _: serde_json:: Error ) -> Self {
145+ Self :: Deserialize
146+ }
147+ }
148+
144149impl From < borsh:: io:: Error > for Error {
145150 fn from ( _: borsh:: io:: Error ) -> Self {
146- Self :: BorshError
151+ Self :: Deserialize
147152 }
148153}
149154
@@ -759,7 +764,7 @@ pub(crate) fn generate_manifest<P: AsRef<Path>>(
759764
760765 write_with_msg (
761766 manifest_path. as_ref ( ) ,
762- & borsh :: to_vec ( & manifest) . unwrap ( ) ,
767+ & serde_json :: to_vec ( & manifest) . expect ( "failed to serialize manifest" ) ,
763768 "Manifest" ,
764769 ) ;
765770
@@ -862,7 +867,7 @@ pub(crate) fn approve_manifest<P: AsRef<Path>>(
862867 ) ) ;
863868 write_with_msg (
864869 & approval_path,
865- & borsh :: to_vec ( & approval) . expect ( "Failed to serialize approval" ) ,
870+ & serde_json :: to_vec ( & approval) . expect ( "Failed to serialize approval" ) ,
866871 "Manifest Approval" ,
867872 ) ;
868873
@@ -1010,7 +1015,7 @@ pub(crate) fn generate_manifest_envelope<P: AsRef<Path>>(
10101015 ) ;
10111016 write_with_msg (
10121017 & path,
1013- & borsh :: to_vec ( & manifest_envelope)
1018+ & serde_json :: to_vec ( & manifest_envelope)
10141019 . expect ( "Failed to serialize manifest envelope" ) ,
10151020 "Manifest Envelope" ,
10161021 ) ;
@@ -1076,7 +1081,7 @@ pub(crate) fn export_key<P: AsRef<Path>>(
10761081
10771082 write_with_msg (
10781083 encrypted_quorum_key_path. as_ref ( ) ,
1079- & borsh :: to_vec ( & encrypted_quorum_key) . expect ( "valid borsh. qed." ) ,
1084+ & serde_json :: to_vec ( & encrypted_quorum_key) . expect ( "valid borsh. qed." ) ,
10801085 "Encrypted Quorum Key" ,
10811086 ) ;
10821087
@@ -1087,10 +1092,10 @@ pub(crate) fn inject_key<P: AsRef<Path>>(
10871092 uri : & str ,
10881093 encrypted_quorum_key_path : P ,
10891094) -> Result < ( ) , Error > {
1090- let encrypted_quorum_key = {
1095+ let encrypted_quorum_key: EncryptedQuorumKey = {
10911096 let bytes = std:: fs:: read ( encrypted_quorum_key_path)
10921097 . map_err ( |_| Error :: FailedToReadEncryptedQuorumKey ) ?;
1093- EncryptedQuorumKey :: try_from_slice ( & bytes)
1098+ serde_json :: from_slice ( & bytes)
10941099 . map_err ( |_| Error :: InvalidEncryptedQuorumKey ) ?
10951100 } ;
10961101
@@ -1201,8 +1206,8 @@ pub(crate) fn get_attestation_doc<P: AsRef<Path>>(
12011206 ) ;
12021207 write_with_msg (
12031208 manifest_envelope_path. as_ref ( ) ,
1204- & borsh :: to_vec ( & manifest_envelope)
1205- . expect ( "manifest enevelope is valid borsh " ) ,
1209+ & serde_json :: to_vec ( & manifest_envelope)
1210+ . expect ( "manifest enevelope is valid json " ) ,
12061211 "Manifest envelope" ,
12071212 ) ;
12081213}
@@ -1313,7 +1318,7 @@ pub(crate) fn proxy_re_encrypt_share<P: AsRef<Path>>(
13131318 eph_pub. encrypt ( plaintext_share) . expect ( "Envelope encryption error" )
13141319 } ;
13151320
1316- let approval = borsh :: to_vec ( & Approval {
1321+ let approval = serde_json :: to_vec ( & Approval {
13171322 signature : pair
13181323 . sign ( & manifest_envelope. manifest . qos_hash ( ) )
13191324 . expect ( "Failed to sign" ) ,
@@ -1573,26 +1578,28 @@ pub(crate) fn display<P: AsRef<Path>>(
15731578 file_path : P ,
15741579 json : bool ,
15751580) -> Result < ( ) , Error > {
1576- let bytes =
1577- fs:: read ( file_path) . map_err ( |e| Error :: ReadShare ( e. to_string ( ) ) ) ?;
15781581 match * display_type {
15791582 DisplayType :: Manifest => {
1580- let decoded = Manifest :: try_from_slice_compat ( & bytes) ?;
1583+ let decoded = read_manifest ( file_path) ?;
1584+
15811585 if json {
15821586 println ! ( "{}" , serde_json:: to_string( & decoded) . unwrap( ) ) ;
15831587 } else {
15841588 println ! ( "{decoded:#?}" ) ;
15851589 }
15861590 }
15871591 DisplayType :: ManifestEnvelope => {
1588- let decoded = ManifestEnvelope :: try_from_slice ( & bytes) ?;
1592+ let decoded = read_manifest_envelope ( file_path) ?;
1593+
15891594 if json {
15901595 println ! ( "{}" , serde_json:: to_string( & decoded) . unwrap( ) ) ;
15911596 } else {
15921597 println ! ( "{decoded:#?}" ) ;
15931598 }
15941599 }
15951600 DisplayType :: GenesisOutput => {
1601+ let bytes = fs:: read ( file_path)
1602+ . map_err ( |e| Error :: ReadShare ( e. to_string ( ) ) ) ?;
15961603 let decoded = GenesisOutput :: try_from_slice ( & bytes) ?;
15971604 println ! ( "{decoded:#?}" ) ;
15981605 }
@@ -1952,7 +1959,7 @@ fn find_approvals<P: AsRef<Path>>(
19521959 return None ;
19531960 } ;
19541961
1955- let approval = Approval :: try_from_slice (
1962+ let approval: Approval = serde_json :: from_slice (
19561963 & fs:: read ( path) . expect ( "Failed to read in approval" ) ,
19571964 )
19581965 . expect ( "Failed to deserialize approval" ) ;
@@ -1981,9 +1988,16 @@ fn find_approvals<P: AsRef<Path>>(
19811988}
19821989
19831990fn read_manifest < P : AsRef < Path > > ( file : P ) -> Result < Manifest , Error > {
1984- let buf = fs:: read ( file) . map_err ( Error :: FailedToReadManifestFile ) ?;
1985- Manifest :: try_from_slice ( & buf)
1986- . map_err ( |_| Error :: FileDidNotHaveValidManifest )
1991+ let bytes = fs:: read ( file) . map_err ( Error :: FailedToReadManifestFile ) ?;
1992+
1993+ // try getting Manifest from json
1994+ let result = serde_json:: from_slice :: < Manifest > ( & bytes) ;
1995+ if result. is_err ( ) {
1996+ // if not try the old borsh format
1997+ Manifest :: try_from_slice_compat ( & bytes) . map_err ( Error :: from)
1998+ } else {
1999+ result. map_err ( Error :: from)
2000+ }
19872001}
19882002
19892003fn read_attestation_doc < P : AsRef < Path > > (
@@ -2003,10 +2017,16 @@ fn read_attestation_doc<P: AsRef<Path>>(
20032017fn read_manifest_envelope < P : AsRef < Path > > (
20042018 file : P ,
20052019) -> Result < ManifestEnvelope , Error > {
2006- let buf =
2007- fs:: read ( file) . map_err ( Error :: FailedToReadManifestEnvelopeFile ) ?;
2008- ManifestEnvelope :: try_from_slice ( & buf)
2009- . map_err ( |_| Error :: FileDidNotHaveValidManifestEnvelope )
2020+ let bytes = fs:: read ( file) . map_err ( Error :: FailedToReadManifestFile ) ?;
2021+
2022+ // try getting Manifest from json
2023+ let result = serde_json:: from_slice :: < ManifestEnvelope > ( & bytes) ;
2024+ if result. is_err ( ) {
2025+ // if not try the old borsh format
2026+ ManifestEnvelope :: try_from_slice_compat ( & bytes) . map_err ( Error :: from)
2027+ } else {
2028+ result. map_err ( Error :: from)
2029+ }
20102030}
20112031
20122032fn read_attestation_approval < P : AsRef < Path > > (
@@ -2015,7 +2035,7 @@ fn read_attestation_approval<P: AsRef<Path>>(
20152035 let manifest_envelope =
20162036 fs:: read ( path) . map_err ( Error :: FailedToReadAttestationApproval ) ?;
20172037
2018- Approval :: try_from_slice ( & manifest_envelope)
2038+ serde_json :: from_slice ( & manifest_envelope)
20192039 . map_err ( |_| Error :: FileDidNotHaveValidAttestationApproval )
20202040}
20212041
0 commit comments