@@ -218,14 +218,14 @@ impl Keyring {
218
218
check_call ( unsafe { keyctl_unlink ( keyring. id , self . id ) } )
219
219
}
220
220
221
- fn search_impl < K > ( & self , description : & str ) -> KeyringSerial
221
+ fn search_impl < K > ( & self , description : & str , destination : Option < & mut Keyring > ) -> KeyringSerial
222
222
where
223
223
K : KeyType ,
224
224
{
225
225
let type_cstr = CString :: new ( K :: name ( ) ) . unwrap ( ) ;
226
226
let desc_cstr = CString :: new ( description) . unwrap ( ) ;
227
227
into_serial ( unsafe {
228
- keyctl_search ( self . id , type_cstr. as_ptr ( ) , desc_cstr. as_ptr ( ) , self . id )
228
+ keyctl_search ( self . id , type_cstr. as_ptr ( ) , desc_cstr. as_ptr ( ) , destination . map ( |dest| dest . id ) )
229
229
} )
230
230
}
231
231
@@ -234,12 +234,13 @@ impl Keyring {
234
234
/// If it is found, it is attached to the keyring (if `write` permission to the keyring and
235
235
/// `link` permission on the key exist) and return it. Requires the `search` permission on the
236
236
/// keyring. Any children keyrings without the `search` permission are ignored.
237
- pub fn search_for_key < K , D > ( & self , description : D ) -> Result < Key >
237
+ pub fn search_for_key < ' a , K , D , DK > ( & self , description : D , destination : DK ) -> Result < Key >
238
238
where
239
239
K : KeyType ,
240
240
D : Borrow < K :: Description > ,
241
+ DK : Into < Option < & ' a mut Keyring > > ,
241
242
{
242
- check_call_key ( self . search_impl :: < K > ( & description. borrow ( ) . description ( ) ) )
243
+ check_call_key ( self . search_impl :: < K > ( & description. borrow ( ) . description ( ) , destination . into ( ) ) )
243
244
}
244
245
245
246
/// Recursively search the keyring for a keyring with the matching description.
@@ -248,12 +249,13 @@ impl Keyring {
248
249
/// `link` permission on the found keyring exist) and return it. Requires the `search`
249
250
/// permission on the keyring. Any children keyrings without the `search` permission are
250
251
/// ignored.
251
- pub fn search_for_keyring < D > ( & self , description : D ) -> Result < Self >
252
+ pub fn search_for_keyring < ' a , D , DK > ( & self , description : D , destination : DK ) -> Result < Self >
252
253
where
253
254
D : Borrow < <keytypes:: Keyring as KeyType >:: Description > ,
255
+ DK : Into < Option < & ' a mut Keyring > > ,
254
256
{
255
257
check_call_keyring (
256
- self . search_impl :: < keytypes:: Keyring > ( & description. borrow ( ) . description ( ) ) ,
258
+ self . search_impl :: < keytypes:: Keyring > ( & description. borrow ( ) . description ( ) , destination . into ( ) ) ,
257
259
)
258
260
}
259
261
@@ -962,44 +964,4 @@ mod tests {
962
964
keyring. unlink_key ( & key) . unwrap ( ) ;
963
965
keyring. invalidate ( ) . unwrap ( ) ;
964
966
}
965
-
966
- #[ test]
967
- fn test_search_key ( ) {
968
- let mut keyring = utils:: new_test_keyring ( ) ;
969
- let mut new_keyring = keyring. add_keyring ( "new_keyring" ) . unwrap ( ) ;
970
- let mut new_inner_keyring = new_keyring. add_keyring ( "new_inner_keyring" ) . unwrap ( ) ;
971
-
972
- // Create the key.
973
- let description = "test:rust-keyutils:search_key" ;
974
- let payload = "payload" ;
975
- let key = new_inner_keyring
976
- . add_key :: < keytypes:: User , _ , _ > ( description, payload. as_bytes ( ) )
977
- . unwrap ( ) ;
978
-
979
- let found_key = keyring
980
- . search_for_key :: < keytypes:: User , _ > ( description)
981
- . unwrap ( ) ;
982
- assert_eq ! ( found_key, key) ;
983
-
984
- // Clean up.
985
- new_inner_keyring. unlink_key ( & key) . unwrap ( ) ;
986
- new_inner_keyring. invalidate ( ) . unwrap ( ) ;
987
- new_keyring. invalidate ( ) . unwrap ( ) ;
988
- keyring. invalidate ( ) . unwrap ( ) ;
989
- }
990
-
991
- #[ test]
992
- fn test_search_keyring ( ) {
993
- let mut keyring = utils:: new_test_keyring ( ) ;
994
- let mut new_keyring = keyring. add_keyring ( "new_keyring" ) . unwrap ( ) ;
995
- let new_inner_keyring = new_keyring. add_keyring ( "new_inner_keyring" ) . unwrap ( ) ;
996
-
997
- let found_keyring = keyring. search_for_keyring ( "new_inner_keyring" ) . unwrap ( ) ;
998
- assert_eq ! ( found_keyring, new_inner_keyring) ;
999
-
1000
- // Clean up.
1001
- new_inner_keyring. invalidate ( ) . unwrap ( ) ;
1002
- new_keyring. invalidate ( ) . unwrap ( ) ;
1003
- keyring. invalidate ( ) . unwrap ( ) ;
1004
- }
1005
967
}
0 commit comments