@@ -38,6 +38,7 @@ use std::mem;
38
38
use std:: ptr;
39
39
use std:: result;
40
40
use std:: str;
41
+ use std:: time:: Duration ;
41
42
42
43
/// Reexport of `Errno` as `Error`.
43
44
pub type Error = errno:: Errno ;
@@ -423,10 +424,12 @@ impl Keyring {
423
424
. and_then ( |desc| Description :: parse ( desc) . ok_or ( errno:: Errno ( libc:: EINVAL ) ) )
424
425
}
425
426
426
- /// Set an expiration timer on the keyring to `timeout` seconds in the future. A timeout of 0
427
- /// means "no expiration". Requires the `setattr` permission on the keyring.
428
- pub fn set_timeout ( & mut self , timeout : u32 ) -> Result < ( ) > {
429
- check_call ( unsafe { keyctl_set_timeout ( self . id , timeout) } , ( ) )
427
+ /// Set an expiration timer on the keyring to `timeout`.
428
+ ///
429
+ /// Any partial seconds are ignored. A timeout of 0 means "no expiration". Requires the
430
+ /// `setattr` permission on the keyring.
431
+ pub fn set_timeout ( & mut self , timeout : Duration ) -> Result < ( ) > {
432
+ check_call ( unsafe { keyctl_set_timeout ( self . id , timeout. as_secs ( ) as u32 ) } , ( ) )
430
433
}
431
434
432
435
/// The security context of the keyring. Depends on the security manager loaded into the kernel
@@ -560,10 +563,11 @@ impl Key {
560
563
Ok ( buffer)
561
564
}
562
565
563
- /// Set an expiration timer on the key to `timeout` seconds in the future .
566
+ /// Set an expiration timer on the keyring to `timeout`.
564
567
///
565
- /// A timeout of `0` means "no expiration". Requires the `setattr` permission on the key.
566
- pub fn set_timeout ( & mut self , timeout : u32 ) -> Result < ( ) > {
568
+ /// Any partial seconds are ignored. A timeout of 0 means "no expiration". Requires the
569
+ /// `setattr` permission on the key.
570
+ pub fn set_timeout ( & mut self , timeout : Duration ) -> Result < ( ) > {
567
571
Keyring :: new_impl ( self . id ) . set_timeout ( timeout)
568
572
}
569
573
@@ -669,21 +673,27 @@ impl KeyManager {
669
673
670
674
/// Reject the key with the given `error`.
671
675
///
672
- /// Requests for the key will fail until `timeout` seconds have elapsed. This is to prevent a
673
- /// denial-of-service by requesting a non-existant key repeatedly. The requester must have
676
+ /// Requests for the key will fail until `timeout` has elapsed (partial
677
+ /// seconds are ignored). This is to prevent a denial-of-service by
678
+ /// requesting a non-existant key repeatedly. The requester must have
674
679
/// `write` permission on the keyring.
675
680
///
676
681
/// TODO: Accept `SpecialKeyring` values here. They are special in that they refer to the
677
682
/// *requester's* special keyring and not this one.
678
- pub fn reject ( self , keyring : & Keyring , timeout : u32 , error : errno:: Errno ) -> Result < ( ) > {
683
+ pub fn reject ( self , keyring : & Keyring , timeout : Duration , error : errno:: Errno ) -> Result < ( ) > {
679
684
let errno:: Errno ( errval) = error;
680
- check_call ( unsafe { keyctl_reject ( self . key . id , timeout, errval as u32 , keyring. id ) } ,
685
+ check_call ( unsafe { keyctl_reject ( self . key . id , timeout. as_secs ( ) as u32 , errval as u32 , keyring. id ) } ,
681
686
( ) )
682
687
}
683
688
684
689
/// Reject the key with `ENOKEY`.
685
- pub fn negate ( self , keyring : & Keyring , timeout : u32 ) -> Result < ( ) > {
686
- check_call ( unsafe { keyctl_negate ( self . key . id , timeout, keyring. id ) } ,
690
+ ///
691
+ /// Requests for the key will fail until `timeout` has elapsed (partial
692
+ /// seconds are ignored). This is to prevent a denial-of-service by
693
+ /// requesting a non-existant key repeatedly. The requester must have
694
+ /// `write` permission on the keyring.
695
+ pub fn negate ( self , keyring : & Keyring , timeout : Duration ) -> Result < ( ) > {
696
+ check_call ( unsafe { keyctl_negate ( self . key . id , timeout. as_secs ( ) as u32 , keyring. id ) } ,
687
697
( ) )
688
698
}
689
699
}
0 commit comments