Struct KeyRing

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

Interface to perform keyring operations. Used to locate, create, search, add, and link/unlink keys to & from keyrings.

Implementations§

Source§

impl KeyRing

Source

pub fn from_special_id( id: KeyRingIdentifier, create: bool, ) -> Result<Self, KeyError>

Obtain a KeyRing from its special identifier.

If the create argument is true, then this method will attempt to create the keyring. Otherwise it will only succeed if the keyring already exists and is valid.

Internally this uses KEYCTL_GET_KEYRING_ID to resolve a keyrings real ID from the special identifier.

Source

pub fn get_persistent(link_with: KeyRingIdentifier) -> Result<Self, KeyError>

Get the persistent keyring (persistent-keyring(7)) of the current user and link it to a specified keyring.

If the call is successful, a link to the persistent keyring is added to the keyring specified in the link_with argument.

The caller must have write permission on the keyring.

The persistent keyring will be created by the kernel if it does not yet exist.

Each time the KeyRing::get_persistent operation is performed, the persistent keyring will have its expiration timeout reset to the value in:

/proc/sys/kernel/keys/persistent_keyring_expiry

Should the timeout be reached, the persistent keyring will be removed and everything it pins can then be garbage collected.

Persistent keyrings were added to Linux in kernel version 3.13.

Source

pub fn metadata(&self) -> Result<Metadata, KeyError>

Obtain information describing the attributes of this keyring.

The keyring must grant the caller view permission.

Source

pub fn add_key<D: AsRef<str> + ?Sized, S: AsRef<[u8]> + ?Sized>( &self, description: &D, secret: &S, ) -> Result<Key, KeyError>

Creates or updates a key of the given type and description, instantiates it with the payload of length plen, attaches it to the User keyring.

If the destination keyring already contains a key that matches the specified type and description, then, if the key type supports it, that key will be updated rather than a new key being created; if not, a new key (with a different ID) will be created and it will displace the link to the extant key from the keyring.

Source

pub fn search<D: AsRef<str> + ?Sized>( &self, description: &D, ) -> Result<Key, KeyError>

Search for a key in the keyring tree, starting with this keyring as the head, returning its ID.

The search is performed breadth-first and recursively.

The source keyring must grant search permission to the caller. When performing the recursive search, only keyrings that grant the caller search permission will be searched. Only keys with for which the caller has search permission can be found.

If the key is found, its ID is returned as the function result.

Obtain a list of the keys/keyrings linked to this keyring.

This method allocates, but you can provide a maximum number of entries to read. Each returned entry is 4 bytes.

The keyring must either grant the caller read permission, or grant the caller search permission.

Create a link from this keyring to a key.

If a key with the same type and description is already linked in the keyring, then that key is displaced from the keyring.

Before creating the link, the kernel checks the nesting of the keyrings and returns appropriate errors if the link would produce a cycle or if the nesting of keyrings would be too deep (The limit on the nesting of keyrings is determined by the kernel constant KEYRING_SEARCH_MAX_DEPTH, defined with the value 6, and is necessary to prevent overflows on the kernel stack when recursively searching keyrings).

The caller must have link permission on the key being added and write permission on the keyring.

Unlink a key from this keyring.

If the key is not currently linked into the keyring, an error results. If the last link to a key is removed, then that key will be scheduled for destruction.

The caller must have write permission on the keyring from which the key is being removed.

Source

pub fn clear(&self) -> Result<(), KeyError>

Clear the contents of (i.e., unlink all keys from) this keyring.

The caller must have write permission on the keyring.

Trait Implementations§

Source§

impl Clone for KeyRing

Source§

fn clone(&self) -> KeyRing

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 KeyRing

Source§

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

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

impl PartialEq<KeyRing> for &LinkNode

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<KeyRing> for LinkNode

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq for KeyRing

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for KeyRing

Source§

impl Eq for KeyRing

Source§

impl StructuralPartialEq for KeyRing

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

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