Skip to content

Commit

Permalink
chore(crypto): Remove OpenSSL-specific variants from public error types
Browse files Browse the repository at this point in the history
  • Loading branch information
scouten-adobe committed Jan 9, 2025
1 parent 7190807 commit caf654a
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 54 deletions.
28 changes: 13 additions & 15 deletions internal/crypto/src/cose/certificate_trust_policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl CertificateTrustPolicy {
}

Err(CertificateTrustError::InternalError(
"no implementation for certificate evaluation available",
"no implementation for certificate evaluation available".to_string(),
))
}

Expand Down Expand Up @@ -344,18 +344,9 @@ pub enum CertificateTrustError {
#[error("the certificate contains an invalid extended key usage (EKU) value")]
InvalidEku,

/// An error was reported by the OpenSSL native code.
///
/// NOTE: We do not directly capture the OpenSSL error itself because it
/// lacks an Eq implementation. Instead we capture the error description.
#[cfg(feature = "openssl")]
#[error("an error was reported by OpenSSL native code: {0}")]
OpenSslError(String),

/// The OpenSSL native code mutex could not be acquired.
#[cfg(feature = "openssl")]
#[error(transparent)]
OpenSslMutexUnavailable(#[from] crate::openssl::OpenSslMutexUnavailable),
/// An error was reported by the underlying cryptography implementation.
#[error("an error was reported by the cryptography library: {0}")]
CryptoLibraryError(String),

/// The certificate (or certificate chain) that was presented is invalid.
#[error("the certificate or certificate chain is invalid")]
Expand All @@ -364,13 +355,20 @@ pub enum CertificateTrustError {
/// An unexpected internal error occured while requesting the time stamp
/// response.
#[error("internal error ({0})")]
InternalError(&'static str),
InternalError(String),
}

#[cfg(feature = "openssl")]
impl From<openssl::error::ErrorStack> for CertificateTrustError {
fn from(err: openssl::error::ErrorStack) -> Self {
Self::OpenSslError(err.to_string())
Self::CryptoLibraryError(err.to_string())
}

Check warning on line 365 in internal/crypto/src/cose/certificate_trust_policy.rs

View check run for this annotation

Codecov / codecov/patch

internal/crypto/src/cose/certificate_trust_policy.rs#L364-L365

Added lines #L364 - L365 were not covered by tests
}

#[cfg(feature = "openssl")]
impl From<crate::openssl::OpenSslMutexUnavailable> for CertificateTrustError {
fn from(err: crate::openssl::OpenSslMutexUnavailable) -> Self {
Self::InternalError(err.to_string())

Check warning on line 371 in internal/crypto/src/cose/certificate_trust_policy.rs

View check run for this annotation

Codecov / codecov/patch

internal/crypto/src/cose/certificate_trust_policy.rs#L370-L371

Added lines #L370 - L371 were not covered by tests
}
}

Expand Down
5 changes: 1 addition & 4 deletions internal/crypto/src/openssl/signers/ecdsa_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,7 @@ impl RawSigner for EcdsaSigner {

self.cert_chain
.iter()
.map(|cert| {
cert.to_der()
.map_err(|e| RawSignerError::OpenSslError(e.to_string()))
})
.map(|cert| cert.to_der().map_err(|e| e.into()))
.collect()
}
}
Expand Down
5 changes: 1 addition & 4 deletions internal/crypto/src/openssl/signers/ed25519_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,7 @@ impl RawSigner for Ed25519Signer {

self.cert_chain
.iter()
.map(|cert| {
cert.to_der()
.map_err(|e| RawSignerError::OpenSslError(e.to_string()))
})
.map(|cert| cert.to_der().map_err(|e| e.into()))
.collect()
}
}
Expand Down
5 changes: 1 addition & 4 deletions internal/crypto/src/openssl/signers/rsa_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,7 @@ impl RawSigner for RsaSigner {

self.cert_chain
.iter()
.map(|cert| {
cert.to_der()
.map_err(|e| RawSignerError::OpenSslError(e.to_string()))
})
.map(|cert| cert.to_der().map_err(|e| e.into()))
.collect()
}

Expand Down
24 changes: 11 additions & 13 deletions internal/crypto/src/raw_signature/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,9 @@ pub enum RawSignerError {
#[error("I/O error ({0})")]
IoError(String),

/// An error was reported by the OpenSSL native code.
///
/// NOTE: We do not directly capture the OpenSSL error itself because it
/// lacks an `Eq` implementation. Instead we capture the error description.
#[cfg(feature = "openssl")]
#[error("an error was reported by OpenSSL native code: {0}")]
OpenSslError(String),

/// The OpenSSL native code mutex could not be acquired.
#[cfg(feature = "openssl")]
#[error(transparent)]
OpenSslMutexUnavailable(#[from] crate::openssl::OpenSslMutexUnavailable),
/// An error was reported by the underlying cryptography implementation.
#[error("an error was reported by the cryptography library: {0}")]
CryptoLibraryError(String),

/// An unexpected internal error occured while requesting the time stamp
/// response.
Expand All @@ -133,7 +124,14 @@ impl From<std::io::Error> for RawSignerError {
#[cfg(feature = "openssl")]
impl From<openssl::error::ErrorStack> for RawSignerError {
fn from(err: openssl::error::ErrorStack) -> Self {
Self::OpenSslError(err.to_string())
Self::CryptoLibraryError(err.to_string())
}

Check warning on line 128 in internal/crypto/src/raw_signature/signer.rs

View check run for this annotation

Codecov / codecov/patch

internal/crypto/src/raw_signature/signer.rs#L127-L128

Added lines #L127 - L128 were not covered by tests
}

#[cfg(feature = "openssl")]
impl From<crate::openssl::OpenSslMutexUnavailable> for RawSignerError {
fn from(err: crate::openssl::OpenSslMutexUnavailable) -> Self {
Self::InternalError(err.to_string())

Check warning on line 134 in internal/crypto/src/raw_signature/signer.rs

View check run for this annotation

Codecov / codecov/patch

internal/crypto/src/raw_signature/signer.rs#L133-L134

Added lines #L133 - L134 were not covered by tests
}
}

Expand Down
26 changes: 12 additions & 14 deletions internal/crypto/src/raw_signature/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,9 @@ pub enum RawSignatureValidationError {
#[error("the signature does not match the provided data or public key")]
SignatureMismatch,

/// An error was reported by the OpenSSL native code.
///
/// NOTE: We do not directly capture the OpenSSL error itself because it
/// lacks an Eq implementation. Instead we capture the error description.
#[cfg(feature = "openssl")]
#[error("an error was reported by OpenSSL native code: {0}")]
OpenSslError(String),

/// The OpenSSL native code mutex could not be acquired.
#[cfg(feature = "openssl")]
#[error(transparent)]
OpenSslMutexUnavailable(#[from] crate::openssl::OpenSslMutexUnavailable),
/// An error was reported by the underlying cryptography implementation.
#[error("an error was reported by the cryptography library: {0}")]
CryptoLibraryError(String),

/// An invalid public key was provided.
#[error("invalid public key")]
Expand All @@ -182,13 +173,20 @@ pub enum RawSignatureValidationError {
/// An unexpected internal error occured while requesting the time stamp
/// response.
#[error("internal error ({0})")]
InternalError(&'static str),
InternalError(String),
}

#[cfg(feature = "openssl")]
impl From<openssl::error::ErrorStack> for RawSignatureValidationError {
fn from(err: openssl::error::ErrorStack) -> Self {
Self::OpenSslError(err.to_string())
Self::CryptoLibraryError(err.to_string())
}

Check warning on line 183 in internal/crypto/src/raw_signature/validator.rs

View check run for this annotation

Codecov / codecov/patch

internal/crypto/src/raw_signature/validator.rs#L182-L183

Added lines #L182 - L183 were not covered by tests
}

#[cfg(feature = "openssl")]
impl From<crate::openssl::OpenSslMutexUnavailable> for RawSignatureValidationError {
fn from(err: crate::openssl::OpenSslMutexUnavailable) -> Self {
Self::InternalError(err.to_string())

Check warning on line 189 in internal/crypto/src/raw_signature/validator.rs

View check run for this annotation

Codecov / codecov/patch

internal/crypto/src/raw_signature/validator.rs#L188-L189

Added lines #L188 - L189 were not covered by tests
}
}

Expand Down

0 comments on commit caf654a

Please sign in to comment.