Struct crypt_guard::KeyControl

source ·
pub struct KeyControl<T: KyberKeyFunctions> {
    pub public_key: Vec<u8>,
    pub secret_key: Vec<u8>,
    pub ciphertext: Vec<u8>,
    pub shared_secret: Vec<u8>,
    /* private fields */
}
Expand description

A structure to manage cryptographic keys and operations for the Kyber algorithm. It encapsulates the public key, secret key, ciphertext, and shared secret.

Fields§

§public_key: Vec<u8>§secret_key: Vec<u8>§ciphertext: Vec<u8>§shared_secret: Vec<u8>

Implementations§

source§

impl<T: KyberKeyFunctions> KeyControl<T>

source

pub fn new() -> Self

Constructs a new instance of KeyControl.

source

pub fn set_ciphertext(&mut self, cipher: Vec<u8>) -> Result<(), CryptError>

Sets the ciphertext for the KeyControl instance.

source

pub fn set_public_key(&mut self, public: Vec<u8>) -> Result<(), CryptError>

Sets the public key for the KeyControl instance.

source

pub fn set_secret_key(&mut self, sec: Vec<u8>) -> Result<(), CryptError>

Sets the secret key for the KeyControl instance.

source

pub fn get_key(&self, key: KeyTypes) -> Result<Key, CryptError>

Retrieves a specified key based on KeyTypes.

source

pub fn save(&self, key: KeyTypes, base_path: PathBuf) -> Result<(), CryptError>

Saves a specified key to a file at the given base path.

source

pub fn load(&self, key: KeyTypes, path: &Path) -> Result<Vec<u8>, CryptError>

Loads a specified key from a file.

source

pub fn public_key(&self) -> Result<Vec<u8>, CryptError>

Getter methods for public_key, secret_key, ciphertext, and shared_secret.

source

pub fn secret_key(&self) -> Result<Vec<u8>, CryptError>

source

pub fn ciphertext(&self) -> Result<Vec<u8>, CryptError>

source

pub fn shared_secret(&self) -> Result<Vec<u8>, CryptError>

source

pub fn encap(&self, public: &[u8]) -> Result<(Vec<u8>, Vec<u8>), CryptError>

Encapsulates a secret using a public key.

source

pub fn decap( &self, secret_key: &[u8], ciphertext: &[u8] ) -> Result<Vec<u8>, CryptError>

Decapsulates the ciphertext using a secret key to retrieve the shared secret.

Auto Trait Implementations§

§

impl<T> Freeze for KeyControl<T>

§

impl<T> RefUnwindSafe for KeyControl<T>
where T: RefUnwindSafe,

§

impl<T> Send for KeyControl<T>
where T: Send,

§

impl<T> Sync for KeyControl<T>
where T: Sync,

§

impl<T> Unpin for KeyControl<T>
where T: Unpin,

§

impl<T> UnwindSafe for KeyControl<T>
where T: UnwindSafe,

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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V