mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
rust/pv_core: Remove unnecessary mirrored constants
They add no value and code outside the crate does not need those constants. Reduces unnecessary constant duplication. Introduce an error for to large Add-Secret requests and check for this to render those contsnts fully unnecessary for the API. Signed-off-by: Steffen Eiden <seiden@linux.ibm.com> Reviewed-by: Julian Ruess <julianr@linux.ibm.com> Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
committed by
Jan Höppner
parent
9eab43994b
commit
a2e556858a
@@ -44,6 +44,9 @@ pub enum Error {
|
||||
#[error("Input does not contain an add-secret request")]
|
||||
NoAsrcb,
|
||||
|
||||
#[error("Input add-secret request is larger than 8k")]
|
||||
AscrbLarge,
|
||||
|
||||
#[error("Input contains unsupported user-data type: {0:#06x}")]
|
||||
UnsupportedUserData(u16),
|
||||
|
||||
|
||||
@@ -161,21 +161,6 @@ impl UvDevice {
|
||||
const RC_MORE_DATA: u16 = 0x0100;
|
||||
const PATH: &'static str = "/dev/uv";
|
||||
|
||||
/// IOCTL number for the info UVC
|
||||
pub const INFO_NR: u8 = ffi::UVIO_IOCTL_UVDEV_INFO_NR;
|
||||
/// IOCTL number for the attestation UVC
|
||||
pub const ATTESTATION_NR: u8 = ffi::UVIO_IOCTL_ATT_NR;
|
||||
/// IOCTL number for the add secret UVC
|
||||
pub const ADD_SECRET_NR: u8 = ffi::UVIO_IOCTL_ADD_SECRET_NR;
|
||||
/// IOCTL number for the list secret UVC
|
||||
pub const LIST_SECRET_NR: u8 = ffi::UVIO_IOCTL_LIST_SECRETS_NR;
|
||||
/// IOCTL number for the lock ksecret UVC
|
||||
pub const LOCK_SECRET_NR: u8 = ffi::UVIO_IOCTL_LOCK_SECRETS_NR;
|
||||
/// Maximum length for add-secret requests
|
||||
pub const ADD_SECRET_MAX_LEN: usize = ffi::UVIO_ADD_SECRET_MAX_LEN;
|
||||
/// Size of the buffer for list secret requests
|
||||
pub const LIST_SECRETS_LEN: usize = ffi::UVIO_LIST_SECRETS_LEN;
|
||||
|
||||
/// Open the uvdevice located at `/dev/uv`
|
||||
///
|
||||
/// # Errors
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2023
|
||||
|
||||
use super::ffi::uvio_uvdev_info;
|
||||
use super::ffi::{self, uvio_uvdev_info};
|
||||
use crate::{
|
||||
misc::{Flags, Lsb0Flags64},
|
||||
uv::{uv_ioctl, UvCmd, UvDevice},
|
||||
@@ -50,7 +50,7 @@ impl UvDeviceInfo {
|
||||
Ok(_) => Ok(cmd.into()),
|
||||
Err(crate::Error::Io(e)) if e.raw_os_error() == Some(libc::ENOTTY) => {
|
||||
let mut supp_uvio_cmds = Lsb0Flags64::default();
|
||||
supp_uvio_cmds.set_bit(UvDevice::ATTESTATION_NR);
|
||||
supp_uvio_cmds.set_bit(ffi::UVIO_IOCTL_ATT_NR);
|
||||
|
||||
Ok(Self {
|
||||
supp_uvio_cmds,
|
||||
@@ -72,7 +72,7 @@ impl From<uvio_uvdev_info> for UvDeviceInfo {
|
||||
}
|
||||
|
||||
impl UvCmd for uvio_uvdev_info {
|
||||
const UV_IOCTL_NR: u8 = UvDevice::INFO_NR;
|
||||
const UV_IOCTL_NR: u8 = ffi::UVIO_IOCTL_UVDEV_INFO_NR;
|
||||
|
||||
fn data(&mut self) -> Option<&mut [u8]> {
|
||||
Some(self.as_bytes_mut())
|
||||
@@ -85,11 +85,11 @@ impl UvCmd for uvio_uvdev_info {
|
||||
|
||||
fn nr_as_string(nr: u8) -> Option<&'static str> {
|
||||
match nr {
|
||||
UvDevice::INFO_NR => Some("Info"),
|
||||
UvDevice::ATTESTATION_NR => Some("Attestation"),
|
||||
UvDevice::ADD_SECRET_NR => Some("Add Secret"),
|
||||
UvDevice::LIST_SECRET_NR => Some("List Secrets"),
|
||||
UvDevice::LOCK_SECRET_NR => Some("Lock Secret Store"),
|
||||
ffi::UVIO_IOCTL_UVDEV_INFO_NR => Some("Info"),
|
||||
ffi::UVIO_IOCTL_ATT_NR => Some("Attestation"),
|
||||
ffi::UVIO_IOCTL_ADD_SECRET_NR => Some("Add Secret"),
|
||||
ffi::UVIO_IOCTL_LIST_SECRETS_NR => Some("List Secrets"),
|
||||
ffi::UVIO_IOCTL_LOCK_SECRETS_NR => Some("Lock Secret Store"),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2023
|
||||
|
||||
use super::ffi;
|
||||
use crate::{
|
||||
assert_size,
|
||||
misc::to_u16,
|
||||
@@ -42,7 +43,7 @@ impl Default for ListCmd {
|
||||
}
|
||||
|
||||
impl UvCmd for ListCmd {
|
||||
const UV_IOCTL_NR: u8 = UvDevice::LIST_SECRET_NR;
|
||||
const UV_IOCTL_NR: u8 = ffi::UVIO_IOCTL_LIST_SECRETS_NR;
|
||||
|
||||
fn data(&mut self) -> Option<&mut [u8]> {
|
||||
Some(self.0.as_mut_slice())
|
||||
@@ -70,6 +71,10 @@ impl AddCmd {
|
||||
let mut data = Vec::with_capacity(PAGESIZE);
|
||||
bin_add_secret_req.read_to_end(&mut data)?;
|
||||
|
||||
if data.len() > ffi::UVIO_ADD_SECRET_MAX_LEN {
|
||||
return Err(Error::AscrbLarge);
|
||||
}
|
||||
|
||||
if !AddSecretMagic::starts_with_magic(&data[..6]) {
|
||||
return Err(Error::NoAsrcb);
|
||||
}
|
||||
@@ -78,7 +83,7 @@ impl AddCmd {
|
||||
}
|
||||
|
||||
impl UvCmd for AddCmd {
|
||||
const UV_IOCTL_NR: u8 = UvDevice::ADD_SECRET_NR;
|
||||
const UV_IOCTL_NR: u8 = ffi::UVIO_IOCTL_ADD_SECRET_NR;
|
||||
|
||||
fn data(&mut self) -> Option<&mut [u8]> {
|
||||
Some(&mut self.0)
|
||||
@@ -112,7 +117,7 @@ impl UvCmd for AddCmd {
|
||||
/// request to modify the secret store will fail.
|
||||
pub struct LockCmd;
|
||||
impl UvCmd for LockCmd {
|
||||
const UV_IOCTL_NR: u8 = UvDevice::LOCK_SECRET_NR;
|
||||
const UV_IOCTL_NR: u8 = ffi::UVIO_IOCTL_LOCK_SECRETS_NR;
|
||||
|
||||
fn rc_fmt(&self, rc: u16, _rrc: u16) -> Option<&'static str> {
|
||||
match rc {
|
||||
|
||||
Reference in New Issue
Block a user