7272//! let policy = builder.build();
7373//! ```
7474
75- use std :: collections:: HashMap ;
75+ use alloc :: { collections:: BTreeMap , string :: String , vec :: Vec } ;
7676
7777use crate :: crypto:: { Hash , PublicKey } ;
7878
@@ -93,13 +93,13 @@ pub use parsing::ParsePolicyError;
9393#[ derive( Debug , Eq , PartialEq ) ]
9494pub struct Policy {
9595 // logs keeps the list of log keys and URLs indexed by keyhash.
96- logs : HashMap < Hash , Entity > ,
96+ logs : BTreeMap < Hash , Entity > ,
9797
9898 // witnesses keeps the list of witness keys and URLs indexed by keyhash.
99- witnesses : HashMap < Hash , Entity > ,
99+ witnesses : BTreeMap < Hash , Entity > ,
100100
101101 // quorums keeps the quorum entries (witnesses and groups), indexed by name.
102- quorums : HashMap < String , Quorum > ,
102+ quorums : BTreeMap < String , Quorum > ,
103103
104104 // quorum is the quorum required by the policy. Invariant: if present, quorum must be an
105105 // existing key in quorums.
@@ -120,7 +120,7 @@ pub struct Witness {
120120}
121121
122122pub struct Logs < ' a > {
123- inner : std :: collections:: hash_map :: Iter < ' a , Hash , Entity > ,
123+ inner : alloc :: collections:: btree_map :: Iter < ' a , Hash , Entity > ,
124124}
125125
126126impl Iterator for Logs < ' _ > {
@@ -252,9 +252,9 @@ impl Default for PolicyBuilder {
252252impl PolicyBuilder {
253253 pub fn new ( ) -> Self {
254254 Self ( Policy {
255- logs : HashMap :: new ( ) ,
256- witnesses : HashMap :: new ( ) ,
257- quorums : HashMap :: new ( ) ,
255+ logs : BTreeMap :: new ( ) ,
256+ witnesses : BTreeMap :: new ( ) ,
257+ quorums : BTreeMap :: new ( ) ,
258258 quorum : None ,
259259 } )
260260 }
@@ -325,6 +325,7 @@ impl PolicyBuilder {
325325
326326#[ cfg( test) ]
327327mod tests {
328+ use alloc:: { string:: String , string:: ToString , vec} ;
328329 use hex_literal:: hex;
329330
330331 use super :: * ;
@@ -333,9 +334,9 @@ mod tests {
333334 fn build_empty_policy ( ) {
334335 let builder = PolicyBuilder :: new ( ) ;
335336 let expected = Policy {
336- logs : HashMap :: new ( ) ,
337- witnesses : HashMap :: new ( ) ,
338- quorums : HashMap :: new ( ) ,
337+ logs : BTreeMap :: new ( ) ,
338+ witnesses : BTreeMap :: new ( ) ,
339+ quorums : BTreeMap :: new ( ) ,
339340 quorum : None ,
340341 } ;
341342 assert_eq ! ( expected, builder. build( ) ) ;
@@ -379,7 +380,7 @@ mod tests {
379380 . unwrap ( ) ;
380381 builder. set_quorum ( String :: from ( "mygroup" ) ) . unwrap ( ) ;
381382 let expected = Policy {
382- logs : HashMap :: from ( [
383+ logs : BTreeMap :: from ( [
383384 (
384385 hex ! ( "e919506c3a798f2030f14046e39f03773c12b390e1010c95d2256d0ae594354e" ) . into ( ) ,
385386 Entity (
@@ -397,7 +398,7 @@ mod tests {
397398 ) ,
398399 ) ,
399400 ] ) ,
400- witnesses : HashMap :: from ( [
401+ witnesses : BTreeMap :: from ( [
401402 (
402403 hex ! ( "d9440882ae2bd57076d4da2e7a12d4b26e137d56116419a69f8d6969709ed747" ) . into ( ) ,
403404 Entity (
@@ -415,7 +416,7 @@ mod tests {
415416 ) ,
416417 ) ,
417418 ] ) ,
418- quorums : HashMap :: from ( [
419+ quorums : BTreeMap :: from ( [
419420 (
420421 "witness01" . into ( ) ,
421422 Quorum :: Witness (
0 commit comments