pub struct VerifiedRandomness(/* private fields */);Expand description
Captured drand randomness from a successful verify CPI.
Wraps the raw [u8; 32] randomness in a #[must_use] newtype. This
closes a class of consumer bugs that ? extraction on a bare
Result<[u8; 32]> cannot catch: writing
alea_sdk::cpi::verify(...)?; discards the randomness silently with
no compiler warning, because ? extracts the Ok variant and Rust
happily drops array return values.
By wrapping in a #[must_use] struct, alea_sdk::cpi::verify(...)?;
produces a compile-time unused_must_use warning — the consumer is
forced to capture the result. Phase 4.5 T1-17 integration-audit fix.
§Usage
ⓘ
// Preferred — capture the bytes:
let randomness = alea_sdk::cpi::verify(/* … */)?.into_inner();
// Or keep the wrapper and read without moving:
let verified = alea_sdk::cpi::verify(/* … */)?;
let first_u64 = u64::from_le_bytes(
verified.as_bytes()[0..8].try_into().unwrap()
);Implementations§
Trait Implementations§
Source§impl AsRef<[u8]> for VerifiedRandomness
impl AsRef<[u8]> for VerifiedRandomness
Source§impl Clone for VerifiedRandomness
impl Clone for VerifiedRandomness
Source§fn clone(&self) -> VerifiedRandomness
fn clone(&self) -> VerifiedRandomness
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for VerifiedRandomness
impl Debug for VerifiedRandomness
Source§impl From<VerifiedRandomness> for [u8; 32]
impl From<VerifiedRandomness> for [u8; 32]
Source§fn from(v: VerifiedRandomness) -> Self
fn from(v: VerifiedRandomness) -> Self
Converts to this type from the input type.
Source§impl PartialEq for VerifiedRandomness
impl PartialEq for VerifiedRandomness
impl Copy for VerifiedRandomness
impl Eq for VerifiedRandomness
impl StructuralPartialEq for VerifiedRandomness
Auto Trait Implementations§
impl Freeze for VerifiedRandomness
impl RefUnwindSafe for VerifiedRandomness
impl Send for VerifiedRandomness
impl Sync for VerifiedRandomness
impl Unpin for VerifiedRandomness
impl UnsafeUnpin for VerifiedRandomness
impl UnwindSafe for VerifiedRandomness
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more