Skip to content

Commit

Permalink
Add from impl for int&int_prime groups
Browse files Browse the repository at this point in the history
  • Loading branch information
myl7 committed Jul 29, 2024
1 parent ec8c9e6 commit cb17827
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/group/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ macro_rules! decl_int_group {
}
}

impl From<$t> for $t_impl {
fn from(value: $t) -> Self {
$t_impl(value)
}
}

impl<const BLEN: usize> From<$t_impl> for [u8; BLEN] {
fn from(value: $t_impl) -> Self {
let mut bs = [0; BLEN];
Expand All @@ -78,6 +84,12 @@ macro_rules! decl_int_group {
bs
}
}

impl From<$t_impl> for $t {
fn from(value: $t_impl) -> Self {
value.0
}
}
};
}

Expand All @@ -86,9 +98,3 @@ decl_int_group!(u16, U16Group);
decl_int_group!(u32, U32Group);
decl_int_group!(u64, U64Group);
decl_int_group!(u128, U128Group);

decl_int_group!(i8, I8Group);
decl_int_group!(i16, I16Group);
decl_int_group!(i32, I32Group);
decl_int_group!(i64, I64Group);
decl_int_group!(i128, I128Group);
12 changes: 12 additions & 0 deletions src/group/int_prime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ macro_rules! decl_int_prime_group {
}
}

impl<const MOD: $t> From<$t> for $t_impl<MOD> {
fn from(value: $t) -> Self {
<$t_impl<MOD>>::new(value)
}
}

impl<const BLEN: usize, const MOD: $t> From<$t_impl<MOD>> for [u8; BLEN] {
fn from(value: $t_impl<MOD>) -> Self {
let mut bs = [0; BLEN];
Expand All @@ -102,6 +108,12 @@ macro_rules! decl_int_prime_group {
bs
}
}

impl<const MOD: $t> From<$t_impl<MOD>> for $t {
fn from(value: $t_impl<MOD>) -> Self {
value.0
}
}
};
}

Expand Down

0 comments on commit cb17827

Please sign in to comment.