Explorar el Código

Use BTreeMap instead of HashMap to iterate over attributes in a deterministic order

We need the generated statements to be identical, not just equivalent
(e.g., the same statements in a different order) because the order of
the elements in the proof depends on the order of the statements.
Ian Goldberg hace 1 mes
padre
commit
eae9f392e5
Se han modificado 1 ficheros con 3 adiciones y 2 borrados
  1. 3 2
      cmz-core/src/lib.rs

+ 3 - 2
cmz-core/src/lib.rs

@@ -9,6 +9,7 @@
 
 use proc_macro2::TokenStream;
 use quote::{format_ident, quote, ToTokens};
+use std::collections::BTreeMap;
 use std::collections::HashMap;
 use syn::parse::{Parse, ParseStream, Result};
 use syn::punctuated::Punctuated;
@@ -107,7 +108,7 @@ struct CredSpec<ShowOrIssue: Parse, const VALID_OPTIONAL: bool> {
     // show that this credential is valid.  The default state of false
     // means we should always show that the credential is valid.
     valid_optional: bool,
-    attrs: HashMap<Ident, ShowOrIssue>,
+    attrs: BTreeMap<Ident, ShowOrIssue>,
 }
 
 impl<ShowOrIssue: Parse + Copy, const VALID_OPTIONAL: bool> Parse
@@ -127,7 +128,7 @@ impl<ShowOrIssue: Parse + Copy, const VALID_OPTIONAL: bool> Parse
         braced!(content in input);
         let attrspecs: Punctuated<AttrSpec<ShowOrIssue>, Token![,]> =
             content.parse_terminated(AttrSpec::<ShowOrIssue>::parse, Token![,])?;
-        let mut attrs: HashMap<Ident, ShowOrIssue> = HashMap::new();
+        let mut attrs: BTreeMap<Ident, ShowOrIssue> = BTreeMap::new();
         for attrspec in attrspecs.iter() {
             attrs.insert(attrspec.attr.clone(), attrspec.spec);
         }