diff options
author | Nora Widdecke <nora@sequoia-pgp.org> | 2021-11-22 16:00:49 +0100 |
---|---|---|
committer | Nora Widdecke <nora@sequoia-pgp.org> | 2021-11-29 11:53:55 +0100 |
commit | 01590ecf0da6ff45f110edb03988efd3847066f8 (patch) | |
tree | 61607d8eb9648410aa3000e848ad30f02ba6b93c /openpgp | |
parent | 4ecbe9e0348b2d56e2d5431aac54c342a08ca1a6 (diff) |
Use range syntax.
- Use range syntac instad of manual comparisons. This is arguably
better to read.
- Found by clippy::manual_range_contains.
Diffstat (limited to 'openpgp')
-rw-r--r-- | openpgp/src/crypto/aead.rs | 4 | ||||
-rw-r--r-- | openpgp/src/crypto/s2k.rs | 2 | ||||
-rw-r--r-- | openpgp/src/packet/header/mod.rs | 7 | ||||
-rw-r--r-- | openpgp/src/packet/signature/subpacket.rs | 2 | ||||
-rw-r--r-- | openpgp/src/packet/tag.rs | 2 | ||||
-rw-r--r-- | openpgp/src/parse.rs | 2 | ||||
-rw-r--r-- | openpgp/src/types/mod.rs | 18 |
7 files changed, 18 insertions, 19 deletions
diff --git a/openpgp/src/crypto/aead.rs b/openpgp/src/crypto/aead.rs index 4ef774a4..5162d351 100644 --- a/openpgp/src/crypto/aead.rs +++ b/openpgp/src/crypto/aead.rs @@ -150,7 +150,7 @@ impl<'a> Decryptor<'a> { source: Box<dyn 'a + BufferedReader<Cookie>>) -> Result<Self> { - if chunk_size < MIN_CHUNK_SIZE || chunk_size > MAX_CHUNK_SIZE { + if !(MIN_CHUNK_SIZE..=MAX_CHUNK_SIZE).contains(&chunk_size) { return Err(Error::InvalidArgument( format!("Invalid AEAD chunk size: {}", chunk_size)).into()); } @@ -567,7 +567,7 @@ impl<W: io::Write> Encryptor<W> { pub fn new(version: u8, sym_algo: SymmetricAlgorithm, aead: AEADAlgorithm, chunk_size: usize, iv: &[u8], key: &SessionKey, sink: W) -> Result<Self> { - if chunk_size < MIN_CHUNK_SIZE || chunk_size > MAX_CHUNK_SIZE { + if !(MIN_CHUNK_SIZE..=MAX_CHUNK_SIZE).contains(&chunk_size) { return Err(Error::InvalidArgument( format!("Invalid AEAD chunk size: {}", chunk_size)).into()); } diff --git a/openpgp/src/crypto/s2k.rs b/openpgp/src/crypto/s2k.rs index 98895b5f..40ae2e70 100644 --- a/openpgp/src/crypto/s2k.rs +++ b/openpgp/src/crypto/s2k.rs @@ -552,7 +552,7 @@ mod tests { S2K::Unknown { tag, .. } => (tag > 3 && tag < 100) || tag == 2 || tag > 110, S2K::Private { tag, .. } => - tag >= 100 && tag <= 110, + (100..=110).contains(&tag), _ => true } } diff --git a/openpgp/src/packet/header/mod.rs b/openpgp/src/packet/header/mod.rs index 809d2efc..0040d501 100644 --- a/openpgp/src/packet/header/mod.rs +++ b/openpgp/src/packet/header/mod.rs @@ -168,16 +168,15 @@ impl Header { // A V3 signature is 19 bytes plus the // MPIs. A V4 is 10 bytes plus the hash // areas and the MPIs. - 10 <= l - && l < (10 // Header, fixed sized fields. + (10..(10 // Header, fixed sized fields. + 2 * 64 * 1024 // Hashed & Unhashed areas. + 64 * 1024 // MPIs. - ), + )).contains(&l), Tag::SKESK => // 2 bytes of fixed header. An s2k // specification (at least 1 byte), an // optional encryption session key. - 3 <= l && l < 10 * 1024, + (3..10 * 1024).contains(&l), Tag::PKESK => // 10 bytes of fixed header, plus the // encrypted session key. diff --git a/openpgp/src/packet/signature/subpacket.rs b/openpgp/src/packet/signature/subpacket.rs index e26375bd..ed7fd57e 100644 --- a/openpgp/src/packet/signature/subpacket.rs +++ b/openpgp/src/packet/signature/subpacket.rs @@ -442,7 +442,7 @@ mod tests { (u == 0 || u == 1 || u == 8 || u == 13 || u == 14 || u == 15 || u == 17 || u == 18 || u == 19), - SubpacketTag::Private(u) => u >= 100 && u <= 110, + SubpacketTag::Private(u) => (100..=110).contains(&u), SubpacketTag::Unknown(u) => (u > 33 && u < 100) || u > 110, _ => true } diff --git a/openpgp/src/packet/tag.rs b/openpgp/src/packet/tag.rs index ba3e98d8..b939b207 100644 --- a/openpgp/src/packet/tag.rs +++ b/openpgp/src/packet/tag.rs @@ -283,7 +283,7 @@ mod tests { fn unknown_private(tag: Tag) -> bool { match tag { Tag::Unknown(u) => u > 19 || u == 15 || u == 16, - Tag::Private(u) => u >= 60 && u <= 63, + Tag::Private(u) => (60..=63).contains(&u), _ => true } } diff --git a/openpgp/src/parse.rs b/openpgp/src/parse.rs index 4bd93fff..0fb5ccae 100644 --- a/openpgp/src/parse.rs +++ b/openpgp/src/parse.rs @@ -1823,7 +1823,7 @@ impl SubpacketLength { octet1 as u32, // Unambiguous. None)) - } else if 192 <= octet1 && octet1 < 255 { + } else if (192..255).contains(&octet1) { // Two octets length. let octet2 = bio.data_consume_hard(1)?[0]; let len = ((octet1 as u32 - 192) << 8) + octet2 as u32 + 192; diff --git a/openpgp/src/types/mod.rs b/openpgp/src/types/mod.rs index 833ca480..e5d5c5e6 100644 --- a/openpgp/src/types/mod.rs +++ b/openpgp/src/types/mod.rs @@ -1728,7 +1728,7 @@ mod tests { fn comp_parse(comp: CompressionAlgorithm) -> bool { match comp { CompressionAlgorithm::Unknown(u) => u > 110 || (u > 3 && u < 100), - CompressionAlgorithm::Private(u) => u >= 100 && u <= 110, + CompressionAlgorithm::Private(u) => (100..=110).contains(&u), _ => true } } @@ -1755,7 +1755,7 @@ mod tests { SymmetricAlgorithm::Unknown(u) => u == 5 || u == 6 || u > 110 || (u > 10 && u < 100), SymmetricAlgorithm::Private(u) => - u >= 100 && u <= 110, + (100..=110).contains(&u), _ => true } } @@ -1782,7 +1782,7 @@ mod tests { AEADAlgorithm::Unknown(u) => u == 0 || u > 110 || (u > 2 && u < 100), AEADAlgorithm::Private(u) => - u >= 100 && u <= 110, + (100..=110).contains(&u), _ => true } } @@ -1807,9 +1807,9 @@ mod tests { fn pk_parse(pk: PublicKeyAlgorithm) -> bool { match pk { PublicKeyAlgorithm::Unknown(u) => - u == 0 || u > 110 || (u >= 4 && u <= 15) - || (u >= 18 && u < 100), - PublicKeyAlgorithm::Private(u) => u >= 100 && u <= 110, + u == 0 || u > 110 || (4..=15).contains(&u) + || (18..100).contains(&u), + PublicKeyAlgorithm::Private(u) => (100..=110).contains(&u), _ => true } } @@ -1880,8 +1880,8 @@ mod tests { fn hash_parse(hash: HashAlgorithm) -> bool { match hash { HashAlgorithm::Unknown(u) => u == 0 || (u > 11 && u < 100) || - u > 110 || (u >= 4 && u <= 7) || u == 0, - HashAlgorithm::Private(u) => u >= 100 && u <= 110, + u > 110 || (4..=7).contains(&u) || u == 0, + HashAlgorithm::Private(u) => (100..=110).contains(&u), _ => true } } @@ -1909,7 +1909,7 @@ mod tests { || (u > 32 && u < 100) || u > 110, ReasonForRevocation::Private(u) => - u >= 100 && u <= 110, + (100..=110).contains(&u), _ => true } } |