File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -14,9 +14,11 @@ rust-version = "1.34.2"
14
14
15
15
[dependencies ]
16
16
base64 = " 0.13.0"
17
+ serde = { version = " 1" , optional = true , features = [" serde_derive" ] }
17
18
18
19
[dev-dependencies ]
19
20
criterion = " 0.3.0"
21
+ serde_json = " 1"
20
22
21
23
[[bench ]]
22
24
name = " pem_benchmark"
Original file line number Diff line number Diff line change 103
103
unused_qualifications
104
104
) ]
105
105
106
+ #[ cfg( feature = "serde" ) ]
107
+ use serde:: { Serialize , Deserialize } ;
108
+
106
109
mod errors;
107
110
mod parser;
108
111
use parser:: { parse_captures, parse_captures_iter, Captures } ;
@@ -131,6 +134,7 @@ pub struct EncodeConfig {
131
134
132
135
/// A representation of Pem-encoded data
133
136
#[ derive( PartialEq , Debug , Clone ) ]
137
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
134
138
pub struct Pem {
135
139
/// The tag extracted from the Pem-encoded data
136
140
pub tag : String ,
@@ -613,4 +617,16 @@ RzHX0lkJl9Stshd/7Gbt65/QYq+v+xvAeT0CoyIg
613
617
614
618
assert_eq ! ( SAMPLE_LF , encoded) ;
615
619
}
620
+
621
+ #[ cfg( feature = "serde" ) ]
622
+ #[ test]
623
+ fn test_serde ( ) {
624
+ let pem = Pem {
625
+ tag : String :: from ( "Mock tag" ) ,
626
+ contents : "Mock contents" . as_bytes ( ) . to_vec ( ) ,
627
+ } ;
628
+ let value = serde_json:: to_string_pretty ( & pem) . unwrap ( ) ;
629
+ let result = serde_json:: from_str ( & value) . unwrap ( ) ;
630
+ assert_eq ! ( pem, result) ;
631
+ }
616
632
}
You can’t perform that action at this time.
0 commit comments