From fdb41822fc4be80647b23a98a03d15f29dcaf8af Mon Sep 17 00:00:00 2001
From: Jack Grigg <thestr4d@gmail.com>
Date: Tue, 13 Jun 2023 20:21:58 +0000
Subject: [PATCH] Bump MSRV to 1.65.0

---
 age-core/CHANGELOG.md        |  5 +++++
 age-core/Cargo.toml          |  2 +-
 age-core/src/format.rs       |  2 +-
 age-core/src/plugin.rs       |  2 +-
 age-plugin/CHANGELOG.md      |  2 ++
 age-plugin/Cargo.toml        |  2 +-
 age/CHANGELOG.md             |  5 +++++
 age/Cargo.toml               |  2 +-
 age/src/plugin.rs            |  2 +-
 age/src/primitives/stream.rs |  2 +-
 age/src/protocol.rs          |  2 +-
 age/src/scrypt.rs            |  2 +-
 age/src/ssh/identity.rs      |  2 +-
 age/src/ssh/recipient.rs     | 14 +++++++-------
 age/src/util.rs              |  4 ++--
 age/src/x25519.rs            |  8 ++++----
 age/tests/testkit.rs         |  6 +++---
 rage/CHANGELOG.md            |  2 ++
 rage/Cargo.toml              |  2 +-
 rust-toolchain.toml          |  2 +-
 20 files changed, 42 insertions(+), 28 deletions(-)

diff --git a/age-core/CHANGELOG.md b/age-core/CHANGELOG.md
index 6085e26..5d2b9d8 100644
--- a/age-core/CHANGELOG.md
+++ b/age-core/CHANGELOG.md
@@ -7,6 +7,11 @@ and this project adheres to Rust's notion of
 to 1.0.0 are beta releases.
 
 ## [Unreleased]
+### Added
+- `impl Eq for age_core::format::Stanza`
+
+### Changed
+- MSRV is now 1.65.0.
 
 ## [0.9.0] - 2022-10-27
 ### Changed
diff --git a/age-core/Cargo.toml b/age-core/Cargo.toml
index 3a06067..e129031 100644
--- a/age-core/Cargo.toml
+++ b/age-core/Cargo.toml
@@ -7,7 +7,7 @@ repository = "https://github.com/str4d/rage"
 readme = "README.md"
 license = "MIT OR Apache-2.0"
 edition = "2021"
-rust-version = "1.59"
+rust-version = "1.65"
 
 [package.metadata.docs.rs]
 all-features = true
diff --git a/age-core/src/format.rs b/age-core/src/format.rs
index cf16d90..260a0ef 100644
--- a/age-core/src/format.rs
+++ b/age-core/src/format.rs
@@ -68,7 +68,7 @@ impl<'a> AgeStanza<'a> {
 /// recipient.
 ///
 /// This is the owned type; see [`AgeStanza`] for the reference type.
-#[derive(Debug, PartialEq)]
+#[derive(Debug, PartialEq, Eq)]
 pub struct Stanza {
     /// A tag identifying this stanza type.
     pub tag: String,
diff --git a/age-core/src/plugin.rs b/age-core/src/plugin.rs
index 7dc0063..0c68c31 100644
--- a/age-core/src/plugin.rs
+++ b/age-core/src/plugin.rs
@@ -430,7 +430,7 @@ mod tests {
                 pipe.0 = pipe.0.split_off(n_out);
                 Ok(n_out)
             } else {
-                (&mut buf[..n_in]).copy_from_slice(&pipe.0);
+                buf[..n_in].copy_from_slice(&pipe.0);
                 pipe.0.clear();
                 Ok(n_in)
             }
diff --git a/age-plugin/CHANGELOG.md b/age-plugin/CHANGELOG.md
index 80aff0a..2ca0860 100644
--- a/age-plugin/CHANGELOG.md
+++ b/age-plugin/CHANGELOG.md
@@ -9,6 +9,8 @@ and this project adheres to Rust's notion of
 to 1.0.0 are beta releases.
 
 ## [Unreleased]
+### Changed
+- MSRV is now 1.65.0.
 
 ## [0.4.0] - 2022-10-27
 ### Changed
diff --git a/age-plugin/Cargo.toml b/age-plugin/Cargo.toml
index 31643ff..81a1715 100644
--- a/age-plugin/Cargo.toml
+++ b/age-plugin/Cargo.toml
@@ -7,7 +7,7 @@ repository = "https://github.com/str4d/rage"
 readme = "README.md"
 license = "MIT OR Apache-2.0"
 edition = "2021"
-rust-version = "1.59"
+rust-version = "1.65"
 
 [dependencies]
 age-core = { version = "0.9.0", path = "../age-core", features = ["plugin"] }
diff --git a/age/CHANGELOG.md b/age/CHANGELOG.md
index c390d37..3677d17 100644
--- a/age/CHANGELOG.md
+++ b/age/CHANGELOG.md
@@ -9,6 +9,11 @@ and this project adheres to Rust's notion of
 to 1.0.0 are beta releases.
 
 ## [Unreleased]
+### Added
+- `impl Eq for age::ssh::{ParseRecipientKeyError, UnsupportedKey}`
+
+### Changed
+- MSRV is now 1.65.0.
 
 ## [0.9.2] - 2023-06-12
 ### Added
diff --git a/age/Cargo.toml b/age/Cargo.toml
index 63ec0a5..7cb7e3c 100644
--- a/age/Cargo.toml
+++ b/age/Cargo.toml
@@ -9,7 +9,7 @@ keywords = ["rage", "encryption"]
 categories = ["cryptography"]
 license = "MIT OR Apache-2.0"
 edition = "2021"
-rust-version = "1.59"
+rust-version = "1.65"
 
 [badges]
 maintenance = { status = "experimental" }
diff --git a/age/src/plugin.rs b/age/src/plugin.rs
index b712616..ab52254 100644
--- a/age/src/plugin.rs
+++ b/age/src/plugin.rs
@@ -172,7 +172,7 @@ impl Identity {
     pub fn default_for_plugin(plugin_name: &str) -> Self {
         bech32::encode(
             &format!("{}{}-", PLUGIN_IDENTITY_PREFIX, plugin_name),
-            &[],
+            [],
             Variant::Bech32,
         )
         .expect("HRP is valid")
diff --git a/age/src/primitives/stream.rs b/age/src/primitives/stream.rs
index a3a84f6..adb5ced 100644
--- a/age/src/primitives/stream.rs
+++ b/age/src/primitives/stream.rs
@@ -60,7 +60,7 @@ impl Nonce {
 
     fn set_last(&mut self, last: bool) -> Result<(), ()> {
         if !self.is_last() {
-            self.0 |= if last { 1 } else { 0 };
+            self.0 |= u128::from(last);
             Ok(())
         } else {
             Err(())
diff --git a/age/src/protocol.rs b/age/src/protocol.rs
index 9d81f0b..fe0ff46 100644
--- a/age/src/protocol.rs
+++ b/age/src/protocol.rs
@@ -64,7 +64,7 @@ impl Encryptor {
     ///
     /// Returns `None` if no recipients were provided.
     pub fn with_recipients(recipients: Vec<Box<dyn Recipient + Send>>) -> Option<Self> {
-        (!recipients.is_empty()).then(|| Encryptor(EncryptorType::Keys(recipients)))
+        (!recipients.is_empty()).then_some(Encryptor(EncryptorType::Keys(recipients)))
     }
 
     /// Returns an `Encryptor` that will create an age file encrypted with a passphrase.
diff --git a/age/src/scrypt.rs b/age/src/scrypt.rs
index 1a510f0..aacd98a 100644
--- a/age/src/scrypt.rs
+++ b/age/src/scrypt.rs
@@ -94,7 +94,7 @@ impl crate::Recipient for Recipient {
             scrypt(&inner_salt, log_n, self.passphrase.expose_secret()).expect("log_n < 64");
         let encrypted_file_key = aead_encrypt(&enc_key, file_key.expose_secret());
 
-        let encoded_salt = base64::encode_config(&salt, base64::STANDARD_NO_PAD);
+        let encoded_salt = base64::encode_config(salt, base64::STANDARD_NO_PAD);
 
         Ok(vec![Stanza {
             tag: SCRYPT_RECIPIENT_TAG.to_owned(),
diff --git a/age/src/ssh/identity.rs b/age/src/ssh/identity.rs
index ee4e4e0..4413153 100644
--- a/age/src/ssh/identity.rs
+++ b/age/src/ssh/identity.rs
@@ -128,7 +128,7 @@ impl UnencryptedKey {
 ///
 /// The Display impl provides details for each unsupported key as to why we don't support
 /// it, and how a user can migrate to a supported key.
-#[derive(Clone, Debug, PartialEq)]
+#[derive(Clone, Debug, PartialEq, Eq)]
 pub enum UnsupportedKey {
     /// An encrypted `PEM` key.
     EncryptedPem,
diff --git a/age/src/ssh/recipient.rs b/age/src/ssh/recipient.rs
index 7ac020c..6964251 100644
--- a/age/src/ssh/recipient.rs
+++ b/age/src/ssh/recipient.rs
@@ -43,7 +43,7 @@ pub(crate) enum ParsedRecipient {
 }
 
 /// Error conditions when parsing an SSH recipient.
-#[derive(Debug, PartialEq)]
+#[derive(Debug, PartialEq, Eq)]
 pub enum ParseRecipientKeyError {
     /// The string is a parseable value that should be ignored. This case is for handling
     /// SSH recipient types that may occur in files we want to be able to parse, but that
@@ -74,10 +74,10 @@ impl fmt::Display for Recipient {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         match self {
             Recipient::SshRsa(ssh_key, _) => {
-                write!(f, "{} {}", SSH_RSA_KEY_PREFIX, base64::encode(&ssh_key))
+                write!(f, "{} {}", SSH_RSA_KEY_PREFIX, base64::encode(ssh_key))
             }
             Recipient::SshEd25519(ssh_key, _) => {
-                write!(f, "{} {}", SSH_ED25519_KEY_PREFIX, base64::encode(&ssh_key))
+                write!(f, "{} {}", SSH_ED25519_KEY_PREFIX, base64::encode(ssh_key))
             }
         }
     }
@@ -127,7 +127,7 @@ impl crate::Recipient for Recipient {
                     )
                     .expect("pubkey is valid and file key is not too long");
 
-                let encoded_tag = base64::encode_config(&ssh_tag(ssh_key), base64::STANDARD_NO_PAD);
+                let encoded_tag = base64::encode_config(ssh_tag(ssh_key), base64::STANDARD_NO_PAD);
 
                 Ok(vec![Stanza {
                     tag: SSH_RSA_RECIPIENT_TAG.to_owned(),
@@ -138,8 +138,8 @@ impl crate::Recipient for Recipient {
             Recipient::SshEd25519(ssh_key, ed25519_pk) => {
                 let pk: X25519PublicKey = ed25519_pk.to_montgomery().to_bytes().into();
 
-                let mut rng = rand_7::rngs::OsRng;
-                let esk = EphemeralSecret::new(&mut rng);
+                let rng = rand_7::rngs::OsRng;
+                let esk = EphemeralSecret::new(rng);
                 let epk: X25519PublicKey = (&esk).into();
 
                 let tweak: StaticSecret =
@@ -158,7 +158,7 @@ impl crate::Recipient for Recipient {
                 );
                 let encrypted_file_key = aead_encrypt(&enc_key, file_key.expose_secret());
 
-                let encoded_tag = base64::encode_config(&ssh_tag(ssh_key), base64::STANDARD_NO_PAD);
+                let encoded_tag = base64::encode_config(ssh_tag(ssh_key), base64::STANDARD_NO_PAD);
                 let encoded_epk = base64::encode_config(epk.as_bytes(), base64::STANDARD_NO_PAD);
 
                 Ok(vec![Stanza {
diff --git a/age/src/util.rs b/age/src/util.rs
index 2844c9e..dd97296 100644
--- a/age/src/util.rs
+++ b/age/src/util.rs
@@ -61,7 +61,7 @@ pub(crate) mod read {
                     let c = c as u8;
                     // Substitute the character in twice after AA, so that padding
                     // characters will also be detected as a valid if allowed.
-                    base64::decode_config_slice(&[65, 65, c, c], config, &mut [0, 0, 0]).is_ok()
+                    base64::decode_config_slice([65, 65, c, c], config, &mut [0, 0, 0]).is_ok()
                 }),
                 |data| base64::decode_config(data, config),
             )(input)
@@ -83,7 +83,7 @@ pub(crate) mod read {
                         let c = c as u8;
                         // Substitute the character in twice after AA, so that padding
                         // characters will also be detected as a valid if allowed.
-                        base64::decode_config_slice(&[65, 65, c, c], config, &mut [0, 0, 0]).is_ok()
+                        base64::decode_config_slice([65, 65, c, c], config, &mut [0, 0, 0]).is_ok()
                     }),
                 ),
                 |chunks| {
diff --git a/age/src/x25519.rs b/age/src/x25519.rs
index 21d3fe8..3006078 100644
--- a/age/src/x25519.rs
+++ b/age/src/x25519.rs
@@ -55,8 +55,8 @@ impl std::str::FromStr for Identity {
 impl Identity {
     /// Generates a new secret key.
     pub fn generate() -> Self {
-        let mut rng = OsRng;
-        Identity(StaticSecret::new(&mut rng))
+        let rng = OsRng;
+        Identity(StaticSecret::new(rng))
     }
 
     /// Serializes this secret key as a string.
@@ -185,8 +185,8 @@ impl fmt::Display for Recipient {
 
 impl crate::Recipient for Recipient {
     fn wrap_file_key(&self, file_key: &FileKey) -> Result<Vec<Stanza>, EncryptError> {
-        let mut rng = OsRng;
-        let esk = EphemeralSecret::new(&mut rng);
+        let rng = OsRng;
+        let esk = EphemeralSecret::new(rng);
         let epk: PublicKey = (&esk).into();
         let shared_secret = esk.diffie_hellman(&self.0);
 
diff --git a/age/tests/testkit.rs b/age/tests/testkit.rs
index 760e424..8d8762e 100644
--- a/age/tests/testkit.rs
+++ b/age/tests/testkit.rs
@@ -583,7 +583,7 @@ fn get_testkit_identities(filename: &str, testfile: &TestFile) -> Vec<x25519::Id
         // `scrypt_uppercase` uses the stanza tag `Scrypt` instead of `scrypt`, so
         // even though there is a valid passphrase, the decryptor treats it as a
         // different recipient stanza kind.
-        if filename == "scrypt_uppercase" { 1 } else { 0 }
+        usize::from(filename == "scrypt_uppercase")
     );
     testfile
         .identities
@@ -612,7 +612,7 @@ fn check_decrypt_success(
 ) {
     match (res, testfile.expect) {
         (Ok(_), Expect::Success { payload_sha256 }) => {
-            assert_eq!(Sha256::digest(&payload)[..], payload_sha256);
+            assert_eq!(Sha256::digest(payload)[..], payload_sha256);
         }
         // These testfile failures are expected, because we maintains support for
         // parsing legacy age stanzas without an explicit short final line.
@@ -642,7 +642,7 @@ fn check_decrypt_success(
             );
             // The tests with this expectation are checking that no partial STREAM
             // blocks are written to the payload.
-            assert_eq!(Sha256::digest(&payload)[..], payload_sha256);
+            assert_eq!(Sha256::digest(payload)[..], payload_sha256);
         }
         (actual, expected) => panic!(
             "Expected {:?}, got {}{}",
diff --git a/rage/CHANGELOG.md b/rage/CHANGELOG.md
index fec3659..940a379 100644
--- a/rage/CHANGELOG.md
+++ b/rage/CHANGELOG.md
@@ -9,6 +9,8 @@ and this project adheres to Rust's notion of
 to 1.0.0 are beta releases.
 
 ## [Unreleased]
+### Changed
+- MSRV is now 1.65.0.
 
 ## [0.9.2] - 2023-06-12
 ### Changed
diff --git a/rage/Cargo.toml b/rage/Cargo.toml
index 38a8f41..bd04412 100644
--- a/rage/Cargo.toml
+++ b/rage/Cargo.toml
@@ -9,7 +9,7 @@ keywords = ["age", "cli", "encryption"]
 categories = ["command-line-utilities", "cryptography"]
 license = "MIT OR Apache-2.0"
 edition = "2021"
-rust-version = "1.59"
+rust-version = "1.65"
 default-run = "rage"
 
 [package.metadata.deb]
diff --git a/rust-toolchain.toml b/rust-toolchain.toml
index 7930d28..ce69938 100644
--- a/rust-toolchain.toml
+++ b/rust-toolchain.toml
@@ -1,3 +1,3 @@
 [toolchain]
-channel = "1.59.0"
+channel = "1.65.0"
 components = ["clippy", "rustfmt"]