Skip to content

Commit

Permalink
errors: &'static str -> String
Browse files Browse the repository at this point in the history
  • Loading branch information
tnytown committed Nov 29, 2023
1 parent d9525fa commit a3c2d81
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/crypto/certificate_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl<'a> CertificatePool<'a> {
let cert_pem = pem::parse(cert_pem)?;
if cert_pem.tag() != "CERTIFICATE" {
return Err(SigstoreError::CertificatePoolError(
"PEM file is not a certificate",
"PEM file is not a certificate".into(),
));
}

Expand Down
11 changes: 7 additions & 4 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub enum SigstoreError {
InvalidKeyFormat { error: String },

#[error("Unable to parse identity token: {0}")]
IdentityTokenError(&'static str),
IdentityTokenError(String),

#[error("unmatched key type {key_typ} and signing scheme {scheme}")]
UnmatchedKeyAndSigningScheme { key_typ: String, scheme: String },
Expand Down Expand Up @@ -107,13 +107,13 @@ pub enum SigstoreError {
CertificateWithIncompleteSubjectAlternativeName,

#[error("Certificate pool error: {0}")]
CertificatePoolError(&'static str),
CertificatePoolError(String),

#[error("Signing session expired")]
ExpiredSigningSession(),

#[error("Fulcio request unsuccessful: {0}")]
FulcioClientError(&'static str),
FulcioClientError(String),

#[error("Cannot fetch manifest of {image}: {error}")]
RegistryFetchManifestError { image: String, error: String },
Expand All @@ -130,6 +130,9 @@ pub enum SigstoreError {
#[error("Rekor request unsuccessful: {0}")]
RekorClientError(String),

#[error(transparent)]
JoinError(#[from] tokio::task::JoinError),

#[cfg(feature = "sign")]
#[error(transparent)]
ReqwestError(#[from] reqwest::Error),
Expand Down Expand Up @@ -166,7 +169,7 @@ pub enum SigstoreError {
TufTargetNotFoundError(String),

#[error("{0}")]
TufMetadataError(&'static str),
TufMetadataError(String),

#[error(transparent)]
IOError(#[from] std::io::Error),
Expand Down
16 changes: 8 additions & 8 deletions src/oauth/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,22 @@ impl TryFrom<&str> for IdentityToken {
type Error = SigstoreError;

fn try_from(value: &str) -> Result<Self, Self::Error> {
let parts: [&str; 3] = value
.split('.')
.collect::<Vec<_>>()
.try_into()
.or(Err(SigstoreError::IdentityTokenError("Malformed JWT")))?;
let parts: [&str; 3] = value.split('.').collect::<Vec<_>>().try_into().or(Err(
SigstoreError::IdentityTokenError("Malformed JWT".into()),
))?;

let claims = base64
.decode(parts[1])
.or(Err(SigstoreError::IdentityTokenError(
"Malformed JWT: Unable to decode claims",
"Malformed JWT: Unable to decode claims".into(),
)))?;
let claims: Claims = serde_json::from_slice(&claims).or(Err(
SigstoreError::IdentityTokenError("Malformed JWT: claims JSON malformed"),
SigstoreError::IdentityTokenError("Malformed JWT: claims JSON malformed".into()),
))?;
if claims.aud != "sigstore" {
return Err(SigstoreError::IdentityTokenError("Not a Sigstore JWT"));
return Err(SigstoreError::IdentityTokenError(
"Not a Sigstore JWT".into(),
));
}

Ok(IdentityToken {
Expand Down
4 changes: 2 additions & 2 deletions src/tuf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl Repository for SigstoreRepository {

if certs.is_empty() {
Err(SigstoreError::TufMetadataError(
"Fulcio certificates not found",
"Fulcio certificates not found".into(),
))
} else {
Ok(certs)
Expand All @@ -215,7 +215,7 @@ impl Repository for SigstoreRepository {

if keys.len() != 1 {
Err(SigstoreError::TufMetadataError(
"Did not find exactly 1 active Rekor key",
"Did not find exactly 1 active Rekor key".into(),
))
} else {
Ok(keys)
Expand Down

0 comments on commit a3c2d81

Please sign in to comment.