coapcore/lib.rs
1//! A CoAP security tool for embedded devices, supporting OSCORE/EDHOC and managing credentials.
2//!
3//! This crate is under active development; breaking changes will be made as necessary. It
4//! currently only handles the server side of CoAP exchanges. At runtime, there is more copying of
5//! messages than is generally preferred; those result from limitations of underlying tools and are
6//! being addressed there.
7//!
8//! This crate builds on several components technically and logically:
9//!
10//! * [libOSCORE](https://gitlab.com/oscore/liboscore/) provides the OSCORE implementation.
11//! * [Lakers](https://github.com/openwsn-berkeley/lakers) provides the EDHOC implementation.
12//! * The combined handling of OSCORE and EDHOC was originally explored in [EDF's CoAP/ACE-OAuth
13//! proof-of-concept firmware](https://gitlab.com/oscore/coap-ace-poc-firmware/). Since this
14//! crate matured, that firmware now uses coapcore.
15//! * The crate is maintained as part of [Ariel OS](https://ariel-os.org/), whose CoAP stack
16//! integrates it and [manages server access
17//! policies](https://ariel-os.github.io/ariel-os/dev/docs/book/tooling/coap.html#server-access-policy).
18//! Nothing in this crate depends on Ariel OS, but some examples may refer to it.
19//!
20//! # Usage
21//!
22//! This crate is mainly used with a CoAP stack (something that takes a [`coap_handler::Handler`])
23//! and a CoAP server application (an implementation of a [`coap_handler::Handler`]). Rather than
24//! passing the handler directly to the stack (which then only applies security mechanisms built
25//! into that concrete stack, if any), a [`OscoreEdhocHandler`] is
26//! [created][OscoreEdhocHandler::new] from the application, and passed into the stack.
27//!
28//! The arguments passed to the [`OscoreEdhocHandler`] at construction guide its behavior.
29//!
30//! # Logging
31//!
32//! Extensive logging is available in this crate through [`defmt_or_log`], depending on features
33//! enabled.
34//!
35//! Errors from CoAP are currently logged through its [`Debug2Format`](defmt_or_log::Debug2Format)
36//! facility, representing a compromise between development and runtime complexity. Should
37//! benchmarks show this to be a significant factor in code size in applications that need error
38//! handling, more fine grained control can be implemented (eg. offering an option to make
39//! [`Debug2Format`](defmt_or_log::Debug2Format) merely print the type name or even make it empty).
40//!
41//! This crate mainly logs on the trace, debug and error level; the latter provides details when an
42//! error is sent over the network and the details are not visible to the peer.
43//!
44//! See the book for [how defmt is configured in
45//! Ariel OS](https://ariel-os.github.io/ariel-os/dev/docs/book/tooling/defmt.html); outside of
46//! that, regular [`defmt_or_log`] practica applies.
47//!
48//! **Warning**: At the Debug level, this module may show cryptographic key material. This will be
49//! revised once all components have been interop-tested.
50//!
51//! # Caveats
52//!
53//! Currently, this has hidden dependencies on a particular implementation of the [`coap_message`]
54//! provided (it needs to be a [`coap_message_implementations::inmemory_write::Message`]) by the
55//! stack. There are plans for removing this limitation by integrating deeper with libOSCORE.
56#![doc = document_features::document_features!(feature_label = r#"<span class="stab portability"><code>{feature}</code></span>"#)]
57#![no_std]
58#![cfg_attr(feature = "_nightly_docs", feature(doc_cfg))]
59#![deny(missing_docs)]
60#![allow(clippy::too_many_lines)]
61#![allow(rust_2018_idioms)]
62#![expect(clippy::unused_trait_names)]
63#![expect(clippy::doc_paragraphs_missing_punctuation)]
64
65mod iana;
66
67mod helpers;
68
69pub mod time;
70
71pub mod ace;
72mod generalclaims;
73pub mod scope;
74pub use generalclaims::GeneralClaims;
75pub mod seccfg;
76
77// Might warrant a standalone crate at some point
78//
79// This is pub only to make the doctests run (but the crate's pub-ness needs a major overhaul
80// anyway)
81#[doc(hidden)]
82pub mod oluru;
83mod seccontext;
84pub use seccontext::*;
85
86mod error;
87pub use error::{CredentialError, CredentialErrorDetail as CredentialErrorKind};