@@ -75,6 +75,10 @@ struct DecryptCommand {
75
75
#[ clap( env, short, long) ]
76
76
pub file : PathBuf ,
77
77
78
+ /// The max number utf-8 characters to read from the file.
79
+ #[ clap( env, long, default_value_t = 8 * 1024 ) ]
80
+ pub max_line_len : u64 ,
81
+
78
82
/// By default, records are output to STDOUT as a BASE64 values followed newlines.
79
83
/// This option can be used to write to a file.
80
84
#[ clap( env, short, long) ]
@@ -88,6 +92,10 @@ struct EncryptCommand {
88
92
#[ clap( env, short, long) ]
89
93
pub file : PathBuf ,
90
94
95
+ /// The max number utf-8 characters to read from the file.
96
+ #[ clap( env, long, default_value_t = 8 * 1024 ) ]
97
+ pub max_line_len : u64 ,
98
+
91
99
/// By default, records are output to STDOUT as a BASE64 values followed newlines.
92
100
/// This option can be used to write to a file.
93
101
#[ clap( env, short, long) ]
@@ -148,9 +156,11 @@ async fn secret_store(
148
156
type LineReaderFn = Box < dyn FnMut ( ) -> Result < Option < String > , io:: Error > + Send > ;
149
157
type OutputFn = Box < dyn Write + Send > ;
150
158
151
- const LINE_LIMIT : u64 = 8 * 1024 ;
152
-
153
- fn pipeline ( file : PathBuf , output : Option < PathBuf > ) -> Result < ( LineReaderFn , OutputFn ) , Errors > {
159
+ fn pipeline (
160
+ file : PathBuf ,
161
+ output : Option < PathBuf > ,
162
+ max_line_len : u64 ,
163
+ ) -> Result < ( LineReaderFn , OutputFn ) , Errors > {
154
164
// A line reader function is provided rather than something based on the
155
165
// Read trait as reading a line from stdin involves locking it via its
156
166
// own read_line function. A Read trait will cause a lock to occur for
@@ -162,14 +172,15 @@ fn pipeline(file: PathBuf, output: Option<PathBuf>) -> Result<(LineReaderFn, Out
162
172
let mut line = String :: new ( ) ;
163
173
Box :: new ( move || {
164
174
line. clear ( ) ;
165
- if stdin. lock ( ) . take ( LINE_LIMIT ) . read_line ( & mut line) ? > 0 {
175
+ if stdin. lock ( ) . take ( max_line_len ) . read_line ( & mut line) ? > 0 {
166
176
Ok ( Some ( line. clone ( ) ) )
167
177
} else {
168
178
Ok ( None )
169
179
}
170
180
} )
171
181
} else {
172
- let mut buf = BufReader :: new ( fs:: File :: open ( file) . map_err ( Errors :: from) ?) . take ( LINE_LIMIT ) ;
182
+ let mut buf =
183
+ BufReader :: new ( fs:: File :: open ( file) . map_err ( Errors :: from) ?) . take ( max_line_len) ;
173
184
let mut line = String :: new ( ) ;
174
185
Box :: new ( move || {
175
186
line. clear ( ) ;
@@ -209,11 +220,13 @@ async fn main() -> Result<(), Box<dyn Error>> {
209
220
let task = tokio:: spawn ( async move {
210
221
match args. command {
211
222
Command :: Decrypt ( command) => {
212
- let ( line_reader, output) = pipeline ( command. file , command. output ) ?;
223
+ let ( line_reader, output) =
224
+ pipeline ( command. file , command. output , command. max_line_len ) ?;
213
225
cryptor:: decrypt ( ss, line_reader, output) . await
214
226
}
215
227
Command :: Encrypt ( command) => {
216
- let ( line_reader, output) = pipeline ( command. file , command. output ) ?;
228
+ let ( line_reader, output) =
229
+ pipeline ( command. file , command. output , command. max_line_len ) ?;
217
230
cryptor:: encrypt ( ss, line_reader, output) . await
218
231
}
219
232
}
0 commit comments