MCPcopy Create free account
hub / github.com/RustCrypto/utils / CtAssignSlice

Interface CtAssignSlice

ctutils/src/traits/ct_assign.rs:38–54  ·  view source on GitHub ↗

Implementing this trait enables use of the [`CtAssign`] trait for `[T]` where `T` is the `Self` type implementing the trait, via a blanket impl. It needs to be a separate trait from [`CtAssign`] because we need to be able to impl [`CtAssign`] for `[T]` which is `?Sized`.

Source from the content-addressed store, hash-verified

36/// It needs to be a separate trait from [`CtAssign`] because we need to be able to impl
37/// [`CtAssign`] for `[T]` which is `?Sized`.
38pub trait CtAssignSlice: CtAssign + Sized {
39 /// Conditionally assign `src` to `dst` if `choice` is [`Choice::TRUE`], or leave it unchanged
40 /// for [`Choice::FALSE`].
41 fn ct_assign_slice(dst: &mut [Self], src: &[Self], choice: Choice) {
42 assert_eq!(
43 dst.len(),
44 src.len(),
45 "source slice length ({}) does not match destination slice length ({})",
46 src.len(),
47 dst.len()
48 );
49
50 for (a, b) in dst.iter_mut().zip(src) {
51 a.ct_assign(b, choice);
52 }
53 }
54}
55
56impl<T: CtAssignSlice> CtAssign for [T] {
57 fn ct_assign(&mut self, src: &[T], choice: Choice) {

Callers

nothing calls this directly

Implementers 3

ct_option.rsctutils/src/ct_option.rs
choice.rsctutils/src/choice.rs
ct_assign.rsctutils/src/traits/ct_assign.rs

Calls

no outgoing calls

Tested by

no test coverage detected