@@ -33,14 +33,17 @@ pub(crate) fn validate_shares<S: IsShare>(shares: Vec<S>) -> Result<(u8, Vec<S>)
33
33
let mut result: Vec < S > = Vec :: with_capacity ( shares_count) ;
34
34
35
35
let mut k_compatibility_sets = HashMap :: new ( ) ;
36
+ let mut data_len_compatibility_sets = HashMap :: new ( ) ;
36
37
37
38
for share in shares {
38
- let ( id, threshold) = ( share. get_id ( ) , share. get_threshold ( ) ) ;
39
+ let ( id, threshold, data_len ) = ( share. get_id ( ) , share. get_threshold ( ) , share . get_data ( ) . len ( ) ) ;
39
40
40
41
if id < 1 {
41
42
bail ! ( ErrorKind :: ShareParsingInvalidShareId ( id) )
42
43
} else if threshold < 2 {
43
44
bail ! ( ErrorKind :: ShareParsingInvalidShareThreshold ( threshold, id) )
45
+ } else if data_len < 1 {
46
+ bail ! ( ErrorKind :: ShareParsingErrorEmptyShare ( id) )
44
47
}
45
48
46
49
k_compatibility_sets
@@ -53,9 +56,12 @@ pub(crate) fn validate_shares<S: IsShare>(shares: Vec<S>) -> Result<(u8, Vec<S>)
53
56
bail ! ( ErrorKind :: DuplicateShareId ( id) ) ;
54
57
}
55
58
56
- if share. get_data ( ) . is_empty ( ) {
57
- bail ! ( ErrorKind :: ShareParsingErrorEmptyShare ( id) )
58
- }
59
+ data_len_compatibility_sets
60
+ . entry ( data_len)
61
+ . or_insert_with ( HashSet :: new) ;
62
+ let data_len_set = data_len_compatibility_sets. get_mut ( & data_len) . unwrap ( ) ;
63
+ data_len_set. insert ( id) ;
64
+
59
65
60
66
result. push ( share) ;
61
67
}
@@ -84,6 +90,23 @@ pub(crate) fn validate_shares<S: IsShare>(shares: Vec<S>) -> Result<(u8, Vec<S>)
84
90
bail ! ( ErrorKind :: MissingShares ( shares_count, threshold) ) ;
85
91
}
86
92
93
+ // Validate share length consistency
94
+ let data_len_sets = data_len_compatibility_sets. keys ( ) . count ( ) ;
95
+
96
+ match data_len_sets {
97
+ 1 => { } // All shares have the same `data` field len
98
+ _ => {
99
+ bail ! {
100
+ ErrorKind :: IncompatibleDataLengths (
101
+ data_len_compatibility_sets
102
+ . values( )
103
+ . map( |x| x. to_owned( ) )
104
+ . collect( ) ,
105
+ )
106
+ }
107
+ }
108
+ }
109
+
87
110
Ok ( ( threshold, result) )
88
111
}
89
112
0 commit comments