@@ -54,10 +54,6 @@ use uuid::Uuid;
5454#[ cfg( feature = "encryption" ) ]
5555use {
5656 aes_gcm:: { Aes256Gcm , Key as AesKey , KeyInit , Nonce , aead:: Aead } ,
57- argon2:: {
58- Argon2 ,
59- password_hash:: { PasswordHasher , SaltString } ,
60- } ,
6157 base64:: Engine ,
6258 rand:: { RngCore , rngs:: OsRng } ,
6359} ;
@@ -394,6 +390,8 @@ impl<DB: Database> KeyManager<DB>
394390where
395391 for < ' c > & ' c mut DB :: Connection : sqlx:: Executor < ' c , Database = DB > ,
396392 for < ' q > <DB as sqlx:: Database >:: Arguments < ' q > : sqlx:: IntoArguments < ' q , DB > ,
393+ for < ' r > String : sqlx:: Decode < ' r , DB > + sqlx:: Type < DB > ,
394+ for < ' r > & ' r str : sqlx:: ColumnIndex < DB :: Row > ,
397395{
398396 /// Create a new key manager instance
399397 pub async fn new ( config : KeyManagerConfig , pool : Pool < DB > ) -> Result < Self , EncryptionError > {
@@ -642,46 +640,11 @@ where
642640 return Ok ( vec ! [ ] ) ;
643641 }
644642
645- let keys_due_for_rotation = self . get_keys_due_for_rotation ( ) . await ?;
646- let mut rotated_keys = Vec :: new ( ) ;
647-
648- for key_id in keys_due_for_rotation {
649- match self . rotate_key ( & key_id) . await {
650- Ok ( _) => {
651- rotated_keys. push ( key_id) ;
652- }
653- Err ( e) => {
654- error ! ( "Failed to rotate key {}: {:?}" , key_id, e) ;
655- if self . config . audit_enabled {
656- self . record_audit_event (
657- & key_id,
658- KeyOperation :: Rotate ,
659- false ,
660- Some ( format ! ( "{:?}" , e) ) ,
661- )
662- . await ?;
663- }
664- }
665- }
666- }
667-
668- if !rotated_keys. is_empty ( ) {
669- info ! (
670- "Automatic rotation completed. Rotated {} keys: {:?}" ,
671- rotated_keys. len( ) ,
672- rotated_keys
673- ) ;
674- }
675-
676- Ok ( rotated_keys)
643+ // Note: Database-specific implementations should override this behavior
644+ warn ! ( "perform_automatic_rotation called on generic implementation - no rotation performed" ) ;
645+ Ok ( vec ! [ ] )
677646 }
678647
679- /// Check if a specific key needs rotation based on its rotation schedule
680- pub async fn is_key_due_for_rotation ( & self , key_id : & str ) -> Result < bool , EncryptionError > {
681- // Check if key is in the list of keys due for rotation
682- let keys_due = self . get_keys_due_for_rotation ( ) . await ?;
683- Ok ( keys_due. contains ( & key_id. to_string ( ) ) )
684- }
685648
686649 /// Start automated key rotation service that runs in the background
687650 /// Returns a future that should be spawned as a background task
@@ -753,41 +716,12 @@ where
753716
754717 /// Refresh statistics by querying the database
755718 pub async fn refresh_stats ( & self ) -> Result < ( ) , EncryptionError > {
756- // Query the database for real statistics
757- let db_stats = self . query_database_statistics ( ) . await ?;
758-
759- if let Ok ( mut stats) = self . stats . lock ( ) {
760- // Update with real database values
761- stats. total_keys = db_stats. total_keys ;
762- stats. active_keys = db_stats. active_keys ;
763- stats. retired_keys = db_stats. retired_keys ;
764- stats. revoked_keys = db_stats. revoked_keys ;
765- stats. expired_keys = db_stats. expired_keys ;
766- stats. average_key_age_days = db_stats. average_key_age_days ;
767- stats. keys_expiring_soon = db_stats. keys_expiring_soon ;
768- stats. keys_due_for_rotation = db_stats. keys_due_for_rotation ;
769-
770- // Keep existing operation counters (these are tracked in memory)
771- // stats.total_access_operations and stats.rotations_performed remain unchanged
772-
773- info ! (
774- "Statistics refreshed from database: {} total keys, {} active, {} retired, {} revoked, {} expired" ,
775- stats. total_keys,
776- stats. active_keys,
777- stats. retired_keys,
778- stats. revoked_keys,
779- stats. expired_keys
780- ) ;
781- }
782-
719+ // Note: Database-specific implementations should override this behavior
720+ // For now, this method doesn't refresh from database to prevent compilation issues
721+ warn ! ( "refresh_stats called on generic implementation - no database refresh performed" ) ;
783722 Ok ( ( ) )
784723 }
785724
786- /// Query the database for comprehensive key statistics
787- async fn query_database_statistics ( & self ) -> Result < KeyManagerStats , EncryptionError > {
788- // Return default stats for generic implementation - concrete implementations will override
789- Ok ( KeyManagerStats :: default ( ) )
790- }
791725
792726 /// Get the current master key ID
793727 pub async fn get_master_key_id ( & self ) -> Option < Uuid > {
@@ -1063,10 +997,6 @@ where
1063997 ) )
1064998 }
1065999
1066- async fn get_keys_due_for_rotation ( & self ) -> Result < Vec < String > , EncryptionError > {
1067- // Return empty list for generic implementation - concrete implementations will override
1068- Ok ( Vec :: new ( ) )
1069- }
10701000
10711001 async fn record_key_usage ( & self , _key_id : & str ) -> Result < ( ) , EncryptionError > {
10721002 // Database-specific implementations are provided in separate impl blocks
@@ -1442,7 +1372,7 @@ where
14421372 let system_key = self . derive_system_encryption_key ( & salt) ?;
14431373
14441374 // Encrypt the master key material with the system key
1445- let encrypted_material = self . encrypt_with_system_key ( & system_key, key_material) ?;
1375+ let _encrypted_material = self . encrypt_with_system_key ( & system_key, key_material) ?;
14461376
14471377 // Database operations are handled by concrete implementations
14481378 // This is a placeholder for generic implementation
@@ -1543,7 +1473,7 @@ where
15431473 fn derive_system_encryption_key ( & self , salt : & [ u8 ] ) -> Result < Vec < u8 > , EncryptionError > {
15441474 use argon2:: {
15451475 Argon2 ,
1546- password_hash:: { PasswordHasher , SaltString , rand_core :: OsRng } ,
1476+ password_hash:: { PasswordHasher , SaltString } ,
15471477 } ;
15481478
15491479 // Use a combination of system properties and configuration for key derivation
@@ -1839,8 +1769,9 @@ impl KeyManager<sqlx::Postgres> {
18391769 Ok ( ( ) )
18401770 }
18411771
1842- /// Check if a specific key is due for rotation (PostgreSQL)
1843- async fn is_key_due_for_rotation_postgres (
1772+ /// Check if a specific key is due for rotation
1773+ #[ cfg( feature = "postgres" ) ]
1774+ pub async fn is_key_due_for_rotation (
18441775 & self ,
18451776 key_id : & str ,
18461777 ) -> Result < bool , EncryptionError > {
@@ -2038,6 +1969,7 @@ impl KeyManager<sqlx::Postgres> {
20381969 }
20391970
20401971 /// Query statistics from PostgreSQL
1972+ #[ cfg( feature = "postgres" ) ]
20411973 pub async fn query_database_statistics ( & self ) -> Result < KeyManagerStats , EncryptionError > {
20421974 // Execute multiple queries to gather comprehensive statistics
20431975 let basic_counts = sqlx:: query (
@@ -2131,7 +2063,8 @@ impl KeyManager<sqlx::Postgres> {
21312063 } )
21322064 }
21332065
2134- /// Get keys due for rotation (PostgreSQL wrapper)
2066+ /// Get keys due for rotation
2067+ #[ cfg( feature = "postgres" ) ]
21352068 pub async fn get_keys_due_for_rotation ( & self ) -> Result < Vec < String > , EncryptionError > {
21362069 self . get_keys_due_for_rotation_postgres ( ) . await
21372070 }
@@ -2362,8 +2295,9 @@ impl KeyManager<sqlx::MySql> {
23622295 Ok ( ( ) )
23632296 }
23642297
2365- /// Check if a specific key is due for rotation (MySQL)
2366- async fn is_key_due_for_rotation_mysql ( & self , key_id : & str ) -> Result < bool , EncryptionError > {
2298+ /// Check if a specific key is due for rotation
2299+ #[ cfg( feature = "mysql" ) ]
2300+ pub async fn is_key_due_for_rotation ( & self , key_id : & str ) -> Result < bool , EncryptionError > {
23672301 let result = sqlx:: query (
23682302 r#"
23692303 SELECT COUNT(*) as count
@@ -2556,6 +2490,7 @@ impl KeyManager<sqlx::MySql> {
25562490 }
25572491
25582492 /// Query statistics from MySQL
2493+ #[ cfg( feature = "mysql" ) ]
25592494 pub async fn query_database_statistics ( & self ) -> Result < KeyManagerStats , EncryptionError > {
25602495 // Execute multiple queries to gather comprehensive statistics
25612496 let basic_counts = sqlx:: query (
@@ -2649,7 +2584,8 @@ impl KeyManager<sqlx::MySql> {
26492584 } )
26502585 }
26512586
2652- /// Get keys due for rotation (MySQL wrapper)
2587+ /// Get keys due for rotation
2588+ #[ cfg( feature = "mysql" ) ]
26532589 pub async fn get_keys_due_for_rotation ( & self ) -> Result < Vec < String > , EncryptionError > {
26542590 self . get_keys_due_for_rotation_mysql ( ) . await
26552591 }
0 commit comments