Shield

Struct Shield 

Source
pub struct Shield { /* private fields */ }
Expand description

EXPTIME-secure symmetric encryption.

Uses password-derived keys with PBKDF2 and encrypts using a SHA256-based stream cipher with HMAC-SHA256 authentication. Breaking requires 2^256 operations - no shortcut exists.

Key material is securely zeroized from memory when dropped.

Implementations§

Source§

impl Shield

Source

pub fn new(password: &str, service: &str) -> Self

Create a new Shield instance from password and service name.

§Arguments
  • password - User’s password
  • service - Service identifier (e.g., “github.com”)
§Example
use shield_core::Shield;
let shield = Shield::new("my_password", "example.com");
Source

pub fn with_key(key: [u8; 32]) -> Self

Create Shield with a pre-shared key (no password derivation).

Source

pub fn encrypt(&self, plaintext: &[u8]) -> Result<Vec<u8>>

Encrypt data.

Returns: nonce(16) || ciphertext || mac(16)

§Errors

Returns error if random generation fails.

Source

pub fn encrypt_with_key(key: &[u8; 32], plaintext: &[u8]) -> Result<Vec<u8>>

Encrypt with explicit key.

Source

pub fn decrypt(&self, encrypted: &[u8]) -> Result<Vec<u8>>

Decrypt and verify data.

§Errors

Returns error if MAC verification fails or ciphertext is malformed.

Source

pub fn decrypt_with_key(key: &[u8; 32], encrypted: &[u8]) -> Result<Vec<u8>>

Decrypt with explicit key.

Source

pub fn key(&self) -> &[u8; 32]

Get the derived key (for testing/debugging).

Trait Implementations§

Source§

impl Drop for Shield

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Zeroize for Shield

Source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.

Auto Trait Implementations§

§

impl Freeze for Shield

§

impl RefUnwindSafe for Shield

§

impl Send for Shield

§

impl Sync for Shield

§

impl Unpin for Shield

§

impl UnwindSafe for Shield

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.