@@ -105,6 +105,7 @@ use crate::{
105105 legacy_encryptor:: LegacyEncryptor ,
106106 metrics:: {
107107 log_actions_token_expired,
108+ log_legacy_admin_key,
108109 log_store_file_auth_expired,
109110 } ,
110111 secret:: InstanceSecret ,
@@ -886,11 +887,12 @@ impl KeyBroker {
886887 pub fn is_encrypted_admin_key ( & self , key : & str ) -> bool {
887888 let encrypted_part = split_admin_key ( key) . map ( |( _, key) | key) . unwrap_or ( key) ;
888889 let admin_key: Result < AdminKeyProto , _ > = self
889- . encryptor
890- . decode_proto ( ADMIN_KEY_VERSION , encrypted_part)
890+ . admin_key_encryptor
891+ . decrypt_proto ( ADMIN_KEY_VERSION , encrypted_part)
891892 . or_else ( |_| {
892- self . admin_key_encryptor
893- . decrypt_proto ( ADMIN_KEY_VERSION , encrypted_part)
893+ self . encryptor
894+ . decode_proto ( ADMIN_KEY_VERSION , encrypted_part)
895+ . inspect ( |_| log_legacy_admin_key ( ) )
894896 } ) ;
895897 admin_key. is_ok ( )
896898 }
@@ -905,11 +907,12 @@ impl KeyBroker {
905907 identity,
906908 is_read_only,
907909 } = self
908- . encryptor
909- . decode_proto ( ADMIN_KEY_VERSION , encrypted_part)
910+ . admin_key_encryptor
911+ . decrypt_proto ( ADMIN_KEY_VERSION , encrypted_part)
910912 . or_else ( |_| {
911- self . admin_key_encryptor
912- . decrypt_proto ( ADMIN_KEY_VERSION , encrypted_part)
913+ self . encryptor
914+ . decode_proto ( ADMIN_KEY_VERSION , encrypted_part)
915+ . inspect ( |_| log_legacy_admin_key ( ) )
913916 } )
914917 . with_context ( || format ! ( "Couldn't decode the AdminKeyProto {key}" ) ) ?;
915918 let instance_name = instance_name
@@ -947,12 +950,8 @@ impl KeyBroker {
947950 authorization_type,
948951 component_id,
949952 } = self
950- . encryptor
951- . decode_proto ( STORE_FILE_AUTHZ_VERSION , store_file_authorization)
952- . or_else ( |_| {
953- self . store_file_encryptor
954- . decrypt_proto ( STORE_FILE_AUTHZ_VERSION , store_file_authorization)
955- } )
953+ . store_file_encryptor
954+ . decrypt_proto ( STORE_FILE_AUTHZ_VERSION , store_file_authorization)
956955 . context ( ErrorMetadata :: unauthenticated (
957956 "StorageTokenInvalid" ,
958957 "Couldn't decode the StoreFileAuthorization token" ,
@@ -1047,9 +1046,8 @@ impl KeyBroker {
10471046 ) -> anyhow:: Result < Cursor > {
10481047 let cursor_version = persistence_version. index_key_version ( CURSOR_VERSION ) ;
10491048 let proto: InstanceCursorProto = self
1050- . encryptor
1051- . decode_proto ( cursor_version, & cursor)
1052- . or_else ( |_| self . cursor_encryptor . decrypt_proto ( cursor_version, & cursor) )
1049+ . cursor_encryptor
1050+ . decrypt_proto ( cursor_version, & cursor)
10531051 . with_context ( cursor_parse_error) ?;
10541052 self . proto_to_cursor ( proto)
10551053 }
@@ -1081,12 +1079,8 @@ impl KeyBroker {
10811079 None => Ok ( QueryJournal :: new ( ) ) ,
10821080 Some ( journal) => {
10831081 let proto: InstanceQueryJournalProto = self
1084- . encryptor
1085- . decode_proto ( query_journal_version, & journal)
1086- . or_else ( |_| {
1087- self . journal_encryptor
1088- . decrypt_proto ( query_journal_version, & journal)
1089- } )
1082+ . journal_encryptor
1083+ . decrypt_proto ( query_journal_version, & journal)
10901084 . with_context ( cursor_parse_error) ?;
10911085 let end_cursor = match proto. end_cursor {
10921086 Some ( cursor) => Some ( self . proto_to_cursor ( cursor) ?) ,
@@ -1122,12 +1116,8 @@ impl KeyBroker {
11221116 issued_s,
11231117 component_id,
11241118 } = self
1125- . encryptor
1126- . decode_proto ( ACTION_KEY_VERSION , token)
1127- . or_else ( |_| {
1128- self . action_callback_encryptor
1129- . decrypt_proto ( ACTION_KEY_VERSION , token)
1130- } )
1119+ . action_callback_encryptor
1120+ . decrypt_proto ( ACTION_KEY_VERSION , token)
11311121 . with_context ( || format ! ( "Couldn't decode ActionCallbackTokenProto {token}" ) ) ?;
11321122
11331123 anyhow:: ensure!( issued_s != 0 , "ActionCallbackTokenProto missing issued_s" ) ;
@@ -1395,5 +1385,6 @@ mod tests {
13951385 let roundtripped = AdminIdentity :: from_proto_unchecked( proto) . unwrap( ) ;
13961386 assert_eq!( admin_identity, roundtripped) ;
13971387 }
1388+
13981389 }
13991390}
0 commit comments