11use crate :: types:: error:: AnoncredsError ;
2- use anoncreds_core:: data_types:: link_secret:: { LinkSecret as AnoncredsLinkSecret } ;
2+ use anoncreds_core:: data_types:: link_secret:: LinkSecret as AnoncredsLinkSecret ;
33use std:: convert:: TryFrom ;
44use std:: convert:: TryInto ;
55use std:: sync:: Arc ;
@@ -14,54 +14,88 @@ impl LinkSecret {
1414 LinkSecret { secret : secret }
1515 }
1616
17- pub fn new_from_json ( json_string : String ) -> Result < Self , AnoncredsError > {
18- let core_def = AnoncredsLinkSecret :: try_from ( json_string. as_str ( ) ) . map_err ( |_| AnoncredsError :: ConversionError ) ?;
19- return Ok ( LinkSecret { secret : core_def } )
17+ pub fn new_from_value ( value_string : String ) -> Result < Self , AnoncredsError > {
18+ let core_def = AnoncredsLinkSecret :: try_from ( value_string. as_str ( ) )
19+ . map_err ( |_| AnoncredsError :: ConversionError ) ?;
20+ return Ok ( LinkSecret { secret : core_def } ) ;
2021 }
2122
2223 pub fn get_big_number ( & self ) -> String {
2324 let clone = self . clone ( ) ;
2425 clone. into ( )
2526 }
2627
27- pub fn get_json ( & self ) -> Result < String , AnoncredsError > {
28+ pub fn get_value ( & self ) -> Result < String , AnoncredsError > {
2829 let clone = self . clone ( ) ;
29- return Ok ( clone. into ( ) )
30+ return Ok ( clone. into ( ) ) ;
3031 }
3132}
3233
3334impl From < AnoncredsLinkSecret > for LinkSecret {
34-
3535 fn from ( acr : AnoncredsLinkSecret ) -> Self {
36- return LinkSecret { secret : acr }
36+ return LinkSecret { secret : acr } ;
3737 }
3838}
3939
4040impl TryFrom < & str > for LinkSecret {
4141 type Error = AnoncredsError ;
4242
4343 fn try_from ( string : & str ) -> Result < Self , Self :: Error > {
44- let acr = AnoncredsLinkSecret :: try_from ( string) . map_err ( |_| AnoncredsError :: ConversionError ) ?;
45- return Ok ( LinkSecret { secret : acr } )
44+ let acr =
45+ AnoncredsLinkSecret :: try_from ( string) . map_err ( |_| AnoncredsError :: ConversionError ) ?;
46+ return Ok ( LinkSecret { secret : acr } ) ;
4647 }
4748}
4849
4950impl TryFrom < & LinkSecret > for AnoncredsLinkSecret {
5051 type Error = AnoncredsError ;
5152
5253 fn try_from ( acr : & LinkSecret ) -> Result < Self , Self :: Error > {
53- acr. secret . try_clone ( ) . map_err ( |_| AnoncredsError :: ConversionError )
54- }
54+ acr. secret
55+ . try_clone ( )
56+ . map_err ( |_| AnoncredsError :: ConversionError )
57+ }
5558}
5659
5760impl Into < String > for LinkSecret {
5861 fn into ( self ) -> String {
59- self . secret . 0 . to_hex ( ) . unwrap ( )
60- }
62+ self . secret . 0 . to_dec ( ) . unwrap ( )
63+ }
6164}
6265
6366impl Clone for LinkSecret {
6467 fn clone ( & self ) -> Self {
65- LinkSecret { secret : self . secret . try_clone ( ) . unwrap ( ) }
68+ LinkSecret {
69+ secret : self . secret . try_clone ( ) . unwrap ( ) ,
70+ }
71+ }
72+ }
73+
74+ #[ cfg( test) ]
75+ mod warp_link_secret_tests {
76+ use super :: * ;
77+
78+ #[ test]
79+ fn should_serialize_and_deserialize_AnoncredsLinkSecret_into_the_same_value ( ) {
80+ let link_secret = AnoncredsLinkSecret :: new ( ) . expect ( "Error creating link secret" ) ;
81+ let link_secret_srt: String = link_secret. try_into ( ) . expect ( "Error creating link secret" ) ;
82+ // println!("{}", link_secret_srt);
83+ let link_secret2 = AnoncredsLinkSecret :: try_from ( link_secret_srt. as_str ( ) )
84+ . expect ( "Error creating link secret" ) ;
85+ let link_secret_srt2: String = link_secret2. try_into ( ) . expect ( "Error creating link secret" ) ;
86+ // println!("{}", link_secret_srt2);
87+ assert_eq ! ( link_secret_srt, link_secret_srt2) ;
6688 }
67- }
89+
90+ #[ test]
91+ fn should_serialize_and_deserialize_LinkSecret_into_the_same_value ( ) {
92+ let link_secret = LinkSecret :: new ( ) ;
93+ let link_secret_srt: String = link_secret. try_into ( ) . expect ( "Error creating link secret" ) ;
94+ println ! ( "{}" , link_secret_srt) ;
95+ let link_secret2 =
96+ LinkSecret :: try_from ( link_secret_srt. as_str ( ) ) . expect ( "Error creating link secret" ) ;
97+ let link_secret_srt2: String = link_secret2. try_into ( ) . expect ( "Error creating link secret" ) ;
98+ println ! ( "{}" , link_secret_srt2) ;
99+ assert_eq ! ( link_secret_srt, link_secret_srt2) ;
100+ }
101+ }
0 commit comments