-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from jymchng/pre-releases/0.2.0
Pre releases/0.2.0
- Loading branch information
Showing
31 changed files
with
2,311 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# CHANGELOG | ||
|
||
## 17 March 2024 | ||
<center><h1>V0.2.0 IS RELEASED</h1></center> | ||
|
||
1. `RTSecret<T, MEC>` is now available. `RTSecret<T, MEC>` is the runtime version of `Secret<T, MEC, EC>`. | ||
2. Substitute of the `Secret<S>` in `secrecy` crate is available as `SecrecySecret<T>` albeit with a different function signature of the method `.expose_secret(...)`. | ||
3. Following optimizations are done: | ||
|
||
a. Given the type parameter `MEC` as an unsigned type-level integer, the second field of `RTSecret<T, MEC>` will be one of the following Rust's primitive unsigned integer types, `u8`, `u16`, `u32` and `u64`, depending on the projected runtime value of `MEC`. | ||
|
||
For example, if `MEC` is `typenum::consts::U69`, then the second field of `RTSecret<T, MEC>` will be of type `u8`. This optimization is done because if `MEC` at runtime is projected to a value, e.g. 69, and the exposure counter, which is the second field of the type, will never exceed the `MEC`'s projected runtime value, then it only needs to be represented by an unsigned integer type (e.g. `u8`) that `MEC`'s projected runtime value (e.g. 69) is minimally representable by (since 69 < `u8::MAX` = 255). | ||
|
||
b. `SecrecySecret<T>` is the same size as `T`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,21 @@ | ||
#![no_std] | ||
#![doc = include_str!("../README.md")] | ||
#![cfg_attr(docsrs, feature(doc_auto_cfg))] | ||
// Apply #![recursion_limit = "256"] only if #![cfg(target_pointer_width = "128")] | ||
#![recursion_limit = "2048"] | ||
|
||
#[cfg(feature = "alloc")] | ||
extern crate alloc; | ||
|
||
// #[cfg(feature = "runtime-secret")] | ||
pub mod runtime; | ||
|
||
mod macros; | ||
mod secret; | ||
|
||
pub mod traits; | ||
pub mod types; | ||
|
||
pub mod prelude { | ||
pub use crate::secret::*; | ||
pub use crate::{runtime::*, secret::*, types::*}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
pub mod error; | ||
pub mod secret; | ||
pub use secret::*; | ||
pub mod traits; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use crate::traits::ChooseMinimallyRepresentableUInt; | ||
|
||
/// An error representing that the secret has been exposed more times than allowed. | ||
#[derive(Debug)] | ||
#[non_exhaustive] | ||
pub enum ExposeSecretError<MEC: ChooseMinimallyRepresentableUInt> { | ||
ExposeMoreThanMaximallyAllow(ExposeMoreThanMaximallyAllowError<MEC>), | ||
} | ||
|
||
/// An error representing that the secret has been exposed more times than allowed. | ||
#[derive(Debug)] | ||
pub struct ExposeMoreThanMaximallyAllowError<MEC: ChooseMinimallyRepresentableUInt> { | ||
pub mec: <MEC as ChooseMinimallyRepresentableUInt>::Output, | ||
pub ec: <MEC as ChooseMinimallyRepresentableUInt>::Output, | ||
} | ||
|
||
impl<MEC: ChooseMinimallyRepresentableUInt> core::fmt::Display | ||
for ExposeMoreThanMaximallyAllowError<MEC> | ||
{ | ||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
write!(f, "`Secret` is exposed more than what it is maximally allowed to; it is exposed for {} times and it is only allowed to be exposed for {} times", self.ec, self.mec) | ||
} | ||
} | ||
|
||
impl<MEC: ChooseMinimallyRepresentableUInt> core::fmt::Display for ExposeSecretError<MEC> { | ||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
match self { | ||
Self::ExposeMoreThanMaximallyAllow(err) => err.fmt(f), | ||
} | ||
} | ||
} |
Oops, something went wrong.