@@ -4,26 +4,25 @@ use super::*;
44#[ derive( Clone , Debug , Deserialize , PartialEq , Serialize ) ]
55#[ serde( deny_unknown_fields, rename_all = "kebab-case" ) ]
66pub struct Note {
7- #[ serde_as( as = "MapPreventDuplicates<_, _>" ) ]
8- pub signatures : BTreeMap < PublicKey , Signature > ,
7+ #[ serde_as( as = "SetPreventDuplicates< _>" ) ]
8+ pub signatures : BTreeSet < Signature > ,
99 #[ serde( default , skip_serializing_if = "is_default" ) ]
1010 pub time : Option < u128 > ,
1111}
1212
1313impl Note {
14- pub ( crate ) fn from_message (
15- message : Message ,
16- public_key : PublicKey ,
17- signature : Signature ,
18- ) -> Self {
14+ pub ( crate ) fn from_message ( message : Message , signature : Signature ) -> Self {
1915 Self {
20- signatures : [ ( public_key , signature) ] . into ( ) ,
16+ signatures : [ signature] . into ( ) ,
2117 time : message. time ,
2218 }
2319 }
2420
25- pub ( crate ) fn has_signature ( & self , public_key : PublicKey ) -> bool {
26- self . signatures . contains_key ( & public_key)
21+ pub fn has_signature ( & self , public_key : PublicKey ) -> bool {
22+ self
23+ . signatures
24+ . iter ( )
25+ . any ( |signature| signature. public_key ( ) == public_key)
2726 }
2827
2928 pub ( crate ) fn message ( & self , fingerprint : Fingerprint ) -> Message {
@@ -35,8 +34,8 @@ impl Note {
3534
3635 pub ( crate ) fn verify ( & self , fingerprint : Fingerprint ) -> Result < u64 > {
3736 let serialized = self . message ( fingerprint) . serialize ( ) ;
38- for ( public_key , signature) in & self . signatures {
39- public_key . verify ( & serialized, signature ) ?;
37+ for signature in & self . signatures {
38+ signature . verify ( & serialized) ?;
4039 }
4140 Ok ( self . signatures . len ( ) . into_u64 ( ) )
4241 }
@@ -49,7 +48,7 @@ mod tests {
4948 #[ test]
5049 fn duplicate_fields_are_rejected ( ) {
5150 assert_eq ! (
52- serde_json:: from_str:: <Note >( r#"{"signatures":{} ,"signatures":{} }"# )
51+ serde_json:: from_str:: <Note >( r#"{"signatures":[] ,"signatures":[] }"# )
5352 . unwrap_err( )
5453 . to_string( ) ,
5554 "duplicate field `signatures` at line 1 column 29" ,
@@ -59,28 +58,26 @@ mod tests {
5958 #[ test]
6059 fn duplicate_signatures_are_rejected ( ) {
6160 let json = format ! (
62- r#"{{"signatures":{{"{}":"{}","{}":"{}"}}}}"# ,
63- test:: PUBLIC_KEY ,
61+ r#"{{"signatures":["{}","{}"]}}"# ,
6462 test:: SIGNATURE ,
65- test:: PUBLIC_KEY ,
6663 test:: SIGNATURE ,
6764 ) ;
6865
6966 assert_matches_regex ! {
7067 serde_json:: from_str:: <Note >( & json) . unwrap_err( ) . to_string( ) ,
71- r"invalid entry: found duplicate key at line 1 column \d+" ,
68+ r"invalid entry: found duplicate value at line 1 column \d+" ,
7269 }
7370 }
7471
7572 #[ test]
7673 fn optional_fields_are_not_serialized ( ) {
7774 assert_eq ! (
7875 serde_json:: to_string( & Note {
79- signatures: BTreeMap :: new( ) ,
76+ signatures: BTreeSet :: new( ) ,
8077 time: None ,
8178 } )
8279 . unwrap( ) ,
83- r#"{"signatures":{} }"# ,
80+ r#"{"signatures":[] }"# ,
8481 ) ;
8582 }
8683}
0 commit comments