Skip to content

Commit 15c5ff5

Browse files
Merge pull request #79 from gvonness-apolitical/refactor/error-helpers
Add error helpers and update README feature table
2 parents 311153e + 12c9d06 commit 15c5ff5

11 files changed

Lines changed: 210 additions & 310 deletions

File tree

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ This library provides the foundational capabilities for working with Codex docum
2727
- **Document Builder** - Fluent API for creating documents programmatically
2828
- **Metadata** - Dublin Core metadata support
2929
- **Presentation Layers** - Paginated and continuous presentation types
30-
- **Digital Signatures** - ECDSA P-256 (ES256) and Ed25519 signing and verification
31-
- **Encryption** - AES-256-GCM content encryption
30+
- **Digital Signatures** - ECDSA P-256 (ES256), P-384 (ES384), Ed25519, RSA-PSS (PS256), and ML-DSA-65 signing and verification
31+
- **Encryption** - AES-256-GCM and ChaCha20-Poly1305 content encryption
3232
- **Asset Management** - Embed and manage images, fonts, and files
3333
- **Document Verification** - Verify content hashes and document integrity
3434
- **Provenance** - Merkle trees, block proofs, and timestamp support for content lineage
@@ -51,9 +51,16 @@ cdx-core = "0.3"
5151
|---------|---------|-------------|
5252
| `zstd` | Yes | Zstandard compression support |
5353
| `signatures` | Yes | ECDSA P-256 digital signatures (ES256) |
54+
| `signatures-es384` | No | P-384 ECDSA digital signatures (ES384) |
55+
| `signatures-rsa` | No | RSA-PSS digital signatures (PS256) |
5456
| `encryption` | No | AES-256-GCM content encryption |
57+
| `encryption-chacha` | No | ChaCha20-Poly1305 content encryption |
58+
| `key-wrapping` | No | ECDH-ES+A256KW key agreement |
59+
| `key-wrapping-rsa` | No | RSA-OAEP-256 key wrapping |
60+
| `key-wrapping-pbes2` | No | PBES2 password-based key wrapping |
5561
| `eddsa` | No | Ed25519 digital signatures |
5662
| `ml-dsa` | No | ML-DSA-65 post-quantum signatures |
63+
| `webauthn` | No | WebAuthn/FIDO2 signature verification |
5764
| `timestamps-rfc3161` | No | RFC 3161 timestamp acquisition |
5865
| `timestamps-ots` | No | OpenTimestamps (Bitcoin anchoring) |
5966
| `ocsp` | No | Certificate revocation checking (OCSP/CRL) |

cdx-core/src/error.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,34 @@ pub enum Error {
185185
},
186186
}
187187

188+
/// Create an [`Error::InvalidManifest`] with a formatted reason.
189+
pub(crate) fn invalid_manifest(reason: impl Into<String>) -> Error {
190+
Error::InvalidManifest {
191+
reason: reason.into(),
192+
}
193+
}
194+
195+
/// Create an [`Error::EncryptionError`] with a formatted reason.
196+
pub(crate) fn encryption_error(reason: impl Into<String>) -> Error {
197+
Error::EncryptionError {
198+
reason: reason.into(),
199+
}
200+
}
201+
202+
/// Create an [`Error::Network`] error with a formatted message.
203+
pub(crate) fn network_error(message: impl Into<String>) -> Error {
204+
Error::Network {
205+
message: message.into(),
206+
}
207+
}
208+
209+
/// Create an [`Error::InvalidCertificate`] with a formatted reason.
210+
pub(crate) fn invalid_certificate(reason: impl Into<String>) -> Error {
211+
Error::InvalidCertificate {
212+
reason: reason.into(),
213+
}
214+
}
215+
188216
#[cfg(test)]
189217
mod tests {
190218
use super::*;

cdx-core/src/security/eddsa.rs

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
//! EdDSA (Ed25519) signature implementation.
44
5+
use crate::error::invalid_manifest;
56
use crate::{DocumentId, Result};
67

78
use super::signature::{Signature, SignatureAlgorithm, SignatureVerification, SignerInfo};
@@ -24,11 +25,8 @@ impl EddsaSigner {
2425
pub fn from_pem(pem: &str, signer_info: SignerInfo) -> Result<Self> {
2526
use ed25519_dalek::pkcs8::DecodePrivateKey;
2627

27-
let signing_key = ed25519_dalek::SigningKey::from_pkcs8_pem(pem).map_err(|e| {
28-
crate::Error::InvalidManifest {
29-
reason: format!("Failed to parse EdDSA private key PEM: {e}"),
30-
}
31-
})?;
28+
let signing_key = ed25519_dalek::SigningKey::from_pkcs8_pem(pem)
29+
.map_err(|e| invalid_manifest(format!("Failed to parse EdDSA private key PEM: {e}")))?;
3230

3331
Ok(Self {
3432
signing_key,
@@ -47,16 +45,13 @@ impl EddsaSigner {
4745
use ed25519_dalek::pkcs8::spki::{der::pem::LineEnding, EncodePublicKey};
4846

4947
let mut key_bytes = [0u8; 32];
50-
getrandom::fill(&mut key_bytes).map_err(|e| crate::Error::InvalidManifest {
51-
reason: format!("System RNG failed: {e}"),
52-
})?;
48+
getrandom::fill(&mut key_bytes)
49+
.map_err(|e| invalid_manifest(format!("System RNG failed: {e}")))?;
5350
let signing_key = ed25519_dalek::SigningKey::from_bytes(&key_bytes);
5451
let verifying_key = signing_key.verifying_key();
5552
let public_key_pem = verifying_key
5653
.to_public_key_pem(LineEnding::LF)
57-
.map_err(|e| crate::Error::InvalidManifest {
58-
reason: format!("Failed to encode EdDSA public key: {e}"),
59-
})?;
54+
.map_err(|e| invalid_manifest(format!("Failed to encode EdDSA public key: {e}")))?;
6055

6156
Ok((
6257
Self {
@@ -78,9 +73,7 @@ impl EddsaSigner {
7873
self.signing_key
7974
.verifying_key()
8075
.to_public_key_pem(LineEnding::LF)
81-
.map_err(|e| crate::Error::InvalidManifest {
82-
reason: format!("Failed to encode EdDSA public key: {e}"),
83-
})
76+
.map_err(|e| invalid_manifest(format!("Failed to encode EdDSA public key: {e}")))
8477
}
8578
}
8679

@@ -141,11 +134,8 @@ impl EddsaVerifier {
141134
pub fn from_pem(pem: &str) -> Result<Self> {
142135
use ed25519_dalek::pkcs8::DecodePublicKey;
143136

144-
let verifying_key = ed25519_dalek::VerifyingKey::from_public_key_pem(pem).map_err(|e| {
145-
crate::Error::InvalidManifest {
146-
reason: format!("Failed to parse EdDSA public key PEM: {e}"),
147-
}
148-
})?;
137+
let verifying_key = ed25519_dalek::VerifyingKey::from_public_key_pem(pem)
138+
.map_err(|e| invalid_manifest(format!("Failed to parse EdDSA public key PEM: {e}")))?;
149139

150140
Ok(Self { verifying_key })
151141
}
@@ -174,9 +164,7 @@ impl Verifier for EddsaVerifier {
174164
// Decode signature from base64
175165
let sig_bytes = base64::engine::general_purpose::STANDARD
176166
.decode(&signature.value)
177-
.map_err(|e| crate::Error::InvalidManifest {
178-
reason: format!("Failed to decode signature: {e}"),
179-
})?;
167+
.map_err(|e| invalid_manifest(format!("Failed to decode signature: {e}")))?;
180168

181169
// Parse signature
182170
let sig_array: [u8; 64] =

0 commit comments

Comments
 (0)