Struct keyutils::Key

source ·
pub struct Key { /* private fields */ }
Expand description

Representation of a kernel key.

Implementations§

source§

impl Key

source

pub unsafe fn new(id: KeyringSerial) -> Self

Instantiate a key from an ID.

This is unsafe because no key is known to exist with the given ID.

Safety

This method assumes that the given serial is a valid key ID at the kernel level.

source

pub fn request<'s, 'a, K, D, I, T>( description: D, info: I, target: T ) -> Result<Self>where K: KeyType, D: Borrow<K::Description>, I: Into<Option<&'s str>>, T: Into<Option<TargetKeyring<'a>>>,

Requests a key with the given type and description by searching the thread, process, and session keyrings.

If it is not found, the info string (if provided) will be handed off to /sbin/request-key to generate the key.

If target is given, the found keyring will be linked into it. If target is not given and a new key is constructed due to the request, it will be linked into the default keyring (see Keyring::set_default).

source

pub fn is_keytype<K>(&self) -> Result<bool>where K: KeyType,

Determine whether the key is of a specific implementation or not.

source

pub fn update<K, P>(&mut self, payload: P) -> Result<()>where K: KeyType, P: Borrow<K::Payload>,

Update the payload in the key.

source

pub fn revoke(self) -> Result<()>

Revokes the key. Requires write permission on the key.

source

pub fn chown(&mut self, uid: uid_t) -> Result<()>

Change the user which owns the key.

Requires the setattr permission on the key and the SysAdmin capability to change it to anything other than the current user.

source

pub fn chgrp(&mut self, gid: gid_t) -> Result<()>

Change the group which owns the key.

Requires the setattr permission on the key and the SysAdmin capability to change it to anything other than a group of which the current user is a member.

source

pub fn set_permissions(&mut self, perms: Permission) -> Result<()>

Set the permissions on the key.

Requires the setattr permission on the key and the SysAdmin capability if the current user does not own the key.

source

pub fn description(&self) -> Result<Description>

Retrieve metadata about the key.

Panics

If the kernel returns malformed data, the parser will panic.

source

pub fn read(&self) -> Result<Vec<u8>>

Read the payload of the key. Requires read permissions on the key.

source

pub fn set_timeout(&mut self, timeout: Duration) -> Result<()>

Set an expiration timer on the keyring to timeout.

Any partial seconds are ignored. A timeout of 0 means “no expiration”. Requires the setattr permission on the key.

source

pub fn security(&self) -> Result<String>

The security context of the key.

Depends on the security manager loaded into the kernel (e.g., SELinux or AppArmor).

source

pub fn invalidate(self) -> Result<()>

Invalidates the key and schedules it for removal.

Requires the search permission on the key.

source

pub fn manage(&mut self) -> Result<KeyManager>

Create an object to manage a key request.

Before a key may be managed on a thread, an authorization key must be attached to an available thread keyring.

Only one key may be managed on a thread at a time. Managing a second key will invalidate any previous KeyManager constructions.

See KeyManager::request_key_auth_key.

source

pub fn compute_dh(private: &Key, prime: &Key, base: &Key) -> Result<Vec<u8>>

Compute a Diffie-Hellman prime for use as a shared secret or public key.

source

pub fn compute_dh_kdf<O>( private: &Key, prime: &Key, base: &Key, hash: KeyctlHash, other: Option<O> ) -> Result<Vec<u8>>where O: AsRef<[u8]>,

Compute a key from a Diffie-Hellman shared secret.

The base key contains the remote public key to create a share secret which is then processed using hash.

See SP800-56A for details.

source

pub fn pkey_query_support( &self, query: &PublicKeyOptions ) -> Result<KeySupportInfo>

Query which optionally supported features may be used by the key.

source

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

Encrypt data using the key.

source

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

Decrypt data using the key.

source

pub fn sign(&self, options: &PublicKeyOptions, data: &[u8]) -> Result<Vec<u8>>

Sign data using the key.

source

pub fn verify( &self, options: &PublicKeyOptions, data: &[u8], signature: &[u8] ) -> Result<bool>

Verify a signature of the data using the key.

Trait Implementations§

source§

impl Clone for Key

source§

fn clone(&self) -> Key

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Key

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl PartialEq<Key> for Key

source§

fn eq(&self, other: &Key) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Key

source§

impl StructuralEq for Key

source§

impl StructuralPartialEq for Key

Auto Trait Implementations§

§

impl RefUnwindSafe for Key

§

impl Send for Key

§

impl Sync for Key

§

impl Unpin for Key

§

impl UnwindSafe for Key

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ManuallyDropMut for T

§

type Ret = ManuallyDrop<T>

source§

fn manually_drop_mut<'__>(&'__ mut self) -> &'__ mut ManuallyDrop<T>

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere 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 Twhere 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.