diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2019-07-15 13:04:51 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2019-07-15 13:04:51 +0200 |
commit | 198991b8621b96d592373c1a5bc2fb193c63fac7 (patch) | |
tree | 259a35a7c96a6a42100ffb2a2ebc5ad324e81f60 | |
parent | 84884193178bb68c8057648d0ec02f79d5f083e4 (diff) |
Make more variables immutable.
- With the MIR-based borrow-checker being more precise than the
AST-based one, we can make more variables immutable.
-rw-r--r-- | openpgp/examples/web-of-trust.rs | 2 | ||||
-rw-r--r-- | openpgp/src/crypto/ecdh.rs | 4 | ||||
-rw-r--r-- | openpgp/src/crypto/s2k.rs | 2 | ||||
-rw-r--r-- | openpgp/src/packet/key.rs | 2 | ||||
-rw-r--r-- | openpgp/src/packet/signature/mod.rs | 6 | ||||
-rw-r--r-- | openpgp/src/parse/mpis.rs | 8 | ||||
-rw-r--r-- | openpgp/src/parse/parse.rs | 27 | ||||
-rw-r--r-- | openpgp/src/parse/stream.rs | 12 | ||||
-rw-r--r-- | openpgp/src/serialize/stream.rs | 6 | ||||
-rw-r--r-- | tool/src/commands/mod.rs | 2 | ||||
-rw-r--r-- | tool/src/commands/sign.rs | 2 | ||||
-rw-r--r-- | tool/src/sq.rs | 4 |
12 files changed, 39 insertions, 38 deletions
diff --git a/openpgp/examples/web-of-trust.rs b/openpgp/examples/web-of-trust.rs index 1fa4845b..754a7b13 100644 --- a/openpgp/examples/web-of-trust.rs +++ b/openpgp/examples/web-of-trust.rs @@ -30,7 +30,7 @@ fn main() { // For each input file, create a parser. for input in &args[1..] { eprintln!("Parsing {}...", input); - let mut parser = TPKParser::from_file(input) + let parser = TPKParser::from_file(input) .expect("Failed to create reader"); for tpk in parser { diff --git a/openpgp/src/crypto/ecdh.rs b/openpgp/src/crypto/ecdh.rs index eddd65e3..2c7862be 100644 --- a/openpgp/src/crypto/ecdh.rs +++ b/openpgp/src/crypto/ecdh.rs @@ -33,7 +33,7 @@ pub fn encrypt(recipient: &Key, session_key: &SessionKey) -> Result<Ciphertext> let R = q.decode_point(curve)?.0; // Generate an ephemeral key pair {v, V=vG} - let mut v: Protected = + let v: Protected = curve25519::private_key(&mut rng).into(); // Compute the public key. We need to add an encoding @@ -297,7 +297,7 @@ pub fn decrypt_shared(recipient: &Key, S: &Protected, ciphertext: &Ciphertext) let Z = kdf(&S, sym.key_size()?, *hash, ¶m)?; // Compute m = AESKeyUnwrap( Z, C ) as per [RFC3394] - let mut m = aes_key_unwrap(*sym, &Z, key)?; + let m = aes_key_unwrap(*sym, &Z, key)?; let cipher = SymmetricAlgorithm::from(m[0]); let m = pkcs5_unpad(m, 1 + cipher.key_size()? + 2)?; diff --git a/openpgp/src/crypto/s2k.rs b/openpgp/src/crypto/s2k.rs index 72b790e5..fcd41a62 100644 --- a/openpgp/src/crypto/s2k.rs +++ b/openpgp/src/crypto/s2k.rs @@ -397,7 +397,7 @@ mod tests { for test in tests.iter() { let path = crate::tests::message(&format!("s2k/{}", test.filename)); - let mut pp = PacketParser::from_bytes(path).unwrap().unwrap(); + let pp = PacketParser::from_bytes(path).unwrap().unwrap(); if let Packet::SKESK(SKESK::V4(ref skesk)) = pp.packet { assert_eq!(skesk.symmetric_algo(), test.cipher_algo); assert_eq!(skesk.s2k(), &test.s2k); diff --git a/openpgp/src/packet/key.rs b/openpgp/src/packet/key.rs index 441f10d1..86ff1e30 100644 --- a/openpgp/src/packet/key.rs +++ b/openpgp/src/packet/key.rs @@ -317,7 +317,7 @@ impl Key4 { let (mpis, secret, pk_algo) = match (curve.clone(), for_signing) { (Curve::Ed25519, true) => { let mut public = [0u8; ED25519_KEY_SIZE + 1]; - let mut private: Protected = + let private: Protected = ed25519::private_key(&mut rng).into(); public[0] = 0x40; diff --git a/openpgp/src/packet/signature/mod.rs b/openpgp/src/packet/signature/mod.rs index a1e3bbd3..b32d47ab 100644 --- a/openpgp/src/packet/signature/mod.rs +++ b/openpgp/src/packet/signature/mod.rs @@ -1088,7 +1088,7 @@ mod test { let mut good = 0; let mut ppr = PacketParser::from_bytes( crate::tests::message(test.data)).unwrap(); - while let PacketParserResult::Some(mut pp) = ppr { + while let PacketParserResult::Some(pp) = ppr { if let Packet::Signature(ref sig) = pp.packet { let result = sig.verify(tpk.primary()).unwrap_or(false); eprintln!(" Primary {:?}: {:?}", @@ -1153,8 +1153,8 @@ mod test { let mut pair = tpk.primary().clone().into_keypair() .expect("secret key is encrypted/missing"); - let mut sig = Builder::new(SignatureType::Binary); - let mut hash = hash_algo.context().unwrap(); + let sig = Builder::new(SignatureType::Binary); + let hash = hash_algo.context().unwrap(); // Make signature. let sig = sig.sign_hash(&mut pair, hash_algo, hash).unwrap(); diff --git a/openpgp/src/parse/mpis.rs b/openpgp/src/parse/mpis.rs index 4e0718b8..c45a9190 100644 --- a/openpgp/src/parse/mpis.rs +++ b/openpgp/src/parse/mpis.rs @@ -134,7 +134,7 @@ impl mpis::PublicKey { "unknown_parameter", php) { mpis.push(mpi); } - let mut rest = php.parse_bytes_eof("rest")?; + let rest = php.parse_bytes_eof("rest")?; Ok(mpis::PublicKey::Unknown { mpis: mpis.into_boxed_slice(), @@ -267,7 +267,7 @@ impl mpis::SecretKey { "unknown_parameter", php) { mpis.push(mpi.into()); } - let mut rest = php.parse_bytes_eof("rest")?; + let rest = php.parse_bytes_eof("rest")?; Ok(mpis::SecretKey::Unknown { mpis: mpis.into_boxed_slice(), @@ -345,7 +345,7 @@ impl mpis::Ciphertext { "unknown_parameter", php) { mpis.push(mpi); } - let mut rest = php.parse_bytes_eof("rest")?; + let rest = php.parse_bytes_eof("rest")?; Ok(mpis::Ciphertext::Unknown { mpis: mpis.into_boxed_slice(), @@ -452,7 +452,7 @@ impl mpis::Signature { "unknown_parameter", php) { mpis.push(mpi); } - let mut rest = php.parse_bytes_eof("rest")?; + let rest = php.parse_bytes_eof("rest")?; Ok(mpis::Signature::Unknown { mpis: mpis.into_boxed_slice(), diff --git a/openpgp/src/parse/parse.rs b/openpgp/src/parse/parse.rs index 7ecb0b1a..b0c77b2d 100644 --- a/openpgp/src/parse/parse.rs +++ b/openpgp/src/parse/parse.rs @@ -274,7 +274,7 @@ impl<'a> PacketHeaderParser<'a> { // This is a buffered_reader::Dup, so this always has an // inner. - let mut inner = Box::new(self.reader).into_inner().unwrap(); + let inner = Box::new(self.reader).into_inner().unwrap(); // Combine the header with the body for the map. let mut data = Vec::with_capacity(total_out + body.len()); @@ -1360,7 +1360,8 @@ impl Key4 { 254 => { let sk: SymmetricAlgorithm = php_try!(php.parse_u8("sym_algo")).into(); let s2k = php_try!(S2K::parse(&mut php)); - let mut cipher = php_try!(php.parse_bytes_eof("encrypted_mpis")); + let cipher = + php_try!(php.parse_bytes_eof("encrypted_mpis")); crate::packet::key::Encrypted::new( s2k, sk, cipher.into_boxed_slice()).into() @@ -1691,7 +1692,7 @@ fn compressed_data_parser_test () { CompressionAlgorithm::BZip2 => (), _ => continue, } - let mut pp = PacketParser::from_bytes(crate::tests::message( + let pp = PacketParser::from_bytes(crate::tests::message( &format!("compressed-data-algo-{}.gpg", i))).unwrap().unwrap(); // We expect a compressed packet containing a literal data @@ -1815,7 +1816,7 @@ fn skesk_parser_test() { ]; for test in tests.iter() { - let mut pp = PacketParser::from_bytes( + let pp = PacketParser::from_bytes( crate::tests::message(test.filename)).unwrap().unwrap(); if let Packet::SKESK(SKESK::V4(ref skesk)) = pp.packet { eprintln!("{:?}", skesk); @@ -1876,7 +1877,7 @@ impl MDC { let state = bio.cookie_mut(); if state.hashes_for == HashesFor::MDC { if state.sig_group().hashes.len() > 0 { - let mut h = state.sig_group_mut().hashes + let h = state.sig_group_mut().hashes .get_mut(&HashAlgorithm::SHA1) .unwrap(); h.digest(&mut computed_hash); @@ -2058,7 +2059,7 @@ impl<'a> Parse<'a, Packet> for Packet { ?.buffer_unread_content().finalize()?; let (p, ppr) = match ppr { - PacketParserResult::Some(mut pp) => { + PacketParserResult::Some(pp) => { pp.next()? }, PacketParserResult::EOF(_) => @@ -3453,7 +3454,7 @@ impl<'a> PacketParser<'a> { // comsume them in case we can't. { let data = self.data(aed.chunk_digest_size()?)?; - let mut dec = aead::Decryptor::new( + let dec = aead::Decryptor::new( 1, aed.symmetric_algo(), aed.aead(), aed.chunk_size(), aed.iv(), key, &data[..cmp::min(data.len(), aed.chunk_digest_size()?)])?; let mut chunk = Vec::new(); @@ -3693,7 +3694,7 @@ mod test { eprintln!("Decrypting {}, streaming content: {}", test.filename, stream); - let mut ppr = PacketParserBuilder::from_bytes( + let ppr = PacketParserBuilder::from_bytes( crate::tests::message(test.filename)).unwrap() .buffer_unread_content() .finalize() @@ -3738,7 +3739,7 @@ mod test { panic!("Expected a Literal packet. Got: {:?}", ppr); } - let mut ppr = consume_until( + let ppr = consume_until( ppr, true, &[ Tag::MDC ][..], &[ Tag::Signature ][..]); if let PacketParserResult::Some( PacketParser { packet: Packet::MDC(ref mdc), .. }) = ppr @@ -3808,7 +3809,7 @@ mod test { .finalize() .expect(&format!("Error reading {:?}", test)); - while let PacketParserResult::Some(mut pp) = ppr { + while let PacketParserResult::Some(pp) = ppr { assert!(pp.possible_keyring().is_ok()); ppr = pp.recurse().unwrap().1; } @@ -3833,7 +3834,7 @@ mod test { .finalize() .expect(&format!("Error reading {:?}", test)); - while let PacketParserResult::Some(mut pp) = ppr { + while let PacketParserResult::Some(pp) = ppr { assert!(pp.possible_keyring().is_ok()); assert!(pp.possible_tpk().is_ok()); ppr = pp.recurse().unwrap().1; @@ -3858,7 +3859,7 @@ mod test { .expect(&format!("Error reading {}", test.filename)[..]); let mut saw_literal = false; - while let PacketParserResult::Some(mut pp) = ppr { + while let PacketParserResult::Some(pp) = ppr { assert!(pp.possible_message().is_ok()); match pp.packet { @@ -3924,7 +3925,7 @@ mod test { "Message shorter than expected (expecting: {:?})", paths); - if let PacketParserResult::EOF(mut eof) = ppr { + if let PacketParserResult::EOF(eof) = ppr { assert_eq!(last_path, eof.last_path()); } else { panic!("Expect an EOF"); diff --git a/openpgp/src/parse/stream.rs b/openpgp/src/parse/stream.rs index 11c061ba..f94d9f5e 100644 --- a/openpgp/src/parse/stream.rs +++ b/openpgp/src/parse/stream.rs @@ -584,7 +584,7 @@ impl<'a, H: VerificationHelper> Verifier<'a, H> { // Process the rest of the packets. let mut ppr = PacketParserResult::Some(pp); - while let PacketParserResult::Some(mut pp) = ppr { + while let PacketParserResult::Some(pp) = ppr { if let Err(err) = pp.possible_message() { return Err(err.context( "Malformed OpenPGP message").into()); @@ -766,7 +766,7 @@ impl<'a> Transformer<'a> { let len = BodyLength::Full((data_prefix.len() + HEADER_LEN) as u32); len.serialize(&mut buf)?; - let mut lit = Literal::new(DataFormat::Binary); + let lit = Literal::new(DataFormat::Binary); lit.serialize_headers(&mut buf, false)?; // Copy the data, then proceed directly to the signatures. @@ -780,7 +780,7 @@ impl<'a> Transformer<'a> { let len = BodyLength::Partial(512); len.serialize(&mut buf)?; - let mut lit = Literal::new(DataFormat::Binary); + let lit = Literal::new(DataFormat::Binary); lit.serialize_headers(&mut buf, false)?; // Copy the prefix up to the first chunk, then keep in the @@ -1377,7 +1377,7 @@ impl<'a, H: VerificationHelper + DecryptionHelper> Decryptor<'a, H> { // Process the rest of the packets. let mut ppr = PacketParserResult::Some(pp); let mut first = true; - while let PacketParserResult::Some(mut pp) = ppr { + while let PacketParserResult::Some(pp) = ppr { // The literal data packet was already inspected. if first { assert_eq!(pp.packet.tag(), packet::Tag::Literal); @@ -1634,7 +1634,7 @@ mod test { for (f, r) in tests { // Test Verifier. - let mut h = VHelper::new(0, 0, 0, 0, keys.clone()); + let h = VHelper::new(0, 0, 0, 0, keys.clone()); let mut v = match Verifier::from_bytes(crate::tests::file(f), h, crate::frozen_time()) { @@ -1662,7 +1662,7 @@ mod test { assert_eq!(reference, &content[..]); // Test Decryptor. - let mut h = VHelper::new(0, 0, 0, 0, keys.clone()); + let h = VHelper::new(0, 0, 0, 0, keys.clone()); let mut v = match Decryptor::from_bytes(crate::tests::file(f), h, crate::frozen_time()) { diff --git a/openpgp/src/serialize/stream.rs b/openpgp/src/serialize/stream.rs index d4a62285..7ce3ac81 100644 --- a/openpgp/src/serialize/stream.rs +++ b/openpgp/src/serialize/stream.rs @@ -412,7 +412,7 @@ impl<'a> Signer<'a> { for signer in self.signers.iter_mut() { // Part of the signature packet is hashed in, // therefore we need to clone the hash. - let mut hash = self.hash.clone(); + let hash = self.hash.clone(); // Make and hash a signature packet. let mut sig = signature::Builder::new(SignatureType::Binary) @@ -1084,9 +1084,9 @@ impl<'a> Encryptor<'a> { // Now recover the original writer. First, strip the // Encryptor. - let mut w = w.into_inner()?.unwrap(); + let w = w.into_inner()?.unwrap(); // And the partial body filter. - let mut w = w.into_inner()?.unwrap(); + let w = w.into_inner()?.unwrap(); Ok(w) } else { diff --git a/tool/src/commands/mod.rs b/tool/src/commands/mod.rs index c0e8ad68..30a833a1 100644 --- a/tool/src/commands/mod.rs +++ b/tool/src/commands/mod.rs @@ -49,7 +49,7 @@ fn get_signing_keys(tpks: &[openpgp::TPK]) -> Result<Vec<crypto::KeyPair>> { .signing_capable() .map(|k| k.2) { - if let Some(mut secret) = key.secret() { + if let Some(secret) = key.secret() { let unencrypted = match secret { SecretKey::Encrypted(ref e) => { let password = rpassword::read_password_from_tty(Some( diff --git a/tool/src/commands/sign.rs b/tool/src/commands/sign.rs index 3bf56daa..749781dc 100644 --- a/tool/src/commands/sign.rs +++ b/tool/src/commands/sign.rs @@ -45,7 +45,7 @@ fn sign_data(input: &mut io::Read, output_path: Option<&str>, let mut ppr = openpgp::parse::PacketParser::from_file(output_path.unwrap())?; - while let PacketParserResult::Some(mut pp) = ppr { + while let PacketParserResult::Some(pp) = ppr { let (packet, ppr_tmp) = pp.recurse()?; ppr = ppr_tmp; diff --git a/tool/src/sq.rs b/tool/src/sq.rs index 408a320f..ec2fe2f8 100644 --- a/tool/src/sq.rs +++ b/tool/src/sq.rs @@ -219,7 +219,7 @@ fn real_main() -> Result<(), failure::Error> { ("autocrypt", Some(m)) => { match m.subcommand() { ("decode", Some(m)) => { - let mut input = open_or_stdin(m.value_of("input"))?; + let input = open_or_stdin(m.value_of("input"))?; let mut output = create_or_stdout(m.value_of("output"), force)?; let ac = autocrypt::AutocryptHeaders::from_reader(input)?; for h in &ac.headers { @@ -231,7 +231,7 @@ fn real_main() -> Result<(), failure::Error> { } }, ("encode-sender", Some(m)) => { - let mut input = open_or_stdin(m.value_of("input"))?; + let input = open_or_stdin(m.value_of("input"))?; let mut output = create_or_stdout(m.value_of("output"), force)?; let tpk = TPK::from_reader(input)?; |