Skip to content

Commit a10a80d

Browse files
committed
Remove workaround for boxed FnOnce in Rust <1.35
Since the MSRV of the crate has been updated, we can remove the workaround for rust-lang/rust#28796 and just use a Box<FnOnce> directly. Signed-off-by: Nick Stevens <[email protected]>
1 parent 2b46834 commit a10a80d

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

src/crypter.rs

+4-20
Original file line numberDiff line numberDiff line change
@@ -318,27 +318,11 @@ impl StateMachine for Encrypter {
318318
}
319319
}
320320

321-
// This is a workaround to allow calling a Box<FnOnce> in Rust versions less
322-
// than 1.35. When the MSRV is 1.35 or greater, this can be removed and
323-
// replaced directly with `Box<dyn FnOnce(...)>`.
324-
//
325-
// Refer to https://github.com/rust-lang/rust/issues/28796 for more info.
326-
pub(crate) trait KeyLookupFn {
327-
fn call_box(self: Box<Self>, public_key: &PublicKey) -> Option<SecretKey>;
328-
}
329-
330-
impl<T> KeyLookupFn for T
331-
where
332-
T: FnOnce(&PublicKey) -> Option<SecretKey>,
333-
{
334-
fn call_box(self: Box<Self>, public_key: &PublicKey) -> Option<SecretKey> {
335-
(*self)(public_key)
336-
}
337-
}
321+
type KeyLookupFn = Box<dyn FnOnce(&PublicKey) -> Option<SecretKey>>;
338322

339323
pub(crate) enum KeyResolution {
340324
Available(PublicKey, SecretKey),
341-
Deferred(Box<dyn KeyLookupFn>),
325+
Deferred(KeyLookupFn),
342326
}
343327

344328
impl fmt::Debug for KeyResolution {
@@ -354,7 +338,7 @@ impl fmt::Debug for KeyResolution {
354338
pub(crate) enum DecrypterState {
355339
ReadPreheader(KeyResolution),
356340
ReadPublicKey(KeyResolution),
357-
SecretKeyLookup(PublicKey, Box<dyn KeyLookupFn>),
341+
SecretKeyLookup(PublicKey, KeyLookupFn),
358342
ReadHeader(PublicKey, PublicKey, SecretKey),
359343
OpenStream(Key, Header),
360344
ReadLength(Stream<Pull>),
@@ -480,7 +464,7 @@ impl Decrypter {
480464
}
481465
},
482466
SecretKeyLookup(file_public_key, lookup_fn) => {
483-
if let Some(secret_key) = lookup_fn.call_box(&file_public_key) {
467+
if let Some(secret_key) = lookup_fn(&file_public_key) {
484468
state::next(ReadHeader(
485469
file_public_key.clone(),
486470
file_public_key,

0 commit comments

Comments
 (0)