Skip to content

Commit

Permalink
Export SecretBox and CanBeZeroizedOnDrop, and add some docs
Browse files Browse the repository at this point in the history
  • Loading branch information
fjarri committed Jun 21, 2021
1 parent bc81807 commit d0c7c76
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions umbral-pre/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ pub use keys::{PublicKey, SecretKey, SecretKeyFactory, SecretKeyFactoryError, Si
pub use pre::{
decrypt_original, decrypt_reencrypted, encrypt, generate_kfrags, reencrypt, ReencryptionError,
};
pub use secret_box::{CanBeZeroizedOnDrop, SecretBox};
pub use traits::{
ConstructionError, DeserializableFromArray, DeserializationError, HasTypeName,
RepresentableAsArray, SerializableToArray, SerializableToSecretArray, SizeMismatchError,
Expand Down
10 changes: 8 additions & 2 deletions umbral-pre/src/secret_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ use generic_array::{ArrayLength, GenericArray};
use zeroize::Zeroize;

/// This is a helper trait for [`SecretBox`], asserting that the type implementing it
/// can either be zeroized (in which case [`ensure_zeroized_on_drop`] is implemented accordingly),
/// or is zeroized on drop (in which case [`ensure_zeroized_on_drop`] does nothing).
/// can either be zeroized
/// (in which case [`ensure_zeroized_on_drop`](`CanBeZeroizedOnDrop::ensure_zeroized_on_drop`)
/// is implemented accordingly),
/// or is zeroized on drop
/// (in which case [`ensure_zeroized_on_drop`](`CanBeZeroizedOnDrop::ensure_zeroized_on_drop`)
/// does nothing).
/// In other words, with this trait we are sure that one way or the other,
/// on drop of [`SecretBox`] the contents are zeroized.
///
Expand Down Expand Up @@ -74,10 +78,12 @@ where
Self(Box::new(val))
}

/// Returns an immutable reference to the secret data.
pub fn as_secret(&self) -> &T {
self.0.as_ref()
}

/// Returns a mutable reference to the secret data.
pub fn as_mut_secret(&mut self) -> &mut T {
self.0.as_mut()
}
Expand Down

0 comments on commit d0c7c76

Please sign in to comment.