summaryrefslogtreecommitdiffstats
path: root/openpgp
diff options
context:
space:
mode:
Diffstat (limited to 'openpgp')
-rw-r--r--openpgp/examples/statistics.rs10
-rw-r--r--openpgp/src/armor.rs20
-rw-r--r--openpgp/src/armor/base64_utils.rs2
-rw-r--r--openpgp/src/cert.rs4
-rw-r--r--openpgp/src/cert/builder.rs2
-rw-r--r--openpgp/src/cert/bundle.rs2
-rw-r--r--openpgp/src/cert/parser/mod.rs6
-rw-r--r--openpgp/src/crypto/aead.rs10
-rw-r--r--openpgp/src/crypto/symmetric.rs6
-rw-r--r--openpgp/src/message/mod.rs2
-rw-r--r--openpgp/src/packet/user_attribute.rs2
-rw-r--r--openpgp/src/packet/userid.rs4
-rw-r--r--openpgp/src/parse.rs32
-rw-r--r--openpgp/src/parse/hashed_reader.rs4
-rw-r--r--openpgp/src/parse/stream.rs6
-rw-r--r--openpgp/src/serialize/stream.rs4
-rw-r--r--openpgp/src/types/bitfield.rs2
17 files changed, 59 insertions, 59 deletions
diff --git a/openpgp/examples/statistics.rs b/openpgp/examples/statistics.rs
index 502af558..fc262ee8 100644
--- a/openpgp/examples/statistics.rs
+++ b/openpgp/examples/statistics.rs
@@ -427,7 +427,7 @@ fn main() -> openpgp::Result<()> {
}
}
- if key_flags.len() > 0 {
+ if !key_flags.is_empty() {
println!();
println!("# KeyFlags statistics");
println!();
@@ -443,7 +443,7 @@ fn main() -> openpgp::Result<()> {
}
}
- if p_sym.len() > 0 {
+ if !p_sym.is_empty() {
println!();
println!("# PreferredSymmetricAlgorithms statistics");
println!();
@@ -462,7 +462,7 @@ fn main() -> openpgp::Result<()> {
}
}
- if p_hashes.len() > 0 {
+ if !p_hashes.is_empty() {
println!();
println!("# PreferredHashlgorithms statistics");
println!();
@@ -482,7 +482,7 @@ fn main() -> openpgp::Result<()> {
}
}
- if p_comp.len() > 0 {
+ if !p_comp.is_empty() {
println!();
println!("# PreferredCompressionAlgorithms statistics");
println!();
@@ -502,7 +502,7 @@ fn main() -> openpgp::Result<()> {
}
}
- if p_aead.len() > 0 {
+ if !p_aead.is_empty() {
println!();
println!("# PreferredAEADAlgorithms statistics");
println!();
diff --git a/openpgp/src/armor.rs b/openpgp/src/armor.rs
index c5d53b83..6a5eb9bb 100644
--- a/openpgp/src/armor.rs
+++ b/openpgp/src/armor.rs
@@ -370,7 +370,7 @@ impl<W: Write> Writer<W> {
self.finalize_headers()?;
// Write any stashed bytes and pad.
- if self.stash.len() > 0 {
+ if !self.stash.is_empty() {
self.sink.write_all(base64::encode_config(
&self.stash, base64::STANDARD).as_bytes())?;
self.column += 4;
@@ -430,9 +430,9 @@ impl<W: Write> Write for Writer<W> {
// and encode it. If writing out the stash fails below, we
// might end up with a stash of size 3.
assert!(self.stash.len() <= 3);
- if self.stash.len() > 0 {
+ if !self.stash.is_empty() {
while self.stash.len() < 3 {
- if input.len() == 0 {
+ if input.is_empty() {
/* We exhausted the input. Return now, any
* stashed bytes are encoded when finalizing the
* writer. */
@@ -470,7 +470,7 @@ impl<W: Write> Write for Writer<W> {
let encoded = base64::encode_config(input, base64::STANDARD_NO_PAD);
written += input.len();
let mut enc = encoded.as_bytes();
- while enc.len() > 0 {
+ while !enc.is_empty() {
let n = cmp::min(LINE_LENGTH - self.column, enc.len());
self.sink
.write_all(&enc[..n])?;
@@ -1086,7 +1086,7 @@ impl<'a> Reader<'a> {
/* Process headers. */
let key_value = line.splitn(2, ": ").collect::<Vec<&str>>();
if key_value.len() == 1 {
- if line.trim_start().len() == 0 {
+ if line.trim_start().is_empty() {
// Empty line.
break;
} else if lines == 1 {
@@ -1143,7 +1143,7 @@ fn common_prefix<A: AsRef<[u8]>, B: AsRef<[u8]>>(a: A, b: B) -> usize {
impl<'a> Reader<'a> {
fn read_armored_data(&mut self, buf: &mut [u8]) -> Result<usize> {
- let (consumed, decoded) = if self.decode_buffer.len() > 0 {
+ let (consumed, decoded) = if !self.decode_buffer.is_empty() {
// We have something buffered, use that.
let amount = cmp::min(buf.len(), self.decode_buffer.len());
@@ -1250,7 +1250,7 @@ impl<'a> Reader<'a> {
/* Look for CRC. The CRC is optional. */
let consumed = {
// Skip whitespace.
- while self.source.data(1)?.len() > 0
+ while !self.source.data(1)?.is_empty()
&& self.source.buffer()[0].is_ascii_whitespace()
{
self.source.consume(1);
@@ -1294,7 +1294,7 @@ impl<'a> Reader<'a> {
// Look for a footer.
let consumed = {
// Skip whitespace.
- while self.source.data(1)?.len() > 0
+ while !self.source.data(1)?.is_empty()
&& self.source.buffer()[0].is_ascii_whitespace()
{
self.source.consume(1);
@@ -1384,7 +1384,7 @@ impl<'a> Reader<'a> {
loop {
let prefixed_line = self.source.read_to(b'\n')?;
- if prefixed_line.len() == 0 {
+ if prefixed_line.is_empty() {
// Truncated?
break;
}
@@ -1502,7 +1502,7 @@ impl<'a> Reader<'a> {
self.initialize()?;
}
- if buf.len() == 0 {
+ if buf.is_empty() {
// Short-circuit here. Otherwise, we copy 0 bytes into
// the buffer, which means we decoded 0 bytes, and we
// wrongfully assume that we reached the end of the
diff --git a/openpgp/src/armor/base64_utils.rs b/openpgp/src/armor/base64_utils.rs
index 9e7fe500..aac7ae2a 100644
--- a/openpgp/src/armor/base64_utils.rs
+++ b/openpgp/src/armor/base64_utils.rs
@@ -165,7 +165,7 @@ pub fn is_armored_pgp_blob(bytes: &[u8]) -> bool {
match base64::decode_config(&bytes, base64::STANDARD) {
Ok(d) => {
// Don't consider an empty message to be valid.
- if d.len() == 0 {
+ if d.is_empty() {
false
} else {
let mut br = buffered_reader::Memory::new(&d);
diff --git a/openpgp/src/cert.rs b/openpgp/src/cert.rs
index 1c23987d..6c4f1ac9 100644
--- a/openpgp/src/cert.rs
+++ b/openpgp/src/cert.rs
@@ -1903,7 +1903,7 @@ impl Cert {
}
}
- if self.bad.len() > 0 {
+ if !self.bad.is_empty() {
t!("{}: ignoring {} bad self signatures",
self.keyid(), self.bad.len());
}
@@ -3739,7 +3739,7 @@ mod test {
assert!(cert_donald_signs_base.userids.len() == 1);
assert!(cert_donald_signs_base.userids[0].self_signatures.len() == 1);
- assert!(cert_base.userids[0].certifications.len() == 0);
+ assert!(cert_base.userids[0].certifications.is_empty());
assert!(cert_donald_signs_base.userids[0].certifications.len() == 1);
let merged = cert_donald_signs_base.clone()
diff --git a/openpgp/src/cert/builder.rs b/openpgp/src/cert/builder.rs
index e62bd5d0..6117a325 100644
--- a/openpgp/src/cert/builder.rs
+++ b/openpgp/src/cert/builder.rs
@@ -1006,7 +1006,7 @@ impl CertBuilder<'_> {
let mut cert = Cert::try_from(packets)?;
- let have_userids = self.userids.len() > 0;
+ let have_userids = !self.userids.is_empty();
// Sign UserIDs.
for (i, uid) in self.userids.into_iter().enumerate() {
diff --git a/openpgp/src/cert/bundle.rs b/openpgp/src/cert/bundle.rs
index 4c4fac2b..2b7847fe 100644
--- a/openpgp/src/cert/bundle.rs
+++ b/openpgp/src/cert/bundle.rs
@@ -623,7 +623,7 @@ impl<C> ComponentBundle<C> {
}
}).collect::<Vec<&Signature>>();
- if revs.len() == 0 {
+ if revs.is_empty() {
None
} else {
Some(revs)
diff --git a/openpgp/src/cert/parser/mod.rs b/openpgp/src/cert/parser/mod.rs
index 9e888e58..31929347 100644
--- a/openpgp/src/cert/parser/mod.rs
+++ b/openpgp/src/cert/parser/mod.rs
@@ -752,7 +752,7 @@ impl<'a> CertParser<'a> {
return Ok(None);
}
- if self.packets.len() > 0 {
+ if !self.packets.is_empty() {
if self.packets.len() == 1 {
if let Err(err) = Cert::valid_start(&self.packets[0]) {
t!("{}", err);
@@ -927,7 +927,7 @@ impl<'a> Iterator for CertParser<'a> {
None => {
t!("EOF.");
- if self.packets.len() == 0 {
+ if self.packets.is_empty() {
return None;
}
match self.cert(None) {
@@ -968,7 +968,7 @@ impl<'a> Iterator for CertParser<'a> {
self.saw_error = true;
return Some(Err(err));
}
- None if self.packets.len() == 0 => {
+ None if self.packets.is_empty() => {
t!("Packet iterator was empty");
Ok(None)
}
diff --git a/openpgp/src/crypto/aead.rs b/openpgp/src/crypto/aead.rs
index 8fd13d5e..a1d62456 100644
--- a/openpgp/src/crypto/aead.rs
+++ b/openpgp/src/crypto/aead.rs
@@ -227,7 +227,7 @@ impl<'a> Decryptor<'a> {
let mut digest = vec![0u8; self.digest_size];
// 1. Copy any buffered data.
- if self.buffer.len() > 0 {
+ if !self.buffer.is_empty() {
let to_copy = cmp::min(self.buffer.len(), plaintext.len());
&plaintext[..to_copy].copy_from_slice(&self.buffer[..to_copy]);
crate::vec_drain_prefix(&mut self.buffer, to_copy);
@@ -292,7 +292,7 @@ impl<'a> Decryptor<'a> {
let check_final_tag;
let chunk = match result {
Ok(chunk) => {
- if chunk.len() == 0 {
+ if chunk.is_empty() {
// Exhausted source.
return Ok(pos);
}
@@ -311,7 +311,7 @@ impl<'a> Decryptor<'a> {
assert!(chunk.len() <= chunk_digest_size);
- if chunk.len() == 0 {
+ if chunk.is_empty() {
// There is nothing to decrypt: all that is left is
// the final tag.
} else if chunk.len() <= self.digest_size {
@@ -639,7 +639,7 @@ impl<W: io::Write> Encryptor<W> {
let amount = buf.len();
// First, fill the buffer if there is something in it.
- if self.buffer.len() > 0 {
+ if !self.buffer.is_empty() {
let n = cmp::min(buf.len(), self.chunk_size - self.buffer.len());
self.buffer.extend_from_slice(&buf[..n]);
assert!(self.buffer.len() <= self.chunk_size);
@@ -696,7 +696,7 @@ impl<W: io::Write> Encryptor<W> {
/// Finish encryption and write last partial chunk.
pub fn finish(&mut self) -> Result<W> {
if let Some(mut inner) = self.inner.take() {
- if self.buffer.len() > 0 {
+ if !self.buffer.is_empty() {
let mut aead = self.make_aead(CipherOp::Encrypt)?;
self.hash_associated_data(&mut aead, false);
diff --git a/openpgp/src/crypto/symmetric.rs b/openpgp/src/crypto/symmetric.rs
index dba529ef..45e9cbd9 100644
--- a/openpgp/src/crypto/symmetric.rs
+++ b/openpgp/src/crypto/symmetric.rs
@@ -107,7 +107,7 @@ impl<R: io::Read> io::Read for Decryptor<R> {
let mut pos = 0;
// 1. Copy any buffered data.
- if self.buffer.len() > 0 {
+ if !self.buffer.is_empty() {
let to_copy = cmp::min(self.buffer.len(), plaintext.len());
&plaintext[..to_copy].copy_from_slice(&self.buffer[..to_copy]);
crate::vec_drain_prefix(&mut self.buffer, to_copy);
@@ -334,7 +334,7 @@ impl<W: io::Write> Encryptor<W> {
/// Finish encryption and write last partial block.
pub fn finish(&mut self) -> Result<W> {
if let Some(mut inner) = self.inner.take() {
- if self.buffer.len() > 0 {
+ if !self.buffer.is_empty() {
unsafe { self.scratch.set_len(self.buffer.len()) }
self.cipher.encrypt(&mut self.scratch, &self.buffer)?;
crate::vec_truncate(&mut self.buffer, 0);
@@ -369,7 +369,7 @@ impl<W: io::Write> io::Write for Encryptor<W> {
let amount = buf.len();
// First, fill the buffer if there is something in it.
- if self.buffer.len() > 0 {
+ if !self.buffer.is_empty() {
let n = cmp::min(buf.len(), self.block_size - self.buffer.len());
self.buffer.extend_from_slice(&buf[..n]);
assert!(self.buffer.len() <= self.block_size);
diff --git a/openpgp/src/message/mod.rs b/openpgp/src/message/mod.rs
index b4ace1aa..f491568d 100644
--- a/openpgp/src/message/mod.rs
+++ b/openpgp/src/message/mod.rs
@@ -164,7 +164,7 @@ impl MessageValidator {
assert!(!self.finished);
assert!(self.depth.is_some());
assert!(token != Token::Pop);
- assert!(path.len() > 0);
+ assert!(!path.is_empty());
if self.error.is_some() {
return;
diff --git a/openpgp/src/packet/user_attribute.rs b/openpgp/src/packet/user_attribute.rs
index 57d93e82..30249d58 100644
--- a/openpgp/src/packet/user_attribute.rs
+++ b/openpgp/src/packet/user_attribute.rs
@@ -172,7 +172,7 @@ impl<'a> Iterator for SubpacketIterator<'a> {
Err(e) => return Some(Err(e.into())),
};
- if raw.len() == 0 {
+ if raw.is_empty() {
return Some(Err(Error::MalformedPacket(
"Subpacket without type octet".into()).into()));
}
diff --git a/openpgp/src/packet/userid.rs b/openpgp/src/packet/userid.rs
index 028e9f73..2994f23e 100644
--- a/openpgp/src/packet/userid.rs
+++ b/openpgp/src/packet/userid.rs
@@ -627,7 +627,7 @@ impl UserID {
}
}
- if value.len() > 0 {
+ if !value.is_empty() {
value.push_str(" ");
}
value.push_str("(");
@@ -655,7 +655,7 @@ impl UserID {
}
}
- let something = value.len() > 0;
+ let something = !value.is_empty();
if something {
value.push_str(" <");
}
diff --git a/openpgp/src/parse.rs b/openpgp/src/parse.rs
index b85c9d4e..8c658746 100644
--- a/openpgp/src/parse.rs
+++ b/openpgp/src/parse.rs
@@ -441,7 +441,7 @@ impl<'a, T: 'a + BufferedReader<Cookie>> PacketHeaderParser<T> {
path: Vec<usize>, header: Header,
header_bytes: Vec<u8>) -> Self
{
- assert!(path.len() > 0);
+ assert!(!path.is_empty());
let mut cookie = Cookie::default();
cookie.level = inner.cookie_ref().level;
@@ -490,7 +490,7 @@ impl<'a, T: 'a + BufferedReader<Cookie>> PacketHeaderParser<T> {
//
// XXX avoid the extra copy.
let body = self.reader.steal_eof()?;
- if body.len() > 0 {
+ if !body.is_empty() {
self.field("body", body.len());
}
@@ -878,13 +878,13 @@ impl Cookie {
/// Returns a reference to the topmost signature group.
pub(crate) fn sig_group(&self) -> &SignatureGroup {
- assert!(self.sig_groups.len() > 0);
+ assert!(!self.sig_groups.is_empty());
&self.sig_groups[self.sig_groups.len() - 1]
}
/// Returns a mutable reference to the topmost signature group.
pub(crate) fn sig_group_mut(&mut self) -> &mut SignatureGroup {
- assert!(self.sig_groups.len() > 0);
+ assert!(!self.sig_groups.is_empty());
let len = self.sig_groups.len();
&mut self.sig_groups[len - 1]
}
@@ -898,7 +898,7 @@ impl Cookie {
/// Tests whether the topmost signature group is no longer used.
fn sig_group_unused(&self) -> bool {
- assert!(self.sig_groups.len() > 0);
+ assert!(!self.sig_groups.is_empty());
self.sig_groups[self.sig_groups.len() - 1].ops_count == 0
}
@@ -1573,7 +1573,7 @@ impl Subpacket {
},
SubpacketTag::RegularExpression => {
let mut v = php.parse_bytes("regular expr", len)?;
- if v.len() == 0 || v[v.len() - 1] != 0 {
+ if v.is_empty() || v[v.len() - 1] != 0 {
return Err(Error::MalformedPacket(
"Regular expression not 0-terminated".into())
.into());
@@ -2769,7 +2769,7 @@ impl MDC {
{
let state = bio.cookie_mut();
if state.hashes_for == HashesFor::MDC {
- if state.sig_group().hashes.len() > 0 {
+ if !state.sig_group().hashes.is_empty() {
let h = state.sig_group_mut().hashes
.iter_mut().find_map(
|mode|
@@ -3587,7 +3587,7 @@ impl<'a> PacketParserEOF<'a> {
/// # Ok(()) }
/// ```
pub fn last_recursion_depth(&self) -> Option<isize> {
- if self.last_path.len() == 0 {
+ if self.last_path.is_empty() {
None
} else {
Some(self.last_path.len() as isize - 1)
@@ -3972,7 +3972,7 @@ impl <'a> PacketParser<'a> {
/// # Ok(()) }
/// ```
pub fn last_recursion_depth(&self) -> Option<isize> {
- if self.last_path.len() == 0 {
+ if self.last_path.is_empty() {
assert_eq!(&self.path[..], &[ 0 ]);
None
} else {
@@ -4160,7 +4160,7 @@ impl <'a> PacketParser<'a> {
path: Vec<usize>)
-> Result<ParserResult<'a>>
{
- assert!(path.len() > 0);
+ assert!(!path.is_empty());
let indent = path.len() as isize - 1;
tracer!(TRACE, "PacketParser::parse", indent);
@@ -4170,7 +4170,7 @@ impl <'a> PacketParser<'a> {
// When header encounters an EOF, it returns an error. But,
// we want to return None. Try a one byte read.
- if bio.data(1)?.len() == 0 {
+ if bio.data(1)?.is_empty() {
t!("No packet at {:?} (EOF).", path);
return Ok(ParserResult::EOF((bio, state, path)));
}
@@ -4692,7 +4692,7 @@ impl <'a> PacketParser<'a> {
fn set_or_extend(rest: Vec<u8>, c: &mut Container, processed: bool)
-> Result<&[u8]> {
- if rest.len() > 0 {
+ if !rest.is_empty() {
let current = match c.body() {
Body::Unprocessed(bytes) => &bytes[..],
Body::Processed(bytes) => &bytes[..],
@@ -4701,7 +4701,7 @@ impl <'a> PacketParser<'a> {
"cannot append unread bytes to parsed packets"
.into()).into()),
};
- let rest = if current.len() > 0 {
+ let rest = if !current.is_empty() {
let mut new =
Vec::with_capacity(current.len() + rest.len());
new.extend_from_slice(current);
@@ -4739,7 +4739,7 @@ impl <'a> PacketParser<'a> {
Packet::AED(p) =>
set_or_extend(rest, p.deref_mut(), ! self.encrypted),
p => {
- if rest.len() > 0 {
+ if !rest.is_empty() {
Err(Error::MalformedPacket(
format!("Unexpected body data for {:?}: {}",
p, crate::fmt::hex::encode_pretty(rest)))
@@ -4794,7 +4794,7 @@ impl <'a> PacketParser<'a> {
self.packet.tag(), recursion_depth,
self.data_eof().unwrap_or(&[]).len());
- self.buffer_unread_content()?.len() > 0
+ !self.buffer_unread_content()?.is_empty()
} else {
t!("({:?} at depth {}): dropping {} bytes of unread content",
self.packet.tag(), recursion_depth,
@@ -4830,7 +4830,7 @@ impl <'a> PacketParser<'a> {
/// Hashes content that has been streamed.
fn hash_read_content(&mut self, b: &[u8]) {
- if b.len() > 0 {
+ if !b.is_empty() {
assert!(self.body_hash.is_some());
self.body_hash.as_mut().map(|h| h.update(b));
self.content_was_read = true;
diff --git a/openpgp/src/parse/hashed_reader.rs b/openpgp/src/parse/hashed_reader.rs
index 03de2916..be074570 100644
--- a/openpgp/src/parse/hashed_reader.rs
+++ b/openpgp/src/parse/hashed_reader.rs
@@ -123,7 +123,7 @@ impl Cookie {
}
}
- if data.len() == 0 {
+ if data.is_empty() {
return;
}
@@ -178,7 +178,7 @@ impl Cookie {
data = &data[1..];
}
- if data.len() == 0 {
+ if data.is_empty() {
return;
}
diff --git a/openpgp/src/parse/stream.rs b/openpgp/src/parse/stream.rs
index 88313604..5170eb8f 100644
--- a/openpgp/src/parse/stream.rs
+++ b/openpgp/src/parse/stream.rs
@@ -2868,7 +2868,7 @@ impl<'a, H: VerificationHelper + DecryptionHelper> Decryptor<'a, H> {
/// Like `io::Read::read()`, but returns our `Result`.
fn read_helper(&mut self, buf: &mut [u8]) -> Result<usize> {
- if buf.len() == 0 {
+ if buf.is_empty() {
return Ok(0);
}
@@ -3456,7 +3456,7 @@ mod test {
// Check that we only got a truncated message.
assert!(v.message_processed());
- assert!(message.len() > 0);
+ assert!(!message.is_empty());
assert!(message.len() <= 1 * 1024 * 1024);
assert!(message.iter().all(|&b| b == 42));
assert!(v.helper_ref().good == 1);
@@ -3507,7 +3507,7 @@ mod test {
// Check that we only got a truncated message.
assert!(v.message_processed());
- assert!(message.len() > 0);
+ assert!(!message.is_empty());
assert!(message.len() <= 1 * 1024 * 1024);
assert!(message.iter().all(|&b| b == 42));
assert!(v.helper_ref().good == 1);
diff --git a/openpgp/src/serialize/stream.rs b/openpgp/src/serialize/stream.rs
index 1bc4b507..84a6bfa4 100644
--- a/openpgp/src/serialize/stream.rs
+++ b/openpgp/src/serialize/stream.rs
@@ -1255,7 +1255,7 @@ impl<'a> Signer<'a> {
/// ```
pub fn build(mut self) -> Result<Message<'a>>
{
- assert!(self.signers.len() > 0, "The constructor adds a signer.");
+ assert!(!self.signers.is_empty(), "The constructor adds a signer.");
assert!(self.inner.is_some(), "The constructor adds an inner writer.");
match self.mode {
@@ -1364,7 +1364,7 @@ impl<'a> Write for Signer<'a> {
// Shortcut empty writes. This is important for the code
// below that delays hashing newlines when creating cleartext
// signed messages.
- if buf.len() == 0 {
+ if buf.is_empty() {
return Ok(0);
}
diff --git a/openpgp/src/types/bitfield.rs b/openpgp/src/types/bitfield.rs
index 7de2311e..c6dd5f13 100644
--- a/openpgp/src/types/bitfield.rs
+++ b/openpgp/src/types/bitfield.rs
@@ -77,7 +77,7 @@ impl Bitfield {
/// Remove any trailing padding.
fn clear_padding(mut self) -> Self {
- while self.raw.len() > 0 && self.raw[self.raw.len() - 1] == 0 {
+ while !self.raw.is_empty() && self.raw[self.raw.len() - 1] == 0 {
self.raw.truncate(self.raw.len() - 1);
}