-
-
Notifications
You must be signed in to change notification settings - Fork 11
feat: Makes the tracing dependency optional.
#30
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
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 |
|---|---|---|
| @@ -1,8 +1,5 @@ | ||
| use super::AlgorithmName; | ||
| use crate::{ | ||
| error::{HttpSigError, HttpSigResult}, | ||
| trace::*, | ||
| }; | ||
| use crate::error::{HttpSigError, HttpSigResult}; | ||
| use ecdsa::{ | ||
| elliptic_curve::{PublicKey as EcPublicKey, SecretKey as EcSecretKey, sec1::ToEncodedPoint}, | ||
| signature::{DigestSigner, DigestVerifier}, | ||
|
|
@@ -13,6 +10,8 @@ use p384::NistP384; | |
| use pkcs8::{Document, PrivateKeyInfo, der::Decode}; | ||
| use sha2::{Digest, Sha256, Sha384}; | ||
| use spki::SubjectPublicKeyInfoRef; | ||
| #[cfg(feature = "tracing")] | ||
| use tracing::debug; | ||
|
|
||
| #[cfg(feature = "rsa-signature")] | ||
| use rsa::{ | ||
|
|
@@ -65,16 +64,19 @@ impl SecretKey { | |
| pub fn from_bytes(alg: &AlgorithmName, bytes: &[u8]) -> HttpSigResult<Self> { | ||
| match alg { | ||
| AlgorithmName::EcdsaP256Sha256 => { | ||
| #[cfg(feature = "tracing")] | ||
| debug!("Read P256 private key"); | ||
| let sk = EcSecretKey::from_bytes(bytes.into()).map_err(|e| HttpSigError::ParsePrivateKeyError(e.to_string()))?; | ||
| Ok(Self::EcdsaP256Sha256(sk)) | ||
| } | ||
| AlgorithmName::EcdsaP384Sha384 => { | ||
| #[cfg(feature = "tracing")] | ||
| debug!("Read P384 private key"); | ||
| let sk = EcSecretKey::from_bytes(bytes.into()).map_err(|e| HttpSigError::ParsePrivateKeyError(e.to_string()))?; | ||
| Ok(Self::EcdsaP384Sha384(sk)) | ||
| } | ||
| AlgorithmName::Ed25519 => { | ||
| #[cfg(feature = "tracing")] | ||
| debug!("Read Ed25519 private key"); | ||
| let mut seed = [0u8; 32]; | ||
| seed.copy_from_slice(bytes); | ||
|
Comment on lines
78
to
82
|
||
|
|
@@ -176,6 +178,7 @@ impl super::SigningKey for SecretKey { | |
| fn sign(&self, data: &[u8]) -> HttpSigResult<Vec<u8>> { | ||
| match &self { | ||
| Self::EcdsaP256Sha256(sk) => { | ||
| #[cfg(feature = "tracing")] | ||
| debug!("Sign EcdsaP256Sha256"); | ||
| let sk = ecdsa::SigningKey::from(sk); | ||
| let mut digest = <Sha256 as Digest>::new(); | ||
|
|
@@ -184,6 +187,7 @@ impl super::SigningKey for SecretKey { | |
| Ok(sig.to_bytes().to_vec()) | ||
| } | ||
| Self::EcdsaP384Sha384(sk) => { | ||
| #[cfg(feature = "tracing")] | ||
| debug!("Sign EcdsaP384Sha384"); | ||
| let sk = ecdsa::SigningKey::from(sk); | ||
| let mut digest = <Sha384 as Digest>::new(); | ||
|
|
@@ -192,6 +196,7 @@ impl super::SigningKey for SecretKey { | |
| Ok(sig.to_bytes().to_vec()) | ||
| } | ||
| Self::Ed25519(sk) => { | ||
| #[cfg(feature = "tracing")] | ||
| debug!("Sign Ed25519"); | ||
| let sig = sk.sign(data, Some(ed25519_compact::Noise::default())); | ||
| Ok(sig.as_ref().to_vec()) | ||
|
Comment on lines
198
to
202
|
||
|
|
@@ -260,16 +265,19 @@ impl PublicKey { | |
| pub fn from_bytes(alg: &AlgorithmName, bytes: &[u8]) -> HttpSigResult<Self> { | ||
| match alg { | ||
| AlgorithmName::EcdsaP256Sha256 => { | ||
| #[cfg(feature = "tracing")] | ||
| debug!("Read P256 public key"); | ||
| let pk = EcPublicKey::from_sec1_bytes(bytes).map_err(|e| HttpSigError::ParsePublicKeyError(e.to_string()))?; | ||
| Ok(Self::EcdsaP256Sha256(pk)) | ||
| } | ||
| AlgorithmName::EcdsaP384Sha384 => { | ||
| #[cfg(feature = "tracing")] | ||
| debug!("Read P384 public key"); | ||
| let pk = EcPublicKey::from_sec1_bytes(bytes).map_err(|e| HttpSigError::ParsePublicKeyError(e.to_string()))?; | ||
| Ok(Self::EcdsaP384Sha384(pk)) | ||
| } | ||
| AlgorithmName::Ed25519 => { | ||
| #[cfg(feature = "tracing")] | ||
| debug!("Read Ed25519 public key"); | ||
| let pk = ed25519_compact::PublicKey::from_slice(bytes).map_err(|e| HttpSigError::ParsePublicKeyError(e.to_string()))?; | ||
| Ok(Self::Ed25519(pk)) | ||
|
Comment on lines
279
to
283
|
||
|
|
@@ -358,6 +366,7 @@ impl super::VerifyingKey for PublicKey { | |
| fn verify(&self, data: &[u8], signature: &[u8]) -> HttpSigResult<()> { | ||
| match self { | ||
| Self::EcdsaP256Sha256(pk) => { | ||
| #[cfg(feature = "tracing")] | ||
| debug!("Verify EcdsaP256Sha256"); | ||
| let signature = ecdsa::Signature::<NistP256>::from_bytes(signature.into()) | ||
| .map_err(|e| HttpSigError::ParseSignatureError(e.to_string()))?; | ||
|
|
@@ -368,6 +377,7 @@ impl super::VerifyingKey for PublicKey { | |
| .map_err(|e| HttpSigError::InvalidSignature(e.to_string())) | ||
| } | ||
| Self::EcdsaP384Sha384(pk) => { | ||
| #[cfg(feature = "tracing")] | ||
| debug!("Verify EcdsaP384Sha384"); | ||
| let signature = ecdsa::Signature::<NistP384>::from_bytes(signature.into()) | ||
| .map_err(|e| HttpSigError::ParseSignatureError(e.to_string()))?; | ||
|
|
@@ -378,6 +388,7 @@ impl super::VerifyingKey for PublicKey { | |
| .map_err(|e| HttpSigError::InvalidSignature(e.to_string())) | ||
| } | ||
| Self::Ed25519(pk) => { | ||
| #[cfg(feature = "tracing")] | ||
| debug!("Verify Ed25519"); | ||
| let sig = | ||
| ed25519_compact::Signature::from_slice(signature).map_err(|e| HttpSigError::ParseSignatureError(e.to_string()))?; | ||
|
|
@@ -386,6 +397,7 @@ impl super::VerifyingKey for PublicKey { | |
| } | ||
| #[cfg(feature = "rsa-signature")] | ||
| Self::RsaV1_5Sha256(pk) => { | ||
| #[cfg(feature = "tracing")] | ||
| debug!("Verify RsaV1_5Sha256"); | ||
| let sig = pkcs1v15::Signature::try_from(signature).map_err(|e| HttpSigError::ParseSignatureError(e.to_string()))?; | ||
| pk.verify(data, &sig) | ||
|
Comment on lines
398
to
403
Owner
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. omg. it must be unacceptable. |
||
|
|
||
|
Owner
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. Adding I have verified locally that this compiles with the feature both on and off. Two gotchas encoded in the snippet:
With this approach the diff shrinks to Cargo.toml and trace.rs only. Please revert the changes to the other five files. |
This file was deleted.
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.
Log output of existing users should not silently disappear, so the current behavior must be preserved.