File tree Expand file tree Collapse file tree 3 files changed +51
-1
lines changed Expand file tree Collapse file tree 3 files changed +51
-1
lines changed Original file line number Diff line number Diff line change @@ -33,3 +33,7 @@ path = "fuzzers/conditional_assign_i8.rs"
33
33
[[bin ]]
34
34
name = " conditional_assign_i128"
35
35
path = " fuzzers/conditional_assign_i128.rs"
36
+
37
+ [[bin ]]
38
+ name = " conditional_assign_array"
39
+ path = " fuzzers/conditional_assign_array.rs"
Original file line number Diff line number Diff line change
1
+ #![ no_main]
2
+
3
+ #[ macro_use]
4
+ extern crate libfuzzer_sys;
5
+ extern crate subtle;
6
+ extern crate core;
7
+
8
+ use core:: convert:: TryFrom ;
9
+
10
+ use subtle:: ConditionallySelectable ;
11
+
12
+ fuzz_target ! ( |data: & [ u8 ] | {
13
+ let chunk_size: usize = 16 ;
14
+
15
+ if data. len( ) % chunk_size != 0 {
16
+ return ;
17
+ }
18
+
19
+ for bytes in data. chunks( chunk_size) {
20
+ let mut x = [ 0u8 ; 16 ] ;
21
+ let y = <[ u8 ; 16 ] >:: try_from( bytes) . unwrap( ) ;
22
+
23
+ x. conditional_assign( & y, 0 . into( ) ) ;
24
+ assert_eq!( x, [ 0u8 ; 16 ] ) ;
25
+
26
+ x. conditional_assign( & y, 1 . into( ) ) ;
27
+ assert_eq!( x, y) ;
28
+ }
29
+ } ) ;
Original file line number Diff line number Diff line change 55
55
//!
56
56
//! ## Minimum Supported Rust Version
57
57
//!
58
- //! Rust **1.41 ** or higher.
58
+ //! Rust **1.51 ** or higher.
59
59
//!
60
60
//! Minimum supported Rust version can be changed in the future, but it will be done with a minor version bump.
61
61
//!
@@ -539,6 +539,23 @@ impl ConditionallySelectable for Choice {
539
539
}
540
540
}
541
541
542
+ impl < T , const N : usize > ConditionallySelectable for [ T ; N ]
543
+ where T : ConditionallySelectable
544
+ {
545
+ #[ inline]
546
+ fn conditional_select ( a : & Self , b : & Self , choice : Choice ) -> Self {
547
+ let mut output = * a;
548
+ output. conditional_assign ( b, choice) ;
549
+ output
550
+ }
551
+
552
+ fn conditional_assign ( & mut self , other : & Self , choice : Choice ) {
553
+ for ( a_i, b_i) in self . iter_mut ( ) . zip ( other) {
554
+ a_i. conditional_assign ( b_i, choice)
555
+ }
556
+ }
557
+ }
558
+
542
559
/// A type which can be conditionally negated in constant time.
543
560
///
544
561
/// # Note
You can’t perform that action at this time.
0 commit comments