From 89afc29f8e0d1416dfbd3b11461d4988a2ccc415 Mon Sep 17 00:00:00 2001 From: "Neal H. Walfield" Date: Tue, 9 Oct 2018 12:00:17 +0200 Subject: openpgp: Standardize on isize for expression recursion depths - When computing the relative depth, this prevents underflows without having to remember to cast. - This is the type that we tend to use anyways when dealing with recursion depths. --- openpgp/src/message/mod.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'openpgp/src/message') diff --git a/openpgp/src/message/mod.rs b/openpgp/src/message/mod.rs index 8b7f96a5..0f06aaa5 100644 --- a/openpgp/src/message/mod.rs +++ b/openpgp/src/message/mod.rs @@ -111,7 +111,7 @@ pub struct MessageValidator { finished: bool, // Once a raw token is pushed, this is set to None and pushing // packet Tags is no longer supported. - depth: Option, + depth: Option, // If we know that the packet sequence is invalid. error: Option, @@ -177,7 +177,7 @@ impl MessageValidator { /// /// The token *must* correspond to a packet; this function will /// panic if `token` is Token::Pop. - pub fn push_token(&mut self, token: Token, depth: usize) { + pub fn push_token(&mut self, token: Token, depth: isize) { assert!(!self.finished); assert!(self.depth.is_some()); assert!(token != Token::Pop); @@ -201,7 +201,7 @@ impl MessageValidator { /// stream. /// /// Note: top-level packets are at depth 0. - pub fn push(&mut self, tag: Tag, depth: usize) { + pub fn push(&mut self, tag: Tag, depth: isize) { let token = match tag { Tag::Literal => Token::Literal, Tag::CompressedData => Token::CompressedData, @@ -304,7 +304,7 @@ impl Message { pub fn from_packet_pile(pile: PacketPile) -> Result { let mut v = MessageValidator::new(); for (path, packet) in pile.descendants().paths() { - v.push(packet.tag(), path.len() - 1); + v.push(packet.tag(), path.len() as isize - 1); match packet { Packet::CompressedData(_) | Packet::SEIP(_) => { @@ -313,7 +313,7 @@ impl Message { if packet.children.is_none() && packet.body.is_some() { v.push_token(Token::OpaqueContent, - path.len() - 1 + 1); + path.len() as isize - 1 + 1); } } _ => {} @@ -530,7 +530,7 @@ mod tests { use Tag::*; struct TestVector<'a> { - s: &'a [(Tag, usize)], + s: &'a [(Tag, isize)], result: bool, } -- cgit v1.2.3