summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2021-01-22 08:02:20 +0100
committerJustus Winter <justus@sequoia-pgp.org>2021-01-22 08:33:14 +0100
commit02fc0a45dd1a34368c5a5526756c5416cf997b83 (patch)
treeb1bfd3f8fa623c1b03e91a442e3bd153b6cd933f
parent2d85f05a3265359cf9c9affa55ca63a04b04215b (diff)
sq: Make limit explicit.
-rw-r--r--sq/src/sq.rs7
1 files changed, 5 insertions, 2 deletions
diff --git a/sq/src/sq.rs b/sq/src/sq.rs
index 02706a22..a62c4922 100644
--- a/sq/src/sq.rs
+++ b/sq/src/sq.rs
@@ -220,13 +220,16 @@ fn parse_armor_kind(kind: Option<&str>) -> Option<armor::Kind> {
}
}
+/// How much data to look at when detecting armor kinds.
+const ARMOR_DETECTION_LIMIT: u64 = 1 << 24;
+
/// Peeks at the first packet to guess the type.
///
/// Returns the given reader unchanged. If the detection fails,
/// armor::Kind::File is returned as safe default.
fn detect_armor_kind(input: Box<dyn BufferedReader<()>>)
-> (Box<dyn BufferedReader<()>>, armor::Kind) {
- let mut dup = Limitor::new(Dup::new(input), 1 << 24).as_boxed();
+ let mut dup = Limitor::new(Dup::new(input), ARMOR_DETECTION_LIMIT).as_boxed();
let kind = 'detection: loop {
if let Ok(ppr) = PacketParser::from_reader(&mut dup) {
if let PacketParserResult::Some(pp) = ppr {
@@ -461,7 +464,7 @@ fn main() -> Result<()> {
// Peek at the data. If it looks like it is armored
// data, avoid armoring it again.
- let mut dup = Limitor::new(Dup::new(input), 1 << 24);
+ let mut dup = Limitor::new(Dup::new(input), ARMOR_DETECTION_LIMIT);
let (already_armored, have_kind) = {
let mut reader =
armor::Reader::new(&mut dup,