Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependency on arrayvec #152

Merged
merged 11 commits into from
Apr 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 7 additions & 53 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,14 @@ jobs:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
# Work around https://github.com/actions/cache/issues/133#issuecomment-599102035
- run: sudo chown -R $(whoami):$(id -ng) ~/.cargo/
name: Fix perms on .cargo so we can restore the cache.
- name: Cache cargo
uses: actions/cache@v1
with:
path: ~/.cargo/
key: ${{ github.job }}
uses: Swatinem/rust-cache@v1
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
- run: rustup component add rustfmt
components: rustfmt
- uses: actions-rs/cargo@v1
with:
command: fmt
Expand Down Expand Up @@ -57,20 +51,8 @@ jobs:
target: x86_64-pc-windows-msvc
steps:
- uses: actions/checkout@v2
# Work around https://github.com/actions/cache/issues/133#issuecomment-599102035
- run: sudo chown -R $(whoami):$(id -ng) ~/.cargo/
name: Fix perms on .cargo so we can restore the cache.
if: "!contains(runner.os, 'windows')"
- name: Cache cargo
uses: actions/cache@v1
with:
path: ~/.cargo/
key: ${{ github.job }}-${{ runner.os }}-${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.toml') }}
- name: Cache cargo build
uses: actions/cache@v1
with:
path: target
key: ${{ github.job }}-${{ runner.os }}-${{ matrix.target }}-target-${{ hashFiles('**/Cargo.toml') }}
uses: Swatinem/rust-cache@v1
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
Expand All @@ -91,23 +73,12 @@ jobs:
rust:
- stable
- beta
- 1.41.1 #MSRV
- 1.48 #MSRV
fail-fast: false
steps:
- uses: actions/checkout@v2
# Work around https://github.com/actions/cache/issues/133#issuecomment-599102035
- run: sudo chown -R $(whoami):$(id -ng) ~/.cargo/
name: Fix perms on .cargo so we can restore the cache.
- name: Cache cargo
uses: actions/cache@v1
with:
path: ~/.cargo/
key: ${{ github.job }}-${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}-${{ matrix.rust }}
- name: Cache cargo build
uses: actions/cache@v1
with:
path: target
key: ${{ github.job }}-${{ runner.os }}-target-${{ hashFiles('**/Cargo.toml') }}-${{ matrix.rust }}
uses: Swatinem/rust-cache@v1
- uses: actions-rs/toolchain@v1
with:
profile: minimal
Expand All @@ -133,19 +104,8 @@ jobs:
- uses: actions/checkout@v2
with:
ref: ${{ matrix.ref }}
# Work around https://github.com/actions/cache/issues/133#issuecomment-599102035
- run: sudo chown -R $(whoami):$(id -ng) ~/.cargo/
name: Fix perms on .cargo so we can restore the cache.
- name: Cache cargo
uses: actions/cache@v1
with:
path: ~/.cargo/
key: ${{ github.job }}-${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}
- name: Cache cargo build
uses: actions/cache@v1
with:
path: target
key: ${{ github.job }}-${{ runner.os }}-target-${{ hashFiles('**/Cargo.toml') }}
uses: Swatinem/rust-cache@v1
- uses: actions-rs/toolchain@v1
with:
profile: minimal
Expand Down Expand Up @@ -174,14 +134,8 @@ jobs:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
# Work around https://github.com/actions/cache/issues/133#issuecomment-599102035
- run: sudo chown -R $(whoami):$(id -ng) ~/.cargo/
name: Fix perms on .cargo so we can restore the cache.
- name: Cache cargo
uses: actions/cache@v1
with:
path: ~/.cargo/
key: ${{ github.job }}
uses: Swatinem/rust-cache@v1
- name: Retrieve benchmark results
uses: actions/download-artifact@v1
with:
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## 0.13.0 (Unreleased)

### Public API changes

- [[#152](https://github.com/IronCoreLabs/recrypt-rs/pull/152)] Change MSRV to Rust 1.48.0

### Notable internal changes

- [[#152](https://github.com/IronCoreLabs/recrypt-rs/pull/152)] Remove dependency on `arrayvec`

## 0.12.0

### Public API changes
Expand Down
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "recrypt"
version = "0.12.0"
version = "0.13.0-pre"
authors = ["IronCore Labs <info@ironcorelabs.com>"]
readme = "README.md"
license = "AGPL-3.0-only"
Expand All @@ -25,7 +25,6 @@ rand_chacha = "~0.2.2"
sha2 = "~0.9"
num-traits = "~0.2"
lazy_static = "~1.4"
arrayvec = "~0.5"
#Disable all features for ed25519 and enable the proper ones down in the [features] section below
ed25519-dalek = { version="=1.0.1", default-features = false, features = ["std"] }
clear_on_drop = "~0.2"
Expand Down
31 changes: 9 additions & 22 deletions src/internal/bytedecoder.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::internal::ByteVector;
use arrayvec;
use arrayvec::ArrayVec;
use gridiron::fp_256::Fp256;
use gridiron::fp_480::Fp480;
use quick_error::quick_error;
use std::convert::From;
use std::convert::TryInto;
use std::result::Result;

/// Decode a ByteVector into an implementing type.
Expand All @@ -23,9 +22,13 @@ where
impl BytesDecoder for gridiron::fp_256::Monty {
const ENCODED_SIZE_BYTES: usize = 32;
fn decode(bytes: ByteVector) -> Result<Self, DecodeErr> {
let byte_arr: ArrayVec<[u8; Self::ENCODED_SIZE_BYTES]> = bytes.into_iter().collect();
let byte_arr: [u8; Self::ENCODED_SIZE_BYTES] = byte_arr.into_inner()?;
Result::Ok(Fp256::from(byte_arr).to_monty())
let byte_array: Result<[u8; Self::ENCODED_SIZE_BYTES], ByteVector> = bytes.try_into();
byte_array
.map(|array| Fp256::from(array).to_monty())
.map_err(|b| DecodeErr::BytesNotCorrectLength {
required_length: Self::ENCODED_SIZE_BYTES,
bad_bytes: b,
})
}
}

Expand All @@ -52,26 +55,10 @@ quick_error! {
BytesNotCorrectLength {
required_length: usize,
bad_bytes: ByteVector,
} {
}
BytesInvalid {
message: String,
bad_bytes: ByteVector,
}{}
}
}
}

/// Needed for error handing when ArrayVec.into_inner is called on an instance that is not
/// at capacity.
macro_rules! from_arrayvec_n { ($($n: expr), *) => {
$(impl From<arrayvec::ArrayVec<[u8; $n]>> for DecodeErr {
fn from(x: arrayvec::ArrayVec<[u8; $n]>) -> Self {
DecodeErr::BytesNotCorrectLength {
required_length: $n,
bad_bytes: x.to_vec(),
}
}
})+
}}

from_arrayvec_n! {32, 128, 384}
clintfred marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion src/internal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,7 @@ pub(crate) fn take_lock<T>(m: &Mutex<T>) -> MutexGuard<T> {
m.lock().unwrap_or_else(|e| {
let error = format!("Error when acquiring lock: {}", e);
error!("{}", error);
panic!(error);
panic!("{}", error);
})
}

Expand Down