ctap_types/
lib.rs

1#![cfg_attr(all(not(test), not(feature = "std")), no_std)]
2// #![no_std]
3
4//! `ctap-types` maps the various types involved in the FIDO CTAP protocol
5//! to Rust structures consisting of `heapless` data types.
6//!
7//! We currently follow the non-public editor's draft dated 19 March 2019.
8//! It still uses `FIDO_2_1_PRE` to signal new commands, but uses non-vendor
9//! API numbering (e.g. 0xA for credential management).
10//!
11//! It also contains a lightweight CBOR deserializer, as the existing `serde_cbor`
12//! creates very large code.
13//!
14//! The various transport protocols (USB, NFC, BLE) are expected to handle
15//! low-level protocol details and deserialize requests / serialize responses,
16//! so the authenticator logic is decoupled from these details.
17
18#[macro_use]
19extern crate delog;
20generate_macros!();
21
22pub use heapless;
23pub use heapless::{String, Vec};
24pub use heapless_bytes;
25pub use heapless_bytes::Bytes;
26pub use serde_bytes::ByteArray;
27
28#[cfg(feature = "arbitrary")]
29mod arbitrary;
30pub mod authenticator;
31pub mod ctap1;
32pub mod ctap2;
33pub(crate) mod operation;
34pub use cbor_smol as serde;
35pub mod sizes;
36pub mod webauthn;
37
38pub use ctap2::{Error, Result};
39
40use core::fmt::{self, Display, Formatter};
41
42/// An error returned by the `TryFrom<&str>` implementation for enums if an invalid value is
43/// provided.
44#[derive(Debug)]
45pub struct TryFromStrError;
46
47impl Display for TryFromStrError {
48    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
49        "invalid enum value".fmt(f)
50    }
51}
52
53#[cfg(test)]
54mod tests {}
55
56/// Call a remote procedure with a request, receive a response, maybe.
57pub trait Rpc<Error, Request, Response> {
58    fn call(&mut self, request: &Request) -> core::result::Result<Response, Error>;
59}