Skip to content

Commit

Permalink
Impl Error for CoseError under std feature
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddrysdale committed Jan 2, 2023
1 parent 1f265f2 commit 60322bc
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
components: rustfmt
override: true
- run: cargo build --release --workspace
- run: cargo build --release --workspace --features=std

test:
runs-on: ubuntu-latest
Expand All @@ -48,6 +49,7 @@ jobs:
components: rustfmt
override: true
- run: cargo test --workspace -- --nocapture
- run: cargo test --workspace --features=std -- --nocapture

examples:
runs-on: ubuntu-latest
Expand All @@ -68,6 +70,7 @@ jobs:
components: rustfmt
override: true
- run: cargo test --examples
- run: cargo test --features=std --examples

no_std:
name: Build for a no_std target
Expand Down Expand Up @@ -107,6 +110,7 @@ jobs:
components: rustfmt
override: true
- run: rustc --version
- run: cargo build --release --workspace
- run: cargo build --release --workspace --all-features

formatting:
Expand Down
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ repository = "https://github.com/google/coset"
keywords = ["cryptography", "cose"]
categories = ["cryptography"]

[features]
default = []
# `std` feature enables an `Error` impl for `CoseError`
std = []

[dependencies]
ciborium = { version = "^0.2.0", default-features = false }
ciborium-io = { version = "^0.2.0", features = ["alloc"] }
Expand Down
3 changes: 3 additions & 0 deletions src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ impl core::fmt::Display for CoseError {
}
}

#[cfg(feature = "std")]
impl std::error::Error for CoseError {}

impl CoseError {
fn fmt_msg(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
//! [COSE]: https://tools.ietf.org/html/rfc8152
//! [CBOR]: https://tools.ietf.org/html/rfc7049
#![no_std]
#![cfg_attr(not(feature = "std"), no_std)]
#![deny(rustdoc::broken_intra_doc_links)]
extern crate alloc;

Expand Down
1 change: 1 addition & 0 deletions src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ pub fn expect_err<T: core::fmt::Debug, E: core::fmt::Debug + core::fmt::Display>
result: Result<T, E>,
err_msg: &str,
) {
#[cfg(not(feature = "std"))]
use alloc::format;
match result {
Ok(_) => {
Expand Down

0 comments on commit 60322bc

Please sign in to comment.