summaryrefslogtreecommitdiffstats
path: root/openpgp/src/message
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@pep.foundation>2018-10-09 12:00:17 +0200
committerNeal H. Walfield <neal@pep.foundation>2018-10-09 12:17:02 +0200
commit89afc29f8e0d1416dfbd3b11461d4988a2ccc415 (patch)
tree71a73e5feb65ac87bd2b83ec462ff6fe4d932fe5 /openpgp/src/message
parente139db9d16f79d7607288f78d360728b14ceed2b (diff)
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.
Diffstat (limited to 'openpgp/src/message')
-rw-r--r--openpgp/src/message/mod.rs12
1 files changed, 6 insertions, 6 deletions
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<usize>,
+ depth: Option<isize>,
// If we know that the packet sequence is invalid.
error: Option<MessageParserError>,
@@ -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<Self> {
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,
}