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

feat(crypto)!: make engine and rng shared #5

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions crates/aranya-afc-util/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function create_bidi_channel(
pub(crate) fn create_bidi_channel<E: Engine>(
&mut self,
_ctx: &CommandContext<'_>,
eng: &mut E,
eng: &E,
parent_cmd_id: Id,
our_enc_key_id: EncryptionKeyId,
our_id: UserId,
Expand Down Expand Up @@ -130,7 +130,7 @@ function create_uni_channel(
pub(crate) fn create_uni_channel<E: Engine>(
&mut self,
_ctx: &CommandContext<'_>,
eng: &mut E,
eng: &E,
parent_cmd_id: Id,
author_enc_key_id: EncryptionKeyId,
their_pk: Vec<u8>,
Expand Down
8 changes: 4 additions & 4 deletions crates/aranya-afc-util/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl<S: KeyStore> Handler<S> {
/// [`AranyaState`][aranya_fast_channels::AranyaState].
pub fn bidi_channel_created<E, SK, OK>(
&mut self,
eng: &mut E,
eng: &E,
effect: &BidiChannelCreated<'_>,
) -> Result<BidiKeys<SK, OK>, Error>
where
Expand Down Expand Up @@ -87,7 +87,7 @@ impl<S: KeyStore> Handler<S> {
/// [`AranyaState`][aranya_fast_channels::AranyaState].
pub fn bidi_channel_received<E, SK, OK>(
&mut self,
eng: &mut E,
eng: &E,
effect: &BidiChannelReceived<'_>,
) -> Result<BidiKeys<SK, OK>, Error>
where
Expand Down Expand Up @@ -200,7 +200,7 @@ impl<S: KeyStore> Handler<S> {
/// [`AranyaState`][aranya_fast_channels::AranyaState].
pub fn uni_channel_created<E, SK, OK>(
&mut self,
eng: &mut E,
eng: &E,
effect: &UniChannelCreated<'_>,
) -> Result<UniKey<SK, OK>, Error>
where
Expand Down Expand Up @@ -249,7 +249,7 @@ impl<S: KeyStore> Handler<S> {
/// [`AranyaState`][aranya_fast_channels::AranyaState].
pub fn uni_channel_received<E, SK, OK>(
&mut self,
eng: &mut E,
eng: &E,
effect: &UniChannelReceived<'_>,
) -> Result<UniKey<SK, OK>, Error>
where
Expand Down
30 changes: 15 additions & 15 deletions crates/aranya-afc-util/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,12 @@ pub struct User<T: TestImpl> {

impl<T: TestImpl> User<T> {
/// Creates a new [`User`].
pub fn new(mut eng: T::Engine, afc: T::Afc, aranya: T::Aranya, mut store: T::Store) -> Self {
let user_id = IdentityKey::<<T::Engine as Engine>::CS>::new(&mut eng)
pub fn new(eng: T::Engine, afc: T::Afc, aranya: T::Aranya, mut store: T::Store) -> Self {
let user_id = IdentityKey::<<T::Engine as Engine>::CS>::new(&eng)
.id()
.expect("user ID should be valid");

let enc_sk = EncryptionKey::new(&mut eng);
let enc_sk = EncryptionKey::new(&eng);
let enc_key_id = enc_sk.id().expect("encryption key ID should be valid");
let enc_pk = encode_enc_pk(
&enc_sk
Expand Down Expand Up @@ -395,7 +395,7 @@ where
let mut peer = T::new();

let label = Label::new(42);
let parent_cmd_id = Id::random(&mut Rng);
let parent_cmd_id = Id::random(&Rng);
let ctx = CommandContext::Action(ActionContext {
name: "CreateBidiChannel",
head_id: parent_cmd_id,
Expand All @@ -406,7 +406,7 @@ where
.ffi
.create_bidi_channel(
&ctx,
&mut author.eng,
&author.eng,
parent_cmd_id,
author.enc_key_id,
author.user_id,
Expand All @@ -422,7 +422,7 @@ where
let keys = author
.handler
.bidi_channel_created(
&mut author.eng,
&author.eng,
&BidiChannelCreated {
parent_cmd_id,
author_id: author.user_id,
Expand All @@ -449,7 +449,7 @@ where
let keys = peer
.handler
.bidi_channel_received(
&mut peer.eng,
&peer.eng,
&BidiChannelReceived {
parent_cmd_id,
author_id: author.user_id,
Expand Down Expand Up @@ -501,7 +501,7 @@ where
let mut peer = T::new();

let label = Label::new(42);
let parent_cmd_id = Id::random(&mut Rng);
let parent_cmd_id = Id::random(&Rng);
let ctx = CommandContext::Action(ActionContext {
name: "CreateSealOnlyChannel",
head_id: parent_cmd_id,
Expand All @@ -512,7 +512,7 @@ where
.ffi
.create_uni_channel(
&ctx,
&mut author.eng,
&author.eng,
parent_cmd_id,
author.enc_key_id,
peer.enc_pk.clone(),
Expand All @@ -528,7 +528,7 @@ where
let keys = author
.handler
.uni_channel_created(
&mut author.eng,
&author.eng,
&UniChannelCreated {
parent_cmd_id,
author_id: author.user_id,
Expand Down Expand Up @@ -557,7 +557,7 @@ where
let keys = peer
.handler
.uni_channel_received(
&mut peer.eng,
&peer.eng,
&UniChannelReceived {
parent_cmd_id,
author_id: author.user_id,
Expand Down Expand Up @@ -609,7 +609,7 @@ where
let mut peer = T::new(); // seal only

let label = Label::new(42);
let parent_cmd_id = Id::random(&mut Rng);
let parent_cmd_id = Id::random(&Rng);
let ctx = CommandContext::Action(ActionContext {
name: "CreateUniOnlyChannel",
head_id: parent_cmd_id,
Expand All @@ -620,7 +620,7 @@ where
.ffi
.create_uni_channel(
&ctx,
&mut author.eng,
&author.eng,
parent_cmd_id,
author.enc_key_id,
peer.enc_pk.clone(),
Expand All @@ -636,7 +636,7 @@ where
let keys = author
.handler
.uni_channel_created(
&mut author.eng,
&author.eng,
&UniChannelCreated {
parent_cmd_id,
author_id: author.user_id,
Expand Down Expand Up @@ -665,7 +665,7 @@ where
let keys = peer
.handler
.uni_channel_received(
&mut peer.eng,
&peer.eng,
&UniChannelReceived {
parent_cmd_id,
author_id: author.user_id,
Expand Down
2 changes: 1 addition & 1 deletion crates/aranya-capi-core/src/internal/conv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ tuple_impls! { A B C D E F G H I J K L M N O P Q R S T U V W X }
tuple_impls! { A B C D E F G H I J K L M N O P Q R S T U V W X Y }
tuple_impls! { A B C D E F G H I J K L M N O P Q R S T U V W X Y Z }

impl<'a, T> TryFromFfi for &'a T {
impl<T> TryFromFfi for &T {
type Ffi = *const T;
type Error = InvalidPtr;
unsafe fn try_from_ffi(val: Self::Ffi) -> Result<Self, Self::Error> {
Expand Down
4 changes: 2 additions & 2 deletions crates/aranya-crypto-ffi/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function sign(
pub(crate) fn sign<E: Engine>(
&self,
ctx: &CommandContext<'_>,
eng: &mut E,
eng: &E,
our_sign_sk_id: Id,
command_bytes: Vec<u8>,
) -> Result<Signed, Error> {
Expand Down Expand Up @@ -155,7 +155,7 @@ function verify(
pub(crate) fn verify<E: Engine>(
&self,
ctx: &CommandContext<'_>,
_eng: &mut E,
_eng: &E,
author_sign_pk: Vec<u8>,
parent_id: Id,
command_bytes: Vec<u8>,
Expand Down
Loading
Loading