From 6b605494d4ece1480f281ae7ffbe8ccacc477711 Mon Sep 17 00:00:00 2001 From: Nick Stevens Date: Thu, 27 Feb 2020 10:54:15 -0600 Subject: [PATCH] Remove workaround for boxed FnOnce in Rust <1.35 Since the MSRV of the crate has been updated, we can remove the workaround for https://github.com/rust-lang/rust/issues/28796 and just use a Box directly. Signed-off-by: Nick Stevens --- src/crypter.rs | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/src/crypter.rs b/src/crypter.rs index 3306ae9..d3681e7 100644 --- a/src/crypter.rs +++ b/src/crypter.rs @@ -336,27 +336,11 @@ impl StateMachine for Encrypter { } } -// This is a workaround to allow calling a Box in Rust versions less -// than 1.35. When the MSRV is 1.35 or greater, this can be removed and -// replaced directly with `Box`. -// -// Refer to https://github.com/rust-lang/rust/issues/28796 for more info. -pub(crate) trait KeyLookupFn { - fn call_box(self: Box, public_key: &PublicKey) -> Option; -} - -impl KeyLookupFn for T -where - T: FnOnce(&PublicKey) -> Option, -{ - fn call_box(self: Box, public_key: &PublicKey) -> Option { - (*self)(public_key) - } -} +type KeyLookupFn = Box Option>; pub(crate) enum KeyResolution { Available(PublicKey, SecretKey), - Deferred(Box), + Deferred(KeyLookupFn), } impl fmt::Debug for KeyResolution { @@ -372,7 +356,7 @@ impl fmt::Debug for KeyResolution { pub(crate) enum DecrypterState { ReadPreheader(KeyResolution), ReadPublicKey(KeyResolution), - SecretKeyLookup(PublicKey, Box), + SecretKeyLookup(PublicKey, KeyLookupFn), ReadHeader(PublicKey, PublicKey, SecretKey), OpenStream(Key, Header), ReadLength(Stream), @@ -504,7 +488,7 @@ impl Decrypter { } }, SecretKeyLookup(file_public_key, lookup_fn) => { - if let Some(secret_key) = lookup_fn.call_box(&file_public_key) { + if let Some(secret_key) = lookup_fn(&file_public_key) { state::next(ReadHeader( file_public_key.clone(), file_public_key,