auths_verifier/
commit_error.rs1use thiserror::Error;
4
5use crate::error::AuthsErrorInfo;
6
7#[derive(Error, Debug)]
18pub enum CommitVerificationError {
19 #[error("commit is unsigned")]
21 UnsignedCommit,
22
23 #[error("GPG signatures not supported, use SSH signing")]
25 GpgNotSupported,
26
27 #[error("SSHSIG parse failed: {0}")]
29 SshSigParseFailed(String),
30
31 #[error("unsupported SSH key type: {found}")]
33 UnsupportedKeyType {
34 found: String,
36 },
37
38 #[error("namespace mismatch: expected \"{expected}\", found \"{found}\"")]
40 NamespaceMismatch {
41 expected: String,
43 found: String,
45 },
46
47 #[error("unsupported hash algorithm: {0}")]
49 HashAlgorithmUnsupported(String),
50
51 #[error("signature verification failed")]
53 SignatureInvalid,
54
55 #[error("signer key not in allowed keys")]
57 UnknownSigner,
58
59 #[error("commit parse failed: {0}")]
61 CommitParseFailed(String),
62}
63
64impl AuthsErrorInfo for CommitVerificationError {
65 fn error_code(&self) -> &'static str {
66 match self {
67 Self::UnsignedCommit => "AUTHS-E2101",
68 Self::GpgNotSupported => "AUTHS-E2102",
69 Self::SshSigParseFailed(_) => "AUTHS-E2103",
70 Self::UnsupportedKeyType { .. } => "AUTHS-E2104",
71 Self::NamespaceMismatch { .. } => "AUTHS-E2105",
72 Self::HashAlgorithmUnsupported(_) => "AUTHS-E2106",
73 Self::SignatureInvalid => "AUTHS-E2107",
74 Self::UnknownSigner => "AUTHS-E2108",
75 Self::CommitParseFailed(_) => "AUTHS-E2109",
76 }
77 }
78
79 fn suggestion(&self) -> Option<&'static str> {
80 match self {
81 Self::UnsignedCommit => Some("Sign commits with: git commit -S"),
82 Self::GpgNotSupported => Some("Configure SSH signing: git config gpg.format ssh"),
83 Self::UnsupportedKeyType { .. } => Some("Use an Ed25519 SSH key for signing"),
84 Self::UnknownSigner => Some("Add the signer's key to the allowed signers list"),
85 Self::SshSigParseFailed(_) => Some(
86 "The SSH signature could not be parsed; verify the commit was signed correctly",
87 ),
88 Self::NamespaceMismatch { .. } => Some(
89 "The signature namespace doesn't match; ensure git config gpg.ssh.defaultKeyCommand is set correctly",
90 ),
91 Self::HashAlgorithmUnsupported(_) => {
92 Some("Use SHA-256 or SHA-512 hash algorithm for signing")
93 }
94 Self::SignatureInvalid => Some(
95 "The commit signature does not match the signed data; the commit may have been modified after signing",
96 ),
97 Self::CommitParseFailed(_) => Some(
98 "The Git commit object is malformed; check repository integrity with `git fsck`",
99 ),
100 }
101 }
102}