@@ -516,13 +516,6 @@ impl Key {
516
516
}
517
517
}
518
518
519
- /// Requests a key with the given description by searching the thread, process, and session
520
- /// keyrings.
521
- pub fn request_key_auth_key ( create : bool ) -> Result < Self > {
522
- let res = unsafe { keyctl_get_keyring_ID ( KEY_SPEC_REQKEY_AUTH_KEY , create as libc:: c_int ) } ;
523
- check_call ( i64:: from ( res) , Key :: new_impl ( res) )
524
- }
525
-
526
519
/// Requests a key with the given description by searching the thread, process, and session
527
520
/// keyrings.
528
521
pub fn request < K , D > ( description : D ) -> Result < Self >
@@ -635,6 +628,14 @@ impl Key {
635
628
}
636
629
637
630
/// Create an object to manage a key request.
631
+ ///
632
+ /// Before a key may be managed on a thread, an authorization key must be attached to an
633
+ /// available thread keyring.
634
+ ///
635
+ /// Only one key may be managed on a thread at a time. Managing a second key will
636
+ /// invalidate any previous `KeyManager` constructions.
637
+ ///
638
+ /// See `KeyManager::request_key_auth_key`.
638
639
pub fn manage ( & mut self ) -> Result < KeyManager > {
639
640
check_call (
640
641
unsafe { keyctl_assume_authority ( self . id ) } ,
@@ -721,7 +722,7 @@ impl Description {
721
722
}
722
723
723
724
/// A manager for a key to respond to instantiate a key request by the kernel.
724
- #[ derive( Debug , Clone , PartialEq , Eq ) ]
725
+ #[ derive( Debug , PartialEq , Eq ) ]
725
726
pub struct KeyManager {
726
727
key : Key ,
727
728
}
@@ -733,6 +734,21 @@ impl KeyManager {
733
734
}
734
735
}
735
736
737
+ /// Requests the authorization key created by `request_key`.
738
+ ///
739
+ /// This key must be present in an available keyring before `Key::manage` may be called.
740
+ pub fn request_key_auth_key ( create : bool ) -> Result < Key > {
741
+ let res = unsafe { keyctl_get_keyring_ID ( KEY_SPEC_REQKEY_AUTH_KEY , create as libc:: c_int ) } ;
742
+ check_call ( i64:: from ( res) , Key :: new_impl ( res) )
743
+ }
744
+
745
+ /// Drop authority for the current thread.
746
+ ///
747
+ /// This invalidates
748
+ pub fn drop_authority ( ) -> Result < ( ) > {
749
+ check_call ( unsafe { keyctl_assume_authority ( 0 ) } , ( ) )
750
+ }
751
+
736
752
/// Instantiate the key with the given payload.
737
753
pub fn instantiate < P > ( self , keyring : & Keyring , payload : P ) -> Result < ( ) >
738
754
where
0 commit comments