Enum linux_keyutils::KeyError
source · pub enum KeyError {
Show 15 variants
AccessDenied,
QuotaExceeded,
BadAddress,
InvalidArguments,
KeyExpired,
KeyRevoked,
KeyRejected,
KeyringDoesNotExist,
KeyDoesNotExist,
OutOfMemory,
InvalidDescription,
InvalidIdentifier,
OperationNotSupported,
WriteError,
Unknown(i32),
}
Expand description
Error type for this library, optionally implements std::error::Error
.
Variants§
AccessDenied
The keyring wasn’t available for modification by the user.
QuotaExceeded
The key quota for this user would be exceeded by creating this key or linking it to the keyring.
BadAddress
One or more of type, description, and payload points outside process’s accessible address space.
InvalidArguments
Provided bad arguments
KeyExpired
The keyring has expired.
KeyRevoked
The keyring has been revoked.
KeyRejected
The attempt to generate a new key was rejected.
KeyringDoesNotExist
The keyring doesn’t exist.
KeyDoesNotExist
They key does not exist
OutOfMemory
Insufficient memory to create a key.
InvalidDescription
Invalid Description
InvalidIdentifier
An invalid identifier was returned
OperationNotSupported
Operation not supported
WriteError
Write to destination failed
Unknown(i32)
Unknown - catch all, return this instead of panicing
Implementations§
source§impl KeyError
impl KeyError
sourcepub fn from_errno() -> KeyError
pub fn from_errno() -> KeyError
Obtain the KeyError derived from checking errno
Examples found in repository?
src/ffi/functions.rs (line 50)
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
pub(crate) fn add_key(
ktype: KeyType,
keyring: libc::c_ulong,
description: &str,
payload: Option<&[u8]>,
) -> Result<KeySerialId, KeyError> {
// Perform conversion into a c string
let description = CString::new(description).or(Err(KeyError::InvalidDescription))?;
// When creating keyrings the payload will be NULL
let (payload, plen) = match payload {
Some(p) => (p.as_ptr(), p.len()),
None => (core::ptr::null(), 0),
};
// Perform the actual system call
let res = unsafe {
libc::syscall(
libc::SYS_add_key,
Into::<&'static CStr>::into(ktype).as_ptr(),
description.as_ptr(),
payload,
plen as libc::size_t,
keyring as u32,
)
};
// Return the underlying error
if res < 0 {
return Err(KeyError::from_errno());
}
// Otherwise return the ID
Ok(KeySerialId::new(
res.try_into().or(Err(KeyError::InvalidIdentifier))?,
))
}
/// keyctl() allows user-space programs to perform key manipulation.
///
/// The operation performed by keyctl() is determined by the value of the operation argument.
/// Each of these operations is wrapped by the KeyCtl interface (provided by the this crate)
/// into individual functions (noted below) to permit the compiler to check types.
pub(crate) fn keyctl_impl(
operation: KeyCtlOperation,
arg2: libc::c_ulong,
arg3: libc::c_ulong,
arg4: libc::c_ulong,
arg5: libc::c_ulong,
) -> Result<libc::c_ulong, KeyError> {
// Perform the actual system call
let res = unsafe { libc::syscall(libc::SYS_keyctl, operation as u32, arg2, arg3, arg4, arg5) };
// Return the underlying error
if res < 0 {
return Err(KeyError::from_errno());
}
// Otherwise return the result
res.try_into().or(Err(KeyError::InvalidIdentifier))
}
Trait Implementations§
source§impl Ord for KeyError
impl Ord for KeyError
source§impl PartialEq<KeyError> for KeyError
impl PartialEq<KeyError> for KeyError
source§impl PartialOrd<KeyError> for KeyError
impl PartialOrd<KeyError> for KeyError
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read more