Skip to content

Commit

Permalink
Cleanup ctaphid-dispatch API
Browse files Browse the repository at this point in the history
This patch flattens the public API of ctaphid-dispatch by making the
dispatch and types modules private and re-exporting the relevant types
from the root and removes unnecessary re-exports of the types defined by
ctaphid-app.
  • Loading branch information
robin-nitrokey committed Jan 8, 2025
1 parent 98b846c commit 3c0382b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 27 deletions.
1 change: 1 addition & 0 deletions dispatch/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Move the `app` and `command` modules into a separate crate, `ctaphid-app`, and re-export it.
- Make `App` trait generic over the response size.
- Remove unused `ShortMessage` type.
- Flatten the public module structure and remove unnecessary re-exports.

## [0.1.1] - 2022-08-22
- adjust to `interchange` API change
Expand Down
5 changes: 0 additions & 5 deletions dispatch/src/constants.rs

This file was deleted.

14 changes: 5 additions & 9 deletions dispatch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@
extern crate delog;
generate_macros!();

pub mod dispatch;
pub mod types;
mod dispatch;
mod types;

pub mod app {
pub use crate::types::AppResult;
pub use ctaphid_app::{App, Command, Error};
}
pub use ctaphid_app as app;

pub mod command {
pub use ctaphid_app::{Command, VendorCommand};
}
pub use dispatch::Dispatch;
pub use types::{Channel, InterchangeResponse, Message, Requester, Responder, MESSAGE_SIZE};
14 changes: 1 addition & 13 deletions dispatch/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
use ctaphid_app::{Command, Error};
use heapless_bytes::Bytes;

pub use ctaphid_app::Error;

// // 7609 bytes is max message size for ctaphid
// type U6144 = <heapless::consts::U4096 as core::ops::Add<heapless::consts::U2048>>::Output;
// type U7168 = <U6144 as core::ops::Add<heapless::consts::U1024>>::Output;
// pub type U7609 = <U7168 as core::ops::Add<heapless::consts::U441>>::Output;
// pub type U7609 = heapless::consts::U4096;

// TODO: find reasonable size
// pub type Message = heapless::Vec<u8, 3072>;
pub const MESSAGE_SIZE: usize = 7609;

pub type Message = Bytes<MESSAGE_SIZE>;
pub type AppResult = core::result::Result<(), Error>;

/// Wrapper struct that implements [`Default`][] to be able to use [`response_mut`](interchange::Responder::response_mut)
pub struct InterchangeResponse(pub Result<Message, Error>);
Expand All @@ -36,8 +26,6 @@ impl From<InterchangeResponse> for Result<Message, Error> {
}
}

pub use crate::command::Command;

pub type Responder<'pipe> = interchange::Responder<'pipe, (Command, Message), InterchangeResponse>;
pub type Requester<'pipe> = interchange::Requester<'pipe, (Command, Message), InterchangeResponse>;
pub type Channel = interchange::Channel<(Command, Message), InterchangeResponse>;

0 comments on commit 3c0382b

Please sign in to comment.