-
Notifications
You must be signed in to change notification settings - Fork 3
feat: remove the anyhow and introduce no_std feature flag
#6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,10 +12,11 @@ description = "A flexible and secure key storage interface for working with cryp | |
| keywords = ["crypto", "storage", "keys", "signatures", "security"] | ||
|
|
||
| [dependencies] | ||
| anyhow = "1" | ||
| thiserror = "2" | ||
| async-trait = "0.1" | ||
| thiserror = { version = "2", optional = true, default-features = false } | ||
| async-trait = { version = "0.1", optional = true } | ||
|
|
||
| [features] | ||
| default = ["send-sync-storage"] | ||
| default = ["std", "send-sync-storage"] | ||
| std = ["thiserror/std", "async-trait"] | ||
| send-sync-storage = [] | ||
| no-std = ["thiserror", "async-trait"] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a side note: cargo feature flags should be additive. Usually, you don't need a no_std feature flag if your modes of operations include no_std and std. You always include thiserror and async-trait as non-optional dependencies because you need them for no_std anyway. And then you only need the std feature flag which additionally activates their respective std flags. In this specific case, the reason is more semantically rather than technical because currently enabling both std and no_std wouldn't conflict. Later, they might diverge and break the promise. As you don't |
||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,8 +3,21 @@ | |||||||||||||
|
|
||||||||||||||
| use thiserror::Error; | ||||||||||||||
|
|
||||||||||||||
| pub type Result<T, E = Error> = std::result::Result<T, E>; | ||||||||||||||
| #[cfg(not(feature = "std"))] | ||||||||||||||
| extern crate alloc; | ||||||||||||||
|
|
||||||||||||||
| #[cfg(not(feature = "std"))] | ||||||||||||||
| use alloc::boxed::Box; | ||||||||||||||
|
|
||||||||||||||
| #[cfg(feature = "std")] | ||||||||||||||
| use std::error::Error as StdError; | ||||||||||||||
|
|
||||||||||||||
| #[cfg(not(feature = "std"))] | ||||||||||||||
| use core::error::Error as CoreError; | ||||||||||||||
|
Comment on lines
+12
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
So in the end, your own |
||||||||||||||
|
|
||||||||||||||
| pub type Result<T, E = Error> = core::result::Result<T, E>; | ||||||||||||||
|
|
||||||||||||||
| #[cfg(feature = "std")] | ||||||||||||||
| #[derive(Debug, Error)] | ||||||||||||||
| pub enum Error { | ||||||||||||||
| #[error("key with ID {0} could not be found")] | ||||||||||||||
|
|
@@ -14,5 +27,18 @@ pub enum Error { | |||||||||||||
| #[error("failed to generate key with provided options")] | ||||||||||||||
| InvalidOptions, | ||||||||||||||
| #[error(transparent)] | ||||||||||||||
| Other(anyhow::Error), | ||||||||||||||
| Other(Box<dyn StdError + Send + Sync>), | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| #[cfg(not(feature = "std"))] | ||||||||||||||
| #[derive(Debug, Error)] | ||||||||||||||
| pub enum Error { | ||||||||||||||
| #[error("key with ID {0} could not be found")] | ||||||||||||||
| KeyNotFound(alloc::string::String), | ||||||||||||||
| #[error("unable to communicate with key store: {0}")] | ||||||||||||||
| StoreDisconnected(alloc::string::String), | ||||||||||||||
| #[error("failed to generate key with provided options")] | ||||||||||||||
| InvalidOptions, | ||||||||||||||
| #[error(transparent)] | ||||||||||||||
| Other(Box<dyn CoreError + Send + Sync>), | ||||||||||||||
| } | ||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,14 @@ | ||
| // Copyright 2020-2024 IOTA Stiftung | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| #![cfg_attr(not(feature = "std"), no_std)] | ||
|
|
||
| #[cfg(feature = "std")] | ||
| extern crate std; | ||
|
|
||
| #[cfg(not(feature = "std"))] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest you remove this gate and simply always use the alloc types. You could even enable |
||
| extern crate alloc; | ||
|
|
||
| mod error; | ||
| mod signature_scheme; | ||
| mod signer; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cargo toml lacks the MSRV bump to 1.81 to use
core::error::Error.