generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 17
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
Add linter to CI and applied some fixes #35
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
21f2fff
Apply clippy fixes
andresuribe87 22be8f1
Setup clippy CI
andresuribe87 a3b60e2
Apply cargo fmt
andresuribe87 f90bf9f
Fix for 'module_inception' clippy rule
amika-sq 33c0879
Apply suggestions from code review
andresuribe87 4a3b727
Merge branch 'main' into clippy
andresuribe87 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,25 @@ | ||
mod key; | ||
pub use key::*; | ||
pub mod private_key; | ||
pub mod public_key; | ||
|
||
mod private_key; | ||
pub use private_key::*; | ||
use ssi_jwk::JWK; | ||
use ssi_jws::Error as JWSError; | ||
|
||
mod public_key; | ||
pub use public_key::*; | ||
/// Enum defining all supported cryptographic key types. | ||
pub enum KeyType { | ||
Secp256k1, | ||
Secp256r1, | ||
Ed25519, | ||
} | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
pub enum KeyError { | ||
#[error(transparent)] | ||
JWSError(#[from] JWSError), | ||
#[error("Algorithm not found on JWK")] | ||
AlgorithmNotFound, | ||
} | ||
|
||
/// Trait defining all common behavior for cryptographic keys. | ||
pub trait Key { | ||
fn jwk(&self) -> &JWK; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,17 @@ | ||
mod key_store; | ||
pub use key_store::*; | ||
pub mod in_memory_key_store; | ||
|
||
mod in_memory_key_store; | ||
pub use in_memory_key_store::*; | ||
use crate::key::private_key::PrivateKey; | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
pub enum KeyStoreError { | ||
#[error("{0}")] | ||
InternalKeyStoreError(String), | ||
} | ||
|
||
// Trait for storing and retrieving private keys. | ||
// | ||
// Implementations of this trait should be thread-safe and allow for concurrent access. | ||
pub trait KeyStore: Send + Sync { | ||
fn get(&self, key_alias: &str) -> Result<Option<PrivateKey>, KeyStoreError>; | ||
fn insert(&self, key_alias: &str, private_key: PrivateKey) -> Result<(), KeyStoreError>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,41 @@ | ||
mod key_manager; | ||
pub use key_manager::*; | ||
pub mod key_store; | ||
pub mod local_key_manager; | ||
|
||
mod local_key_manager; | ||
pub use local_key_manager::*; | ||
use crate::key::public_key::PublicKey; | ||
use crate::key::{KeyError, KeyType}; | ||
use crate::key_manager::key_store::KeyStoreError; | ||
use ssi_jwk::Error as JWKError; | ||
|
||
pub mod key_store; | ||
#[derive(thiserror::Error, Debug)] | ||
pub enum KeyManagerError { | ||
#[error("Signing key not found in KeyManager")] | ||
SigningKeyNotFound, | ||
#[error(transparent)] | ||
JWKError(#[from] JWKError), | ||
#[error(transparent)] | ||
KeyError(#[from] KeyError), | ||
#[error(transparent)] | ||
KeyStoreError(#[from] KeyStoreError), | ||
} | ||
|
||
/// A key management trait for generating, storing, and utilizing keys private keys and their | ||
/// associated public keys. | ||
/// | ||
/// Implementations of this trait might provide key management through various Key Management | ||
/// Systems (KMS), such as AWS KMS, Google Cloud KMD, Hardware Security Modules (HSM), or simple | ||
/// in-memory storage, each adhering to the same consistent API for usage within applications. | ||
pub trait KeyManager: Send + Sync { | ||
/// Generates and securely stores a private key based on the provided `key_type`, | ||
/// returning a unique alias that can be utilized to reference the generated key for future | ||
/// operations. | ||
fn generate_private_key(&self, key_type: KeyType) -> Result<String, KeyManagerError>; | ||
|
||
/// Returns the public key associated with the provided `key_alias`, if one exists. | ||
fn get_public_key(&self, key_alias: &str) -> Result<Option<PublicKey>, KeyManagerError>; | ||
|
||
/// Signs the provided payload using the private key identified by the provided `key_alias`. | ||
fn sign(&self, key_alias: &str, payload: &[u8]) -> Result<Vec<u8>, KeyManagerError>; | ||
|
||
/// Returns the key alias of a public key, as was originally returned by `generate_private_key`. | ||
fn alias(&self, public_key: &PublicKey) -> Result<String, KeyManagerError>; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What provoked this change? Why is
signature
passed by reference butpayload
isn't?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.
This is the error https://rust-lang.github.io/rust-clippy/master/index.html#/needless_borrow
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.
BTW this was the result of running
cargo clippy --fix
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.
Oh I see, because
payload
was already initialized by reference whereassignature
was not