Skip to content

Commit ca05106

Browse files
atlas-formclaude
andcommitted
refactor: reorganize capsula-crypto module with enhanced hash API
- Restructure crypto module into functional categories: * asymmetric/ - Ed25519 signatures and X25519 key exchange * symmetric/ - AES-256-GCM and ChaCha20-Poly1305 encryption * hash/ - SHA-256 and SHA-512 hash functions with flexible API * kdf/ - HKDF key derivation with cleaner API - Enhance hash module with algorithm selection: * Add HashAlgorithm enum for SHA-256/SHA-512 selection * Implement generic hash() function with algorithm parameter * Add quick_hash() convenience functions using default algorithm * Maintain backward compatibility with existing sha256/sha512 functions - Improve KDF module: * Rename functions to derive_key32() and derive_many() * Keep legacy names as deprecated aliases for compatibility - Update all imports and examples to use new module structure - All 25 tests passing with enhanced test coverage BREAKING CHANGE: Module paths have changed, but all exports are maintained at crate root for backward compatibility 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 8f3bc69 commit ca05106

File tree

17 files changed

+599
-102
lines changed

17 files changed

+599
-102
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ getrandom = "0.3"
103103
sha2 = "0.10"
104104
signature = "2.2"
105105
base64 = "0.22.1"
106+
hkdf = "0.12.4"
106107

107108
# 证书相关
108109
rcgen = { version = "0.14", features = ["pem"] }

crates/capsula-crypto/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ed25519-dalek = { workspace = true, features = [
2020
x25519-dalek = { workspace = true, features = ["static_secrets", "zeroize"] }
2121
p256 = { workspace = true, features = ["ecdsa"] }
2222
pkcs8 = { workspace = true }
23+
hkdf = { workspace = true }
2324

2425
# PEM encoding
2526
pem = { workspace = true }
File renamed without changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//! Asymmetric cryptography algorithms
2+
//!
3+
//! This module provides implementations of asymmetric cryptographic algorithms
4+
//! including digital signatures and key exchange.
5+
6+
pub mod ed25519;
7+
pub mod x25519;
8+
9+
pub use ed25519::Ed25519;
10+
pub use x25519::X25519;
File renamed without changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//! Cryptographic hash functions
2+
//!
3+
//! This module provides cryptographic hash functions for data integrity
4+
//! and key derivation purposes, including SHA-256 and SHA-512.
5+
6+
pub mod sha;
7+
8+
// Re-export the hash algorithm enum
9+
pub use sha::HashAlgorithm;
10+
// Re-export generic hash functions
11+
pub use sha::{hash, hash_hex, verify};
12+
// Re-export convenience functions
13+
pub use sha::{quick_hash, quick_hash_hex};
14+
// Re-export SHA-256 specific functions
15+
pub use sha::{sha256, sha256_hex, sha256_verify};
16+
// Re-export SHA-512 specific functions
17+
pub use sha::{sha512, sha512_hex, sha512_verify};
18+
// Re-export SHA types from sha2 crate for convenience
19+
pub use sha2::{Sha256, Sha512};

0 commit comments

Comments
 (0)