@@ -19,29 +19,29 @@ use symmetriccipher::{BlockEncryptor, BlockEncryptorX8, Encryptor, BlockDecrypto
19
19
SynchronousStreamCipher , SymmetricCipherError } ;
20
20
use symmetriccipher:: SymmetricCipherError :: { InvalidPadding , InvalidLength } ;
21
21
22
- /// The BlockProcessor trait is used to implement modes that require processing complete blocks of
23
- /// data. The methods of this trait are called by the BlockEngine which is in charge of properly
22
+ /// The ` BlockProcessor` trait is used to implement modes that require processing complete blocks of
23
+ /// data. The methods of this trait are called by the ` BlockEngine` which is in charge of properly
24
24
/// buffering input data.
25
25
trait BlockProcessor {
26
26
/// Process a block of data. The in_hist and out_hist parameters represent the input and output
27
27
/// when the last block was processed. These values are necessary for certain modes.
28
28
fn process_block ( & mut self , in_hist : & [ u8 ] , out_hist : & [ u8 ] , input : & [ u8 ] , output : & mut [ u8 ] ) ;
29
29
}
30
30
31
- /// A PaddingProcessor handles adding or removing padding
31
+ /// A ` PaddingProcessor` handles adding or removing padding
32
32
pub trait PaddingProcessor {
33
33
/// Add padding to the last block of input data
34
34
/// If the mode can't handle a non-full block, it signals that error by simply leaving the block
35
- /// as it is which will be detected as an InvalidLength error.
35
+ /// as it is which will be detected as an ` InvalidLength` error.
36
36
fn pad_input < W : WriteBuffer > ( & mut self , input_buffer : & mut W ) ;
37
37
38
38
/// Remove padding from the last block of output data
39
39
/// If false is returned, the processing fails
40
40
fn strip_output < R : ReadBuffer > ( & mut self , output_buffer : & mut R ) -> bool ;
41
41
}
42
42
43
- /// The BlockEngine is implemented as a state machine with the following states. See comments in the
44
- /// BlockEngine code for more information on the states.
43
+ /// The ` BlockEngine` is implemented as a state machine with the following states. See comments in the
44
+ /// ` BlockEngine` code for more information on the states.
45
45
#[ derive( Clone , Copy ) ]
46
46
enum BlockEngineState {
47
47
FastMode ,
@@ -53,28 +53,28 @@ enum BlockEngineState {
53
53
Error ( SymmetricCipherError )
54
54
}
55
55
56
- /// BlockEngine buffers input and output data and handles sending complete block of data to the
57
- /// Processor object. Additionally, BlockEngine handles logic necessary to add or remove padding by
56
+ /// ` BlockEngine` buffers input and output data and handles sending complete block of data to the
57
+ /// Processor object. Additionally, ` BlockEngine` handles logic necessary to add or remove padding by
58
58
/// calling the appropriate methods on the Processor object.
59
59
struct BlockEngine < P , X > {
60
60
/// The block sized expected by the Processor
61
61
block_size : usize ,
62
62
63
- /// in_hist and out_hist keep track of data that was input to and output from the last
64
- /// invocation of the process_block() method of the Processor. Depending on the mode, these may
63
+ /// ` in_hist` and ` out_hist` keep track of data that was input to and output from the last
64
+ /// invocation of the ` process_block()` method of the Processor. Depending on the mode, these may
65
65
/// be empty vectors if history is not needed.
66
66
in_hist : Vec < u8 > ,
67
67
out_hist : Vec < u8 > ,
68
68
69
69
/// If some input data is supplied, but not a complete blocks worth, it is stored in this buffer
70
- /// until enough arrives that it can be passed to the process_block() method of the Processor.
70
+ /// until enough arrives that it can be passed to the ` process_block()` method of the Processor.
71
71
in_scratch : OwnedWriteBuffer ,
72
72
73
73
/// If input data is processed but there isn't enough space in the output buffer to store it,
74
- /// it is written into out_write_scratch. OwnedWriteBuffer' s may be converted into
75
- /// OwnedReaderBuffers without re-allocating, so, after being written, out_write_scratch is
76
- /// turned into out_read_scratch. After that, if is written to the output as more output becomes
77
- /// available. The main point is - only out_write_scratch or out_read_scratch contains a value
74
+ /// it is written into ` out_write_scratch`. ` OwnedWriteBuffer` s may be converted into
75
+ /// `OwnedReaderBuffer`s without re-allocating, so, after being written, ` out_write_scratch` is
76
+ /// turned into ` out_read_scratch` . After that, if is written to the output as more output becomes
77
+ /// available. The main point is - only ` out_write_scratch` or ` out_read_scratch` contains a value
78
78
/// at any given time; never both.
79
79
out_write_scratch : Option < OwnedWriteBuffer > ,
80
80
out_read_scratch : Option < OwnedReadBuffer > ,
@@ -105,7 +105,7 @@ fn update_history(in_hist: &mut [u8], out_hist: &mut [u8], last_in: &[u8], last_
105
105
}
106
106
107
107
impl < P : BlockProcessor , X : PaddingProcessor > BlockEngine < P , X > {
108
- /// Create a new BlockProcessor instance with the given processor and block_size. No history
108
+ /// Create a new ` BlockProcessor` instance with the given processor and ` block_size` . No history
109
109
/// will be saved.
110
110
fn new ( processor : P , padding : X , block_size : usize ) -> BlockEngine < P , X > {
111
111
BlockEngine {
@@ -121,7 +121,7 @@ impl <P: BlockProcessor, X: PaddingProcessor> BlockEngine<P, X> {
121
121
}
122
122
}
123
123
124
- /// Create a new BlockProcessor instance with the given processor, block_size, and initial input
124
+ /// Create a new ` BlockProcessor` instance with the given processor, ` block_size` , and initial input
125
125
/// and output history.
126
126
fn new_with_history (
127
127
processor : P ,
@@ -136,9 +136,9 @@ impl <P: BlockProcessor, X: PaddingProcessor> BlockEngine<P, X> {
136
136
}
137
137
}
138
138
139
- /// This implements the FastMode state. Ideally, the encryption or decryption operation should
140
- /// do the bulk of its work in FastMode. Significantly, FastMode avoids doing copies as much as
141
- /// possible. The FastMode state does not handle the final block of data.
139
+ /// This implements the ` FastMode` state. Ideally, the encryption or decryption operation should
140
+ /// do the bulk of its work in ` FastMode` . Significantly, ` FastMode` avoids doing copies as much as
141
+ /// possible. The ` FastMode` state does not handle the final block of data.
142
142
fn fast_mode < R : ReadBuffer , W : WriteBuffer > (
143
143
& mut self ,
144
144
input : & mut R ,
@@ -211,7 +211,7 @@ impl <P: BlockProcessor, X: PaddingProcessor> BlockEngine<P, X> {
211
211
}
212
212
}
213
213
214
- /// This method implements the BlockEngine state machine.
214
+ /// This method implements the ` BlockEngine` state machine.
215
215
fn process < R : ReadBuffer , W : WriteBuffer > (
216
216
& mut self ,
217
217
input : & mut R ,
@@ -460,7 +460,7 @@ impl PaddingProcessor for PkcsPadding {
460
460
}
461
461
}
462
462
463
- /// Wraps a PaddingProcessor so that only pad_input() will actually be called.
463
+ /// Wraps a ` PaddingProcessor` so that only ` pad_input()` will actually be called.
464
464
pub struct EncPadding < X > {
465
465
padding : X
466
466
}
@@ -474,7 +474,7 @@ impl <X: PaddingProcessor> PaddingProcessor for EncPadding<X> {
474
474
fn strip_output < R : ReadBuffer > ( & mut self , _: & mut R ) -> bool { true }
475
475
}
476
476
477
- /// Wraps a PaddingProcessor so that only strip_output() will actually be called.
477
+ /// Wraps a ` PaddingProcessor` so that only ` strip_output()` will actually be called.
478
478
pub struct DecPadding < X > {
479
479
padding : X
480
480
}
0 commit comments