mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
fix rust 1.64.0 rkyv warning regressions on unused enum types
rkyv-derived enums throw warnings that they are unused. Not sure how to get rid of them; I've tried surrounding them in `#[allow(dead_code)]` directives, and also explicitly creating each enum variant that I'm aware of through some dummy code and some log prints of the dummy code calls to ensure the results are used, and the warnings still persist. Significantly, the warnings only happen for enums that take a value. Simple rkyv enums do not throw a warning. These warnings overwhelm the build logs, so they need to be isolated in order for us to ensure that the build is clean of other more important warnings. The method chosen to isolate them is to take the enums that are problematic, carve them into their own special file, and add a file-wide `#![allow(dead_code)]` directive. This only happens in 7 service crates, and this change commits all of the modifications in a single big commit that could be undone later if this turns out to be a compiler regression or something similar. I also opened an issue with the rkyv maintainer to see what his opinion is on the situation. https://github.com/rkyv/rkyv/issues/318
This commit is contained in:
parent
4aad245b31
commit
f815ed85b5
17 changed files with 391 additions and 244 deletions
|
|
@ -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
|
||||
|
|
|
|||
31
services/com/src/api/rkyv_enum.rs
Normal file
31
services/com/src/api/rkyv_enum.rs
Normal file
|
|
@ -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,
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
|
|||
26
services/engine-25519/src/api/rkyv_enum.rs
Normal file
26
services/engine-25519/src/api/rkyv_enum.rs
Normal file
|
|
@ -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,
|
||||
}
|
||||
|
|
@ -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 {
|
||||
|
|
|
|||
22
services/engine-sha512/src/api/rkyv_enum.rs
Normal file
22
services/engine-sha512/src/api/rkyv_enum.rs
Normal file
|
|
@ -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,
|
||||
}
|
||||
|
|
@ -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<Gid>),
|
||||
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>,
|
||||
|
|
|
|||
57
services/gam/src/api/rkyv_enum.rs
Normal file
57
services/gam/src/api/rkyv_enum.rs
Normal file
|
|
@ -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<Gid>),
|
||||
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)),
|
||||
}
|
||||
|
|
@ -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<PredictionTriggers, xous::Error>;
|
||||
fn unpick(&self) -> Result<(), xous::Error>;
|
||||
|
|
|
|||
19
services/ime-plugin-api/src/rkyv_enum.rs
Normal file
19
services/ime-plugin-api/src/rkyv_enum.rs
Normal file
|
|
@ -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,
|
||||
}
|
||||
|
|
@ -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<SsidRecord>; 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<SocketAddr> for NetSocketAddr {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Archive, Serialize, Deserialize, Copy, Clone)]
|
||||
pub enum NetIpAddr {
|
||||
Ipv4([u8; 4]),
|
||||
Ipv6([u8; 16]),
|
||||
}
|
||||
impl From<SocketAddr> 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<IpAddress> 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<IpAddr> 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<NetIpAddr> 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<NetIpAddr> 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 {
|
||||
|
|
|
|||
114
services/net/src/api/rkyv_enum.rs
Normal file
114
services/net/src/api/rkyv_enum.rs
Normal file
|
|
@ -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<SocketAddr> 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<IpAddress> 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<IpAddr> 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<NetIpAddr> 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<NetIpAddr> 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,
|
||||
}
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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<BASIS_NAME_LEN>),
|
||||
*/
|
||||
|
||||
/// 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)]
|
||||
|
|
|
|||
61
services/pddb/src/api/rkyv_enum.rs
Normal file
61
services/pddb/src/api/rkyv_enum.rs
Normal file
|
|
@ -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<BASIS_NAME_LEN>),
|
||||
*/
|
||||
|
||||
/// Return codes
|
||||
Success,
|
||||
AuthFail,
|
||||
UserAbort,
|
||||
VerifyFail,
|
||||
InternalError,
|
||||
}
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
35
services/root-keys/src/api/rkyv_enum.rs
Normal file
35
services/root-keys/src/api/rkyv_enum.rs
Normal file
|
|
@ -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])),
|
||||
}
|
||||
Loading…
Reference in a new issue