From 5db18c5a8fd4ad36ee41c458e0c8ac706c8adac2 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Fri, 6 May 2022 13:57:03 +1000 Subject: [PATCH] Derive Hash for enums Audit the whole crate and for any enum that can derive `Hash`. Exclude error enums. Derive `Hash` on any non-error enums that can. --- src/expression.rs | 1 + src/interpreter/mod.rs | 6 +++--- src/miniscript/decode.rs | 2 +- src/miniscript/lex.rs | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/expression.rs b/src/expression.rs index 990e8f627..25ee6370e 100644 --- a/src/expression.rs +++ b/src/expression.rs @@ -39,6 +39,7 @@ pub trait FromTree: Sized { fn from_tree(top: &Tree) -> Result; } +#[derive(Hash)] enum Found { Nothing, LBracket(usize), // Either a left ( or { diff --git a/src/interpreter/mod.rs b/src/interpreter/mod.rs index 2c91375d6..520f84546 100644 --- a/src/interpreter/mod.rs +++ b/src/interpreter/mod.rs @@ -57,7 +57,7 @@ pub struct Interpreter<'txin> { // Ecdsa and Schnorr signatures /// A type for representing signatures supported as of bitcoin core 22.0 -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum KeySigPair { /// A Full public key and corresponding Ecdsa signature Ecdsa(bitcoin::PublicKey, bitcoin::EcdsaSig), @@ -452,7 +452,7 @@ impl<'txin> Interpreter<'txin> { } /// Type of HashLock used for SatisfiedConstraint structure -#[derive(Copy, Clone, Debug, Eq, PartialEq)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] pub enum HashLockType { ///SHA 256 hashlock Sha256(sha256::Hash), @@ -467,7 +467,7 @@ pub enum HashLockType { /// A satisfied Miniscript condition (Signature, Hashlock, Timelock) /// 'intp represents the lifetime of descriptor and `stack represents /// the lifetime of witness -#[derive(Copy, Clone, Debug, Eq, PartialEq)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] pub enum SatisfiedConstraint { ///Public key and corresponding signature PublicKey { diff --git a/src/miniscript/decode.rs b/src/miniscript/decode.rs index 7715dd051..ddb750aab 100644 --- a/src/miniscript/decode.rs +++ b/src/miniscript/decode.rs @@ -96,7 +96,7 @@ mod private { impl Sealed for super::bitcoin::secp256k1::XOnlyPublicKey {} } -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, Hash)] enum NonTerm { Expression, WExpression, diff --git a/src/miniscript/lex.rs b/src/miniscript/lex.rs index a113824d3..f8ce1186c 100644 --- a/src/miniscript/lex.rs +++ b/src/miniscript/lex.rs @@ -25,7 +25,7 @@ use super::Error; use crate::prelude::*; /// Atom of a tokenized version of a script -#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] #[allow(missing_docs)] pub enum Token<'s> { BoolAnd,