Skip to content

Commit

Permalink
Merge pull request #3075 from autonomys/minor-fixes
Browse files Browse the repository at this point in the history
Minor fixes
  • Loading branch information
nazar-pc authored Sep 30, 2024
2 parents 510da22 + a9c817d commit 2149a47
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 76 deletions.
74 changes: 0 additions & 74 deletions crates/subspace-core-primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1176,77 +1176,3 @@ impl SectorId {
Some(HistorySize::from(expiration_history_size))
}
}

/// A Vec<> that enforces the invariant that it cannot be empty.
#[derive(Debug, Clone, Encode, Decode, Eq, PartialEq)]
pub struct NonEmptyVec<T>(Vec<T>);

/// Error codes for `NonEmptyVec`.
#[derive(Debug)]
pub enum NonEmptyVecErr {
/// Tried to create with an empty Vec
EmptyVec,
}

#[allow(clippy::len_without_is_empty)]
impl<T: Clone> NonEmptyVec<T> {
/// Creates the Vec.
pub fn new(vec: Vec<T>) -> Result<Self, NonEmptyVecErr> {
if vec.is_empty() {
return Err(NonEmptyVecErr::EmptyVec);
}

Ok(Self(vec))
}

/// Creates the Vec with the entry.
pub fn new_with_entry(entry: T) -> Self {
Self(vec![entry])
}

/// Returns the number of entries.
pub fn len(&self) -> usize {
self.0.len()
}

/// Returns the slice of the entries.
pub fn as_slice(&self) -> &[T] {
self.0.as_slice()
}

/// Returns an iterator for the entries.
pub fn iter(&self) -> Box<dyn Iterator<Item = &T> + '_> {
Box::new(self.0.iter())
}

/// Returns a mutable iterator for the entries.
pub fn iter_mut(&mut self) -> Box<dyn Iterator<Item = &mut T> + '_> {
Box::new(self.0.iter_mut())
}

/// Returns the first entry.
pub fn first(&self) -> T {
self.0
.first()
.expect("NonEmptyVec::first(): collection cannot be empty")
.clone()
}

/// Returns the last entry.
pub fn last(&self) -> T {
self.0
.last()
.expect("NonEmptyVec::last(): collection cannot be empty")
.clone()
}

/// Adds an entry to the end.
pub fn push(&mut self, entry: T) {
self.0.push(entry);
}

/// Returns the entries in the collection.
pub fn to_vec(self) -> Vec<T> {
self.0
}
}
6 changes: 4 additions & 2 deletions crates/subspace-proof-of-time/src/aes.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! AES related functionality.

#[cfg(target_arch = "x86_64")]
#[cfg(all(feature = "std", target_arch = "x86_64"))]
mod x86_64;

#[cfg(not(feature = "std"))]
Expand All @@ -9,12 +9,14 @@ extern crate alloc;
use aes::cipher::array::Array;
use aes::cipher::{BlockCipherDecrypt, BlockCipherEncrypt, KeyInit};
use aes::Aes128;
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
use subspace_core_primitives::{PotCheckpoints, PotKey, PotOutput, PotSeed};

/// Creates the AES based proof.
#[inline(always)]
pub(crate) fn create(seed: PotSeed, key: PotKey, checkpoint_iterations: u32) -> PotCheckpoints {
#[cfg(target_arch = "x86_64")]
#[cfg(all(feature = "std", target_arch = "x86_64"))]
if std::is_x86_feature_detected!("aes") {
return unsafe { x86_64::create(seed.as_ref(), key.as_ref(), checkpoint_iterations) };
}
Expand Down

0 comments on commit 2149a47

Please sign in to comment.