summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNora Widdecke <nora@sequoia-pgp.org>2021-04-07 20:23:44 +0200
committerNora Widdecke <nora@sequoia-pgp.org>2021-04-09 13:13:59 +0200
commit19169b76117db8b1d81f1aafa64a5440d042803d (patch)
treebdd07c05920f6217bd1512e6dc56c1d8fb1da6bf
parent694680ae3b2192c102f1b9a4d342677545cac629 (diff)
Lint: Use is_empty().
- https://rust-lang.github.io/rust-clippy/master/index.html#len_zero - https://rust-lang.github.io/rust-clippy/master/index.html#comparison_to_empty
-rw-r--r--autocrypt/src/lib.rs12
-rw-r--r--buffered-reader/src/decompress_deflate.rs2
-rw-r--r--buffered-reader/src/dup.rs2
-rw-r--r--buffered-reader/src/generic.rs2
-rw-r--r--buffered-reader/src/lib.rs6
-rw-r--r--buffered-reader/src/limitor.rs2
-rw-r--r--buffered-reader/src/memory.rs2
-rw-r--r--ffi/tests/c-tests.rs4
-rw-r--r--ipc/src/assuan/mod.rs2
-rw-r--r--ipc/src/gnupg.rs2
-rw-r--r--ipc/src/sexp.rs4
-rw-r--r--net/src/wkd.rs2
-rw-r--r--openpgp-ffi/tests/c-tests.rs4
-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
-rw-r--r--sq/build.rs2
-rw-r--r--sq/src/commands/certify.rs4
-rw-r--r--sq/src/commands/dump.rs2
-rw-r--r--sq/src/commands/inspect.rs2
-rw-r--r--sq/src/commands/key.rs2
-rw-r--r--sq/src/commands/keyring.rs2
-rw-r--r--sq/src/sq.rs8
-rw-r--r--sqv/build.rs2
-rw-r--r--sqv/src/sqv.rs4
39 files changed, 96 insertions, 96 deletions
diff --git a/autocrypt/src/lib.rs b/autocrypt/src/lib.rs
index 5c2386cc..b3bebd65 100644
--- a/autocrypt/src/lib.rs
+++ b/autocrypt/src/lib.rs
@@ -239,7 +239,7 @@ impl AutocryptHeaders {
// Return any error.
let mut line = line?;
- if line == "" {
+ if line.is_empty() {
// End of headers.
break;
}
@@ -252,7 +252,7 @@ impl AutocryptHeaders {
//
// See https://tools.ietf.org/html/rfc5322#section-2.2.3
while let Some(Ok(nl)) = next_line {
- if nl.len() > 0 && (&nl[0..1] == " " || &nl[0..1] == "\t") {
+ if !nl.is_empty() && (&nl[0..1] == " " || &nl[0..1] == "\t") {
line.push_str(&nl[..]);
next_line = lines.next();
} else {
@@ -315,7 +315,7 @@ impl AutocryptHeaders {
}
}
- let critical = key.len() >= 1 && &key[0..1] == "_";
+ let critical = !key.is_empty() && &key[0..1] == "_";
header.attributes.push(Attribute {
critical,
key: if critical {
@@ -571,7 +571,7 @@ impl AutocryptSetupMessage {
if k == "Passphrase-Format" { Some(v) } else { None }
})
.collect::<Vec<&String>>();
- let format = if format.len() > 0 {
+ let format = if !format.is_empty() {
// If there are multiple headers, then just silently take
// the first one.
Some(format[0].clone())
@@ -584,7 +584,7 @@ impl AutocryptSetupMessage {
if k == "Passphrase-Begin" { Some(v) } else { None }
})
.collect::<Vec<&String>>();
- let begin = if begin.len() > 0 {
+ let begin = if !begin.is_empty() {
// If there are multiple headers, then just silently take
// the first one.
Some(begin[0].clone())
@@ -754,7 +754,7 @@ impl<'a> AutocryptSetupMessageParser<'a> {
})
.collect::<Vec<&String>>();
- if prefer_encrypt.len() > 0 {
+ if !prefer_encrypt.is_empty() {
// If there are multiple headers, then just
// silently take the first one.
Some(prefer_encrypt[0].clone())
diff --git a/buffered-reader/src/decompress_deflate.rs b/buffered-reader/src/decompress_deflate.rs
index d713413a..1bb0bc4f 100644
--- a/buffered-reader/src/decompress_deflate.rs
+++ b/buffered-reader/src/decompress_deflate.rs
@@ -294,7 +294,7 @@ mod test {
for i in 0..input_raw.len() {
let data = reader.data(DEFAULT_BUF_SIZE + 1).unwrap().to_vec();
- assert!(data.len() > 0);
+ assert!(!data.is_empty());
assert_eq!(data, reader.buffer());
// And, we may as well check to make sure we read the
// right data.
diff --git a/buffered-reader/src/dup.rs b/buffered-reader/src/dup.rs
index df4a6e2f..c63ab9c8 100644
--- a/buffered-reader/src/dup.rs
+++ b/buffered-reader/src/dup.rs
@@ -194,7 +194,7 @@ mod test {
for i in 0..input.len() {
let data = reader.data(DEFAULT_BUF_SIZE + 1).unwrap().to_vec();
- assert!(data.len() > 0);
+ assert!(!data.is_empty());
assert_eq!(data, reader.buffer());
// And, we may as well check to make sure we read the
// right data.
diff --git a/buffered-reader/src/generic.rs b/buffered-reader/src/generic.rs
index 19f799eb..aa72e1b4 100644
--- a/buffered-reader/src/generic.rs
+++ b/buffered-reader/src/generic.rs
@@ -351,7 +351,7 @@ mod test {
for i in 0..input.len() {
let data = reader.data(DEFAULT_BUF_SIZE + 1).unwrap().to_vec();
- assert!(data.len() > 0);
+ assert!(!data.is_empty());
assert_eq!(data, reader.buffer());
// And, we may as well check to make sure we read the
// right data.
diff --git a/buffered-reader/src/lib.rs b/buffered-reader/src/lib.rs
index 18fdbaee..ed5a4724 100644
--- a/buffered-reader/src/lib.rs
+++ b/buffered-reader/src/lib.rs
@@ -723,13 +723,13 @@ pub trait BufferedReader<C> : io::Read + fmt::Debug + fmt::Display + Send + Sync
let len = {
// Try self.buffer. Only if it is empty, use
// self.data.
- let buffer = if self.buffer().len() == 0 {
+ let buffer = if self.buffer().is_empty() {
self.data(DEFAULT_BUF_SIZE)?
} else {
self.buffer()
};
- if buffer.len() == 0 {
+ if buffer.is_empty() {
break 'outer 0;
}
@@ -1096,7 +1096,7 @@ mod test {
{
let result = bio.data(buffer.len());
let buffer = result.unwrap();
- if buffer.len() > 0 {
+ if !buffer.is_empty() {
assert_eq!(buffer,
&data[data_start..data_start + buffer.len()]);
}
diff --git a/buffered-reader/src/limitor.rs b/buffered-reader/src/limitor.rs
index c20edced..e7260c3b 100644
--- a/buffered-reader/src/limitor.rs
+++ b/buffered-reader/src/limitor.rs
@@ -266,7 +266,7 @@ mod test {
for i in 0..input.len() {
let data = reader.data(DEFAULT_BUF_SIZE + 1).unwrap().to_vec();
- assert!(data.len() > 0);
+ assert!(!data.is_empty());
assert_eq!(data, reader.buffer());
// And, we may as well check to make sure we read the
// right data.
diff --git a/buffered-reader/src/memory.rs b/buffered-reader/src/memory.rs
index a177c6c0..6fb9e338 100644
--- a/buffered-reader/src/memory.rs
+++ b/buffered-reader/src/memory.rs
@@ -167,7 +167,7 @@ mod test {
for i in 0..input.len() {
let data = reader.data(DEFAULT_BUF_SIZE + 1).unwrap().to_vec();
- assert!(data.len() > 0);
+ assert!(!data.is_empty());
assert_eq!(data, reader.buffer());
// And, we may as well check to make sure we read the
// right data.
diff --git a/ffi/tests/c-tests.rs b/ffi/tests/c-tests.rs
index 4dd5f616..40f82094 100644
--- a/ffi/tests/c-tests.rs
+++ b/ffi/tests/c-tests.rs
@@ -163,7 +163,7 @@ fn for_all_tests<F>(path: &Path, mut fun: F)
}
if let Some(name) = exported_function_name(&line) {
- if test.len() > 0 {
+ if !test.is_empty() {
fun(path, test_starts_at, &name, replace(&mut test, vec![]),
run)?;
test.clear();
@@ -175,7 +175,7 @@ fn for_all_tests<F>(path: &Path, mut fun: F)
continue;
}
- if line == "//! ```" && test.len() > 0 {
+ if line == "//! ```" && !test.is_empty() {
let name = format!("{}_{}",
path.file_stem().unwrap().to_string_lossy(),
lineno); // XXX: nicer to point to the top
diff --git a/ipc/src/assuan/mod.rs b/ipc/src/assuan/mod.rs
index a3276210..6bbab37f 100644
--- a/ipc/src/assuan/mod.rs
+++ b/ipc/src/assuan/mod.rs
@@ -163,7 +163,7 @@ impl Client {
let mut data = data.as_ref();
let mut request = Vec::with_capacity(data.len());
while ! data.is_empty() {
- if request.len() > 0 {
+ if !request.is_empty() {
request.push(0x0a);
}
write!(&mut request, "D ").unwrap();
diff --git a/ipc/src/gnupg.rs b/ipc/src/gnupg.rs
index 1492345c..1d6b49bf 100644
--- a/ipc/src/gnupg.rs
+++ b/ipc/src/gnupg.rs
@@ -179,7 +179,7 @@ impl Context {
if output.status.success() {
let mut result = Vec::new();
for mut line in output.stdout.split(nl) {
- if line.len() == 0 {
+ if line.is_empty() {
// EOF.
break;
}
diff --git a/ipc/src/sexp.rs b/ipc/src/sexp.rs
index 771eee18..3d25862d 100644
--- a/ipc/src/sexp.rs
+++ b/ipc/src/sexp.rs
@@ -97,11 +97,11 @@ impl Sexp {
}
// Skip non-zero bytes.
- while s.len() > 0 && s[0] > 0 {
+ while !s.is_empty() && s[0] > 0 {
s = &s[1..];
}
- if s.len() == 0 {
+ if s.is_empty() {
return Err(Error::MalformedMPI(
"Invalid DEK encoding, no zero found".into())
.into());
diff --git a/net/src/wkd.rs b/net/src/wkd.rs
index cc14613c..50f32206 100644
--- a/net/src/wkd.rs
+++ b/net/src/wkd.rs
@@ -364,7 +364,7 @@ pub fn insert<P, S, V>(base_path: P, domain: S, variant: V,
}).collect::<Vec<_>>();
// Any?
- if addresses.len() == 0 {
+ if addresses.is_empty() {
return Err(openpgp::Error::InvalidArgument(
format!("Key {} does not have a UserID in {}", cert, domain)
).into());
diff --git a/openpgp-ffi/tests/c-tests.rs b/openpgp-ffi/tests/c-tests.rs
index 33a52261..ee906b0e 100644
--- a/openpgp-ffi/tests/c-tests.rs
+++ b/openpgp-ffi/tests/c-tests.rs
@@ -162,7 +162,7 @@ fn for_all_tests<F>(path: &Path, mut fun: F)
}
if let Some(name) = exported_function_name(&line) {
- if test.len() > 0 {
+ if !test.is_empty() {
fun(path, test_starts_at, &name, replace(&mut test, vec![]),
run)?;
test.clear();
@@ -174,7 +174,7 @@ fn for_all_tests<F>(path: &Path, mut fun: F)
continue;
}
- if line == "//! ```" && test.len() > 0 {
+ if line == "//! ```" && !test.is_empty() {
let name = format!("{}_{}",
path.file_stem().unwrap().to_string_lossy(),
lineno); // XXX: nicer to point to the top
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/ba