@@ -62,24 +62,30 @@ pub struct ClarifySliceWriter<'a> {
62
62
63
63
/// Clarifier that creates HEX with comments
64
64
pub struct Clarifier {
65
- // Buffer into which debug HEX and comments are written
65
+ /// Buffer into which debug HEX and comments are written
66
66
clarify_buf : Vec < u8 > ,
67
67
68
- // Position in the buffer is used to track how long is the current sub-message
68
+ /// Position in the buffer is used to track how long is the current sub-message
69
69
last_position : u32 ,
70
70
71
71
/// Used for debug indentation
72
72
///
73
73
/// Pushes writer positions on the stack
74
74
depth : Vec < Option < u32 > > ,
75
75
76
+ /// Determines if newlines and indent are currently enabled
76
77
indent_enabled : bool ,
78
+
79
+ /// Sans-io buffer for comments
77
80
comment_writer : Box < dyn CommentWriter > ,
78
81
}
79
82
80
83
/// Returned by .finish()
81
84
pub struct ClarifyOutputs < ' a > {
85
+ /// Raw DER/BER buffer
82
86
pub raw : Result < Cow < ' a , [ u8 ] > > ,
87
+
88
+ /// Hex-encoded DER/BER with comments
83
89
pub clarify_buf : Vec < u8 > ,
84
90
}
85
91
@@ -97,13 +103,6 @@ impl<'a> ClarifyOutputs<'a> {
97
103
clarify_buf : self . clarify_buf ,
98
104
}
99
105
}
100
- // pub fn and(result: Result<Cow<'a, [u8]>>) {
101
- // ClarifyOutputs {
102
- // // prioritize Encode::encode errors
103
- // raw: result.and(outputs.raw),
104
- // clarify_buf: outputs.clarify_buf,
105
- // };
106
- // }
107
106
}
108
107
109
108
/// Determines how comments will look like
@@ -225,17 +224,14 @@ impl Clarifier {
225
224
}
226
225
/// Writes string to debug output, for example a comment: `// SEQUENCE: name`
227
226
pub fn write_clarify_type_str ( & mut self , start_end : & str , type_name : & str ) {
228
- //let mut debugbuf = self.debug_ref.borrow_mut();
229
-
230
227
let comment = format ! ( "{start_end}: {type_name} " ) ;
231
228
self . comment_writer . comment ( & comment) ;
232
229
}
233
230
234
231
/// Writes string to debug output, for example a comment: `// "abc"`
235
232
pub fn write_clarify_value_quote ( & mut self , type_name : & str , value : & [ u8 ] ) {
236
- //let mut debugbuf = self.debug_ref.borrow_mut();
237
-
238
233
let contains_control = value. iter ( ) . any ( |& c| c == 0x7F || ( c < 0x20 && c != b'\n' ) ) ;
234
+
239
235
if value. len ( ) > 2 && !contains_control {
240
236
let type_name = strip_transparent_types ( type_name) ;
241
237
let comment = format ! ( "{} {:?} " , type_name, String :: from_utf8_lossy( value) ) ;
@@ -278,27 +274,13 @@ impl Clarifier {
278
274
self . write_clarify_type_str ( "end" , type_name. as_ref ( ) ) ;
279
275
}
280
276
281
- // /// for better tag-length pretty-printing inline
282
- // pub fn clarify_end_tag(&mut self, _tag: &Tag) {
283
- // // just to print a single length byte without indent
284
- // self.indent_enabled = false;
285
- // }
286
-
287
277
/// for better tag-length pretty-printing inline
288
278
pub fn clarify_header_start_tag ( & mut self , _tag : & Tag ) {
289
279
self . write_clarify_indent ( ) ;
290
280
// just to print header bytes without indent
291
281
self . indent_enabled = false ;
292
282
}
293
283
294
- // fn debug_set_indent_enabled(&mut self, enabled: bool) {
295
- // if !enabled {
296
- // // Write tabs before we switch to in-line mode
297
- // self.write_debug_indent();
298
- // }
299
- // self.indent_enabled = enabled;
300
- // }
301
-
302
284
/// Writes field name, i.e. field: `public_key`
303
285
///
304
286
/// when used on Sequence field:
@@ -330,15 +312,6 @@ impl Clarifier {
330
312
}
331
313
}
332
314
333
- // fn clarify_value_quote(&mut self, _type_name: &str, tag_name: &[u8]) {
334
- // //self.write_debug_value_quote(type_name, tag_name);
335
- // self.write_debug_value_quote("", tag_name);
336
- // }
337
-
338
- // fn debug_int(&mut self, value: i64) {
339
- // self.write_debug_int(value);
340
- // }
341
-
342
315
/// Writes pretty-printed `CHOICE name`
343
316
pub fn clarify_choice ( & mut self , choice_name : & [ u8 ] ) {
344
317
self . write_clarify_indent ( ) ;
0 commit comments