pub struct Encryption { /* private fields */ }Expand description
Encryption settings for a Bark encrypted push.
The algorithm, mode, key, and IV mirror Bark’s CryptoSettingFields.
Create this value with Encryption::new to generate a fresh IV for CBC or
GCM automatically, or with Encryption::with_iv when an exact IV is needed
for tests or interoperability checks.
The IV is not secret. For CBC and GCM this crate serializes it as the
top-level APNs iv field so Bark’s notification service extension can use it
instead of the IV stored in the app settings.
Implementations§
Source§impl Encryption
impl Encryption
Sourcepub fn new<K>(
algorithm: EncryptionAlgorithm,
mode: EncryptionMode,
key: K,
) -> Result<Self>
pub fn new<K>( algorithm: EncryptionAlgorithm, mode: EncryptionMode, key: K, ) -> Result<Self>
Creates encryption settings and generates a mode-appropriate IV.
CBC generates a 16-byte ASCII IV, GCM generates a 12-byte ASCII IV, and ECB stores no IV. The key is validated immediately against the selected algorithm’s required byte length.
§Errors
Returns Error::InvalidKeyLength if the key length does not match the
algorithm, or Error::Random if the operating system cannot provide
randomness for an IV.
Sourcepub fn with_iv<K, I>(
algorithm: EncryptionAlgorithm,
mode: EncryptionMode,
key: K,
iv: I,
) -> Result<Self>
pub fn with_iv<K, I>( algorithm: EncryptionAlgorithm, mode: EncryptionMode, key: K, iv: I, ) -> Result<Self>
Creates encryption settings with an explicit IV.
Use this when reproducing Bark documentation examples or when the caller
deliberately wants to control the IV. Normal sends should prefer
Encryption::new so CBC and GCM do not reuse IVs.
For ECB, pass an empty string because Bark’s ECB mode does not use an IV.
§Errors
Returns Error::InvalidKeyLength when the key has the wrong length, or
Error::InvalidIvLength when the IV length does not match the selected
mode.
Sourcepub const fn algorithm(&self) -> EncryptionAlgorithm
pub const fn algorithm(&self) -> EncryptionAlgorithm
Returns the selected Bark encryption algorithm.
Sourcepub const fn mode(&self) -> EncryptionMode
pub const fn mode(&self) -> EncryptionMode
Returns the selected Bark encryption mode.
Trait Implementations§
Source§impl Clone for Encryption
impl Clone for Encryption
Source§fn clone(&self) -> Encryption
fn clone(&self) -> Encryption
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Encryption
impl Debug for Encryption
impl Eq for Encryption
Source§impl PartialEq for Encryption
impl PartialEq for Encryption
impl StructuralPartialEq for Encryption
Auto Trait Implementations§
impl Freeze for Encryption
impl RefUnwindSafe for Encryption
impl Send for Encryption
impl Sync for Encryption
impl Unpin for Encryption
impl UnsafeUnpin for Encryption
impl UnwindSafe for Encryption
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.