diff --git a/services/com/src/api.rs b/services/com/src/api.rs index 59ba5a309..8b128ad19 100644 --- a/services/com/src/api.rs +++ b/services/com/src/api.rs @@ -1,3 +1,6 @@ +mod rkyv_enum; +pub(crate) use rkyv_enum::*; + // NOTE: the use of ComState "verbs" as commands is not meant as a 1:1 mapping of commands // It's just a convenient abuse of already-defined constants. However, it's intended that // the COM server on the SoC side abstracts much of the EC bus complexity away. @@ -43,23 +46,6 @@ impl Into<[usize; 2]> for BattStats { } } -#[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] -pub(crate) enum FlashOp { - /// erase a region defined by (address, len) - Erase(u32, u32), - /// Send up to 1kiB of data at a time. This reduces messaging overhead and makes - /// programming more efficient, while taking full advantage of the 1280-deep receive FIFO on the EC. - /// Address + up to 4 pages. page 0 is at address, page 1 is at address + 256, etc. - /// Pages stored as None are skipped, yet the address pointer is still incremented. - Program(u32, [Option<[u8; 256]>; 4]), - /// Read a data at the `u32` address specified. - Verify(u32, [u8; 256]), -} -#[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] -pub(crate) enum FlashResult { - Pass, - Fail, -} #[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] pub(crate) struct FlashRecord { /// identifier to validate that we're authorized to do this diff --git a/services/com/src/api/rkyv_enum.rs b/services/com/src/api/rkyv_enum.rs new file mode 100644 index 000000000..3ff76a458 --- /dev/null +++ b/services/com/src/api/rkyv_enum.rs @@ -0,0 +1,31 @@ +// As of Rust 1.64.0: +// +// Rkyv-derived enums throw warnings that rkyv::Archive derived enums are never used +// and I can't figure out how to make them go away. Since they spam the build log, +// rkyv-derived enums are now isolated to their own file with a file-wide `dead_code` +// allow on top. +// +// This might be a temporary compiler regression, or it could just +// be yet another indicator that it's time to upgrade rkyv. However, we are waiting +// until rkyv hits 0.8 (the "shouldn't ever change again but still not sure enough +// for 1.0") release until we rework the entire system to chase the latest rkyv. +// As of now, the current version is 0.7.x and there isn't a timeline yet for 0.8. +#![allow(dead_code)] + +#[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] +pub(crate) enum FlashOp { + /// erase a region defined by (address, len) + Erase(u32, u32), + /// Send up to 1kiB of data at a time. This reduces messaging overhead and makes + /// programming more efficient, while taking full advantage of the 1280-deep receive FIFO on the EC. + /// Address + up to 4 pages. page 0 is at address, page 1 is at address + 256, etc. + /// Pages stored as None are skipped, yet the address pointer is still incremented. + Program(u32, [Option<[u8; 256]>; 4]), + /// Read a data at the `u32` address specified. + Verify(u32, [u8; 256]), +} +#[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] +pub(crate) enum FlashResult { + Pass, + Fail, +} \ No newline at end of file diff --git a/services/engine-25519/src/api.rs b/services/engine-25519/src/api.rs index 1ca97eb72..cf7b867be 100644 --- a/services/engine-25519/src/api.rs +++ b/services/engine-25519/src/api.rs @@ -53,6 +53,9 @@ pub struct MontgomeryJob { pub scalar: [u8; 32], } +mod rkyv_enum; +pub use rkyv_enum::*; + #[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)] pub(crate) enum Opcode { /// Runs a job, if the server is not already occupied @@ -83,19 +86,6 @@ pub(crate) enum Return { Quit, } - -#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] -pub enum JobResult { - /// returns a copy of the entire register file as a result - Result([u32; RF_SIZE_IN_U32]), - SingleResult([u8; 32]), - Started, - EngineUnavailable, - NotAsyncObject, // attempt to run an async job on an object that was setup for sync jobs - IllegalOpcodeException, - SuspendError, -} - #[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)] pub(crate) enum SusResOps { /// Suspend/resume callback diff --git a/services/engine-25519/src/api/rkyv_enum.rs b/services/engine-25519/src/api/rkyv_enum.rs new file mode 100644 index 000000000..89c6be724 --- /dev/null +++ b/services/engine-25519/src/api/rkyv_enum.rs @@ -0,0 +1,26 @@ +// As of Rust 1.64.0: +// +// Rkyv-derived enums throw warnings that rkyv::Archive derived enums are never used +// and I can't figure out how to make them go away. Since they spam the build log, +// rkyv-derived enums are now isolated to their own file with a file-wide `dead_code` +// allow on top. +// +// This might be a temporary compiler regression, or it could just +// be yet another indicator that it's time to upgrade rkyv. However, we are waiting +// until rkyv hits 0.8 (the "shouldn't ever change again but still not sure enough +// for 1.0") release until we rework the entire system to chase the latest rkyv. +// As of now, the current version is 0.7.x and there isn't a timeline yet for 0.8. + +#![allow(dead_code)] + +#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] +pub enum JobResult { + /// returns a copy of the entire register file as a result + Result([u32; crate::RF_SIZE_IN_U32]), + SingleResult([u8; 32]), + Started, + EngineUnavailable, + NotAsyncObject, // attempt to run an async job on an object that was setup for sync jobs + IllegalOpcodeException, + SuspendError, +} diff --git a/services/engine-sha512/src/api.rs b/services/engine-sha512/src/api.rs index 9262e7a60..cb523ab79 100644 --- a/services/engine-sha512/src/api.rs +++ b/services/engine-sha512/src/api.rs @@ -1,13 +1,6 @@ pub(crate) const SERVER_NAME_SHA512: &str = "_Sha512 hardware accelerator server_"; - -#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] -pub(crate) enum Sha2Result { - Sha512Result([u8; 64]), - Sha512Trunc256Result([u8; 32]), - SuspendError, - Uninitialized, - IdMismatch, -} +mod rkyv_enum; +pub use rkyv_enum::*; #[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] pub(crate) struct Sha2Finalize { diff --git a/services/engine-sha512/src/api/rkyv_enum.rs b/services/engine-sha512/src/api/rkyv_enum.rs new file mode 100644 index 000000000..e5ebbe054 --- /dev/null +++ b/services/engine-sha512/src/api/rkyv_enum.rs @@ -0,0 +1,22 @@ +// As of Rust 1.64.0: +// +// Rkyv-derived enums throw warnings that rkyv::Archive derived enums are never used +// and I can't figure out how to make them go away. Since they spam the build log, +// rkyv-derived enums are now isolated to their own file with a file-wide `dead_code` +// allow on top. +// +// This might be a temporary compiler regression, or it could just +// be yet another indicator that it's time to upgrade rkyv. However, we are waiting +// until rkyv hits 0.8 (the "shouldn't ever change again but still not sure enough +// for 1.0") release until we rework the entire system to chase the latest rkyv. +// As of now, the current version is 0.7.x and there isn't a timeline yet for 0.8. + +#![allow(dead_code)] +#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] +pub enum Sha2Result { + Sha512Result([u8; 64]), + Sha512Trunc256Result([u8; 32]), + SuspendError, + Uninitialized, + IdMismatch, +} \ No newline at end of file diff --git a/services/gam/src/api.rs b/services/gam/src/api.rs index 19cd0e933..3b86e8265 100644 --- a/services/gam/src/api.rs +++ b/services/gam/src/api.rs @@ -1,18 +1,14 @@ -use graphics_server::api::{Rectangle, TextView, Line, RoundedRectangle, Circle, Point, Gid}; +mod rkyv_enum; +// note: many enums in the API are isolated to this file. +pub use rkyv_enum::*; + +use graphics_server::api::{Point, Gid}; #[cfg(feature="ditherpunk")] use graphics_server::api::Tile; use xous_ipc::String; pub(crate) const SERVER_NAME_GAM: &str = "_Graphical Abstraction Manager_"; -#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone)] -pub enum GamObjectType { - Line(Line), - Circ(Circle), - Rect(Rectangle), - RoundRect(RoundedRectangle), -} - #[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone)] pub struct GamObject { pub canvas: Gid, @@ -207,32 +203,10 @@ pub(crate) enum Opcode { Bip39Suggestions = 32, } -#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] -pub(crate) enum Return { - UxToken(Option<[u32; 4]>), - RenderReturn(TextView), - SetCanvasBoundsReturn(SetCanvasBoundsRequest), - ContentCanvasReturn(Option), - Failure, - NotCurrentlyDrawable, -} - // small wart -- we have to reset the size of a modal to max size for resize computations // reveal the max size globally, since it's a constant pub const MODAL_Y_MAX: i16 = 350; // in absolute screen coords, not relative to top pad -#[derive(Debug, Eq, PartialEq, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] -pub(crate) enum MenuMgrOp { - // incoming is one of these ops - AddItem, - InsertItem(usize), - DeleteItem, - SetIndex(usize), - Quit, - // response must be one of these - Ok, - Err, -} #[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, PartialEq, Eq)] pub enum ActivationResult { Success, @@ -250,15 +224,6 @@ pub(crate) struct MenuManagement { pub(crate) op: MenuMgrOp, } -#[allow(dead_code)] // here until Memory types are implemented -#[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] -pub enum MenuPayload { - /// memorized scalar payload - Scalar([u32; 4]), - /// this a nebulous-but-TBD maybe way of bodging in a more complicated record, which would involve - /// casting this memorized, static payload into a Buffer and passing it on. Let's not worry too much about it for now, it's mostly apirational... - Memory(([u8; 256], usize)), -} #[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] pub struct MenuItem { pub name: String::<64>, diff --git a/services/gam/src/api/rkyv_enum.rs b/services/gam/src/api/rkyv_enum.rs new file mode 100644 index 000000000..64b7c2ee6 --- /dev/null +++ b/services/gam/src/api/rkyv_enum.rs @@ -0,0 +1,57 @@ +// As of Rust 1.64.0: +// +// Rkyv-derived enums throw warnings that rkyv::Archive derived enums are never used +// and I can't figure out how to make them go away. Since they spam the build log, +// rkyv-derived enums are now isolated to their own file with a file-wide `dead_code` +// allow on top. +// +// This might be a temporary compiler regression, or it could just +// be yet another indicator that it's time to upgrade rkyv. However, we are waiting +// until rkyv hits 0.8 (the "shouldn't ever change again but still not sure enough +// for 1.0") release until we rework the entire system to chase the latest rkyv. +// As of now, the current version is 0.7.x and there isn't a timeline yet for 0.8. +#![allow(dead_code)] + +use graphics_server::api::{Rectangle, TextView, Line, RoundedRectangle, Circle}; +use crate::*; + +#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone)] +pub enum GamObjectType { + Line(Line), + Circ(Circle), + Rect(Rectangle), + RoundRect(RoundedRectangle), +} + +#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] +pub(crate) enum Return { + UxToken(Option<[u32; 4]>), + RenderReturn(TextView), + SetCanvasBoundsReturn(SetCanvasBoundsRequest), + ContentCanvasReturn(Option), + Failure, + NotCurrentlyDrawable, +} + +#[derive(Debug, Eq, PartialEq, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] +pub(crate) enum MenuMgrOp { + // incoming is one of these ops + AddItem, + InsertItem(usize), + DeleteItem, + SetIndex(usize), + Quit, + // response must be one of these + Ok, + Err, +} + +#[allow(dead_code)] // here until Memory types are implemented +#[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] +pub enum MenuPayload { + /// memorized scalar payload + Scalar([u32; 4]), + /// this a nebulous-but-TBD maybe way of bodging in a more complicated record, which would involve + /// casting this memorized, static payload into a Buffer and passing it on. Let's not worry too much about it for now, it's mostly apirational... + Memory(([u8; 256], usize)), +} diff --git a/services/ime-plugin-api/src/lib.rs b/services/ime-plugin-api/src/lib.rs index 724f1679c..9c63a1a43 100644 --- a/services/ime-plugin-api/src/lib.rs +++ b/services/ime-plugin-api/src/lib.rs @@ -1,5 +1,8 @@ #![cfg_attr(target_os = "none", no_std)] +mod rkyv_enum; +pub use rkyv_enum::*; + use num_traits::{FromPrimitive, ToPrimitive}; use xous::{send_message, Message, CID}; use xous_ipc::{Buffer, String}; @@ -83,12 +86,6 @@ pub enum Opcode { Quit, } -#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] -pub enum Return { - Prediction(Prediction), - Failure, -} - pub trait PredictionApi { fn get_prediction_triggers(&self) -> Result; fn unpick(&self) -> Result<(), xous::Error>; diff --git a/services/ime-plugin-api/src/rkyv_enum.rs b/services/ime-plugin-api/src/rkyv_enum.rs new file mode 100644 index 000000000..954e34131 --- /dev/null +++ b/services/ime-plugin-api/src/rkyv_enum.rs @@ -0,0 +1,19 @@ +// As of Rust 1.64.0: +// +// Rkyv-derived enums throw warnings that rkyv::Archive derived enums are never used +// and I can't figure out how to make them go away. Since they spam the build log, +// rkyv-derived enums are now isolated to their own file with a file-wide `dead_code` +// allow on top. +// +// This might be a temporary compiler regression, or it could just +// be yet another indicator that it's time to upgrade rkyv. However, we are waiting +// until rkyv hits 0.8 (the "shouldn't ever change again but still not sure enough +// for 1.0") release until we rework the entire system to chase the latest rkyv. +// As of now, the current version is 0.7.x and there isn't a timeline yet for 0.8. +#![allow(dead_code)] + +#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] +pub enum Return { + Prediction(crate::Prediction), + Failure, +} diff --git a/services/net/src/api.rs b/services/net/src/api.rs index 4b68693aa..4419fd1d8 100644 --- a/services/net/src/api.rs +++ b/services/net/src/api.rs @@ -6,10 +6,12 @@ pub use ping::NetPingCallback; #[allow(unused_imports)] pub(crate) use tcp::*; +pub mod rkyv_enum; +pub use rkyv_enum::*; + use com::SsidRecord; use rkyv::{Archive, Deserialize, Serialize}; use smoltcp::wire::IpAddress; -use std::convert::TryInto; use std::fmt; use std::fmt::Debug; use std::io::Write; @@ -375,15 +377,6 @@ pub(crate) struct SsidList { pub(crate) list: [Option; 32], } -#[derive(Debug, Archive, Serialize, Deserialize, Copy, Clone)] -pub enum XousServerId { - /// A SID that is shared directly with the Net crate; a private, single-use SID for best security - PrivateSid([u32; 4]), - /// A name that needs to be looked up with XousNames. Easier to implement, but less secure as it requires - /// an open connection slot that could be abused by other processes. - ServerName(xous_ipc::String<64>), -} - /// These opcodes are reserved for private SIDs shared from a DNS server to /// reconfigure DNS on IP change/update. #[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)] @@ -413,20 +406,6 @@ pub(crate) enum NetCallback { Drop, } -#[derive(Debug, Archive, Serialize, Deserialize, Copy, Clone, PartialEq, Eq)] -#[repr(C, u16)] -pub(crate) enum NetMemResponse { - Ok, - Sent(u16), - OutOfMemory, - SocketInUse, - AccessDenied, - Invalid, - Finished, - LibraryError, - AlreadyUsed, -} - #[repr(C)] #[derive(Debug)] pub enum NetError { @@ -457,65 +436,6 @@ impl From for NetSocketAddr { } } -#[derive(Archive, Serialize, Deserialize, Copy, Clone)] -pub enum NetIpAddr { - Ipv4([u8; 4]), - Ipv6([u8; 16]), -} -impl From for NetIpAddr { - fn from(other: SocketAddr) -> NetIpAddr { - match other { - SocketAddr::V4(sav4) => NetIpAddr::Ipv4(sav4.ip().octets()), - SocketAddr::V6(sav6) => NetIpAddr::Ipv6(sav6.ip().octets()), - } - } -} -impl From for NetIpAddr { - fn from(other: IpAddress) -> NetIpAddr { - match other { - IpAddress::Ipv4(ipv4) => NetIpAddr::Ipv4(ipv4.0), - IpAddress::Ipv6(ipv6) => NetIpAddr::Ipv6(ipv6.0), - _ => { - panic!("Invalid IpAddress") - } - } - } -} -impl From for NetIpAddr { - fn from(other: IpAddr) -> NetIpAddr { - match other { - IpAddr::V4(ipv4) => NetIpAddr::Ipv4(ipv4.octets()), - IpAddr::V6(ipv6) => NetIpAddr::Ipv6(ipv6.octets()), - } - } -} -impl From for IpAddr { - fn from(other: NetIpAddr) -> IpAddr { - match other { - NetIpAddr::Ipv4(octets) => IpAddr::V4(Ipv4Addr::from(octets)), - NetIpAddr::Ipv6(octets) => IpAddr::V6(Ipv6Addr::from(octets)), - } - } -} -impl From for IpAddress { - fn from(other: NetIpAddr) -> IpAddress { - match other { - NetIpAddr::Ipv4([a, b, c, d]) => { - IpAddress::Ipv4(smoltcp::wire::Ipv4Address::new(a, b, c, d)) - } - NetIpAddr::Ipv6(ipv6) => IpAddress::Ipv6(smoltcp::wire::Ipv6Address::new( - u16::from_be_bytes(ipv6[0..1].try_into().unwrap()), - u16::from_be_bytes(ipv6[2..3].try_into().unwrap()), - u16::from_be_bytes(ipv6[4..5].try_into().unwrap()), - u16::from_be_bytes(ipv6[6..7].try_into().unwrap()), - u16::from_be_bytes(ipv6[8..9].try_into().unwrap()), - u16::from_be_bytes(ipv6[10..11].try_into().unwrap()), - u16::from_be_bytes(ipv6[12..13].try_into().unwrap()), - u16::from_be_bytes(ipv6[14..15].try_into().unwrap()), - )), - } - } -} #[allow(dead_code)] pub fn ipaddress_to_ipaddr(other: IpAddress) -> IpAddr { match other { diff --git a/services/net/src/api/rkyv_enum.rs b/services/net/src/api/rkyv_enum.rs new file mode 100644 index 000000000..b2c4f72ef --- /dev/null +++ b/services/net/src/api/rkyv_enum.rs @@ -0,0 +1,114 @@ +// As of Rust 1.64.0: +// +// Rkyv-derived enums throw warnings that rkyv::Archive derived enums are never used +// and I can't figure out how to make them go away. Since they spam the build log, +// rkyv-derived enums are now isolated to their own file with a file-wide `dead_code` +// allow on top. +// +// This might be a temporary compiler regression, or it could just +// be yet another indicator that it's time to upgrade rkyv. However, we are waiting +// until rkyv hits 0.8 (the "shouldn't ever change again but still not sure enough +// for 1.0") release until we rework the entire system to chase the latest rkyv. +// As of now, the current version is 0.7.x and there isn't a timeline yet for 0.8. + +#![allow(dead_code)] +use rkyv::{Archive, Deserialize, Serialize}; +use smoltcp::wire::IpAddress; +use std::fmt::Debug; +use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr}; +use std::convert::TryInto; + +#[derive(Debug, Archive, Serialize, Deserialize, Copy, Clone)] +pub enum XousServerId { + /// A SID that is shared directly with the Net crate; a private, single-use SID for best security + PrivateSid([u32; 4]), + /// A name that needs to be looked up with XousNames. Easier to implement, but less secure as it requires + /// an open connection slot that could be abused by other processes. + ServerName(xous_ipc::String<64>), +} + +#[derive(Debug, Archive, Serialize, Deserialize, Copy, Clone, PartialEq, Eq)] +#[repr(C, u16)] +pub(crate) enum NetMemResponse { + Ok, + Sent(u16), + OutOfMemory, + SocketInUse, + AccessDenied, + Invalid, + Finished, + LibraryError, + AlreadyUsed, +} + +#[derive(Archive, Serialize, Deserialize, Copy, Clone)] +pub enum NetIpAddr { + Ipv4([u8; 4]), + Ipv6([u8; 16]), +} +impl From for NetIpAddr { + fn from(other: SocketAddr) -> NetIpAddr { + match other { + SocketAddr::V4(sav4) => NetIpAddr::Ipv4(sav4.ip().octets()), + SocketAddr::V6(sav6) => NetIpAddr::Ipv6(sav6.ip().octets()), + } + } +} +impl From for NetIpAddr { + fn from(other: IpAddress) -> NetIpAddr { + match other { + IpAddress::Ipv4(ipv4) => NetIpAddr::Ipv4(ipv4.0), + IpAddress::Ipv6(ipv6) => NetIpAddr::Ipv6(ipv6.0), + _ => { + panic!("Invalid IpAddress") + } + } + } +} +impl From for NetIpAddr { + fn from(other: IpAddr) -> NetIpAddr { + match other { + IpAddr::V4(ipv4) => NetIpAddr::Ipv4(ipv4.octets()), + IpAddr::V6(ipv6) => NetIpAddr::Ipv6(ipv6.octets()), + } + } +} +impl From for IpAddr { + fn from(other: NetIpAddr) -> IpAddr { + match other { + NetIpAddr::Ipv4(octets) => IpAddr::V4(Ipv4Addr::from(octets)), + NetIpAddr::Ipv6(octets) => IpAddr::V6(Ipv6Addr::from(octets)), + } + } +} +impl From for IpAddress { + fn from(other: NetIpAddr) -> IpAddress { + match other { + NetIpAddr::Ipv4([a, b, c, d]) => { + IpAddress::Ipv4(smoltcp::wire::Ipv4Address::new(a, b, c, d)) + } + NetIpAddr::Ipv6(ipv6) => IpAddress::Ipv6(smoltcp::wire::Ipv6Address::new( + u16::from_be_bytes(ipv6[0..1].try_into().unwrap()), + u16::from_be_bytes(ipv6[2..3].try_into().unwrap()), + u16::from_be_bytes(ipv6[4..5].try_into().unwrap()), + u16::from_be_bytes(ipv6[6..7].try_into().unwrap()), + u16::from_be_bytes(ipv6[8..9].try_into().unwrap()), + u16::from_be_bytes(ipv6[10..11].try_into().unwrap()), + u16::from_be_bytes(ipv6[12..13].try_into().unwrap()), + u16::from_be_bytes(ipv6[14..15].try_into().unwrap()), + )), + } + } +} + +#[derive(Debug, Archive, Serialize, Deserialize, Copy, Clone, PartialEq, Eq)] +pub(crate) enum TcpMgmtCode { + SetRxShutdown, + SetNoDelay(bool), + GetNoDelay(bool), + SetTtl(u32), + GetTtl(u32), + ErrorCheck(NetMemResponse), + Flush(bool), + CloseListener, +} diff --git a/services/net/src/api/tcp.rs b/services/net/src/api/tcp.rs index b6e55f918..ee1c1202b 100644 --- a/services/net/src/api/tcp.rs +++ b/services/net/src/api/tcp.rs @@ -31,18 +31,6 @@ pub(crate) struct NetTcpListenCallback { pub(crate) local_port: u16, } -#[derive(Debug, Archive, Serialize, Deserialize, Copy, Clone, PartialEq, Eq)] -pub(crate) enum TcpMgmtCode { - SetRxShutdown, - SetNoDelay(bool), - GetNoDelay(bool), - SetTtl(u32), - GetTtl(u32), - ErrorCheck(NetMemResponse), - Flush(bool), - CloseListener, -} - #[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)] pub(crate) enum NetTcpCallback { RxData, diff --git a/services/pddb/src/api.rs b/services/pddb/src/api.rs index 06ef95024..ce7fbfd98 100644 --- a/services/pddb/src/api.rs +++ b/services/pddb/src/api.rs @@ -1,3 +1,6 @@ +mod rkyv_enum; +pub use rkyv_enum::*; + use bitfield::bitfield; use std::num::NonZeroU32; @@ -264,13 +267,7 @@ pub enum PddbRequestCode { Uninit = 10, DuplicateEntry = 11, } -#[derive(Copy, Clone, Eq, PartialEq, Debug)] -#[derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] -pub enum BasisRetentionPolicy { - Persist, - ClearAfterSleeps(u32), - //TimeOutSecs(u32), -} +// enum def is in rkyv_enum module impl BasisRetentionPolicy { pub fn derive_init_state(&self) -> u32 { match self { @@ -450,46 +447,6 @@ impl PddbKeyAttrIpc { } } -#[derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Eq, PartialEq)] -pub enum PddbRekeyOp { - /// rekeys the a restored PDDB to the current device DNA using the "fast" method. - /// The "fast" method is significantly faster on PDDBs with a small amount of data, but - /// it will leak information on the amount of data in the PDDB, in a manner that can be - /// trivially recovered by doing comparative ciphertext analysis between the backup and - /// the current database image. *Some* amount of chaffe data is written, but only a - /// small amount. - FromDnaFast(u64), - /// same as the above, but blank space is also turned over, guaranteeing the deniability - /// of stored data even if an attacker has the previous backup copy of the PDDB. - FromDnaSafe(u64), - /// Basically the same as FromDnaSafe, but doing a self-to-self "safe" rekey - Churn, - /* - // skip this implementation for now. This opcode fits generally into this code flow, - // but requires some rework of the UX to actually acquire the old and new passwords. - // this UX work is off-topic from the mission of getting backup restoration done, - // but the potential to integrate the password rotation scheme into this function is - // noted here for future efforts. - // - /// Requests a single secret basis to have its password changed. This will reveal the size - /// of the Basis if the attacker has a before-and-after image of the PDDB. - /// Recommended to call `Churn` after this operation is done for optimal safety. - /// - /// Note: changing the password on the .System basis is a different flow. The - /// system basis keys are encrypted directly by the rootkeys enclave, so changing - /// its password requires calling a routine in root_keys (that does not exist - /// at this current time). - ChangePass(xous_ipc::String), - */ - - /// Return codes - Success, - AuthFail, - UserAbort, - VerifyFail, - InternalError, -} - /// Debugging commands, available only in hosted mode #[cfg(any(feature="hosted"))] #[derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] diff --git a/services/pddb/src/api/rkyv_enum.rs b/services/pddb/src/api/rkyv_enum.rs new file mode 100644 index 000000000..75fd56f53 --- /dev/null +++ b/services/pddb/src/api/rkyv_enum.rs @@ -0,0 +1,61 @@ +// As of Rust 1.64.0: +// +// Rkyv-derived enums throw warnings that rkyv::Archive derived enums are never used +// and I can't figure out how to make them go away. Since they spam the build log, +// rkyv-derived enums are now isolated to their own file with a file-wide `dead_code` +// allow on top. +// +// This might be a temporary compiler regression, or it could just +// be yet another indicator that it's time to upgrade rkyv. However, we are waiting +// until rkyv hits 0.8 (the "shouldn't ever change again but still not sure enough +// for 1.0") release until we rework the entire system to chase the latest rkyv. +// As of now, the current version is 0.7.x and there isn't a timeline yet for 0.8. + +#![allow(dead_code)] +#[derive(Copy, Clone, Eq, PartialEq, Debug)] +#[derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] +pub enum BasisRetentionPolicy { + Persist, + ClearAfterSleeps(u32), + //TimeOutSecs(u32), +} + +#[derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Eq, PartialEq)] +pub enum PddbRekeyOp { + /// rekeys the a restored PDDB to the current device DNA using the "fast" method. + /// The "fast" method is significantly faster on PDDBs with a small amount of data, but + /// it will leak information on the amount of data in the PDDB, in a manner that can be + /// trivially recovered by doing comparative ciphertext analysis between the backup and + /// the current database image. *Some* amount of chaffe data is written, but only a + /// small amount. + FromDnaFast(u64), + /// same as the above, but blank space is also turned over, guaranteeing the deniability + /// of stored data even if an attacker has the previous backup copy of the PDDB. + FromDnaSafe(u64), + /// Basically the same as FromDnaSafe, but doing a self-to-self "safe" rekey + Churn, + /* + // skip this implementation for now. This opcode fits generally into this code flow, + // but requires some rework of the UX to actually acquire the old and new passwords. + // this UX work is off-topic from the mission of getting backup restoration done, + // but the potential to integrate the password rotation scheme into this function is + // noted here for future efforts. + // + /// Requests a single secret basis to have its password changed. This will reveal the size + /// of the Basis if the attacker has a before-and-after image of the PDDB. + /// Recommended to call `Churn` after this operation is done for optimal safety. + /// + /// Note: changing the password on the .System basis is a different flow. The + /// system basis keys are encrypted directly by the rootkeys enclave, so changing + /// its password requires calling a routine in root_keys (that does not exist + /// at this current time). + ChangePass(xous_ipc::String), + */ + + /// Return codes + Success, + AuthFail, + UserAbort, + VerifyFail, + InternalError, +} \ No newline at end of file diff --git a/services/root-keys/src/api.rs b/services/root-keys/src/api.rs index bdd98c150..0e56514b4 100644 --- a/services/root-keys/src/api.rs +++ b/services/root-keys/src/api.rs @@ -1,3 +1,6 @@ +mod rkyv_enum; +pub use rkyv_enum::*; + use core::ops::{Deref, DerefMut}; use core::mem::size_of; @@ -153,12 +156,6 @@ pub enum AesRootkeyType { NoneSpecified = 0xff, } -#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Zeroize)] -#[zeroize(drop)] -pub enum AesBlockType { - SingleBlock([u8; 16]), - ParBlock([[u8; 16]; PAR_BLOCKS]), -} #[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Zeroize)] #[zeroize(drop)] pub enum AesOpType { @@ -192,17 +189,6 @@ impl AesOp { } } -#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Eq, PartialEq, Copy, Clone)] -pub enum KeywrapError { - InvalidDataSize, - InvalidKekSize, - InvalidOutputSize, - IntegrityCheckFailed, - /// this is a bodge to return an error code that upgrades from a faulty early version of AES-KWP - /// only works for 256-bit keys, but that is also all we used. - /// The return tuple is: (unwrapped key, correctly wrapped key) - UpgradeToNew(([u8; 32], [u8; 40])), -} #[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Eq, PartialEq)] pub enum KeyWrapOp { Wrap = 0, diff --git a/services/root-keys/src/api/rkyv_enum.rs b/services/root-keys/src/api/rkyv_enum.rs new file mode 100644 index 000000000..62f6f3ba5 --- /dev/null +++ b/services/root-keys/src/api/rkyv_enum.rs @@ -0,0 +1,35 @@ +// As of Rust 1.64.0: +// +// Rkyv-derived enums throw warnings that rkyv::Archive derived enums are never used +// and I can't figure out how to make them go away. Since they spam the build log, +// rkyv-derived enums are now isolated to their own file with a file-wide `dead_code` +// allow on top. +// +// This might be a temporary compiler regression, or it could just +// be yet another indicator that it's time to upgrade rkyv. However, we are waiting +// until rkyv hits 0.8 (the "shouldn't ever change again but still not sure enough +// for 1.0") release until we rework the entire system to chase the latest rkyv. +// As of now, the current version is 0.7.x and there isn't a timeline yet for 0.8. + +#![allow(dead_code)] +use zeroize::Zeroize; +use crate::PAR_BLOCKS; + +#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Zeroize)] +#[zeroize(drop)] +pub enum AesBlockType { + SingleBlock([u8; 16]), + ParBlock([[u8; 16]; PAR_BLOCKS]), +} + +#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Eq, PartialEq, Copy, Clone)] +pub enum KeywrapError { + InvalidDataSize, + InvalidKekSize, + InvalidOutputSize, + IntegrityCheckFailed, + /// this is a bodge to return an error code that upgrades from a faulty early version of AES-KWP + /// only works for 256-bit keys, but that is also all we used. + /// The return tuple is: (unwrapped key, correctly wrapped key) + UpgradeToNew(([u8; 32], [u8; 40])), +}