11use crate :: types:: error:: AnoncredsError ;
2- use anoncreds_core:: data_types:: nonce:: { Nonce as AnoncredsNounce } ;
2+ use anoncreds_core:: data_types:: nonce:: Nonce as AnoncredsNonce ;
33use std:: convert:: TryFrom ;
44use std:: convert:: TryInto ;
55use std:: sync:: Arc ;
66
77pub struct Nonce {
8- pub anoncreds_nonce : AnoncredsNounce ,
8+ pub anoncreds_nonce : AnoncredsNonce ,
99}
1010
1111impl Nonce {
1212 pub fn new ( ) -> Self {
13- let nonce = AnoncredsNounce :: new ( ) . unwrap ( ) ;
14- return Nonce { anoncreds_nonce : nonce }
13+ let nonce = AnoncredsNonce :: new ( ) . unwrap ( ) ;
14+ return Nonce {
15+ anoncreds_nonce : nonce,
16+ } ;
17+ }
18+
19+ pub fn new_from_value ( value_string : String ) -> Result < Self , AnoncredsError > {
20+ let nonce = AnoncredsNonce :: try_from ( value_string. as_str ( ) )
21+ . map_err ( |_| AnoncredsError :: ConversionError ) ?;
22+ return Ok ( Nonce {
23+ anoncreds_nonce : nonce,
24+ } ) ;
25+ }
26+
27+ pub fn get_value ( & self ) -> Result < String , AnoncredsError > {
28+ let clone = self . clone ( ) ;
29+ return Ok ( clone. into ( ) ) ;
30+ }
31+ }
32+
33+ impl From < AnoncredsNonce > for Nonce {
34+ fn from ( acr : AnoncredsNonce ) -> Self {
35+ return Nonce {
36+ anoncreds_nonce : acr,
37+ } ;
38+ }
39+ }
40+
41+ impl TryFrom < & Nonce > for AnoncredsNonce {
42+ type Error = AnoncredsError ;
43+
44+ fn try_from ( acr : & Nonce ) -> Result < Self , Self :: Error > {
45+ acr. anoncreds_nonce
46+ . try_clone ( )
47+ . map_err ( |_| AnoncredsError :: ConversionError )
1548 }
1649}
1750
@@ -25,14 +58,18 @@ impl TryFrom<&str> for Nonce {
2558 type Error = AnoncredsError ;
2659
2760 fn try_from ( value : & str ) -> Result < Self , Self :: Error > {
28- let nonce = AnoncredsNounce :: try_from ( value) . map_err ( |_| AnoncredsError :: ConversionError ) ?;
29- return Ok ( Nonce { anoncreds_nonce : nonce } )
61+ let nonce = AnoncredsNonce :: try_from ( value) . map_err ( |_| AnoncredsError :: ConversionError ) ?;
62+ return Ok ( Nonce {
63+ anoncreds_nonce : nonce,
64+ } ) ;
3065 }
3166}
3267
3368impl Clone for Nonce {
3469 fn clone ( & self ) -> Self {
3570 let original = self . anoncreds_nonce . try_clone ( ) . unwrap ( ) ;
36- return Nonce { anoncreds_nonce : original }
71+ return Nonce {
72+ anoncreds_nonce : original,
73+ } ;
3774 }
38- }
75+ }
0 commit comments