@@ -237,18 +237,21 @@ impl Keyring {
237
237
/// Requires `read` permission on the keyring.
238
238
pub fn read ( & self ) -> Result < ( Vec < Key > , Vec < Keyring > ) > {
239
239
let sz = check_call_ret ( unsafe { keyctl_read ( self . id , ptr:: null_mut ( ) , 0 ) } ) ?;
240
- let mut buffer = Vec :: < key_serial_t > :: with_capacity ( ( sz as usize ) /
241
- mem:: size_of :: < KeyringSerial > ( ) ) ;
240
+ let mut buffer =
241
+ Vec :: < key_serial_t > :: with_capacity ( ( sz as usize ) / mem:: size_of :: < KeyringSerial > ( ) ) ;
242
242
let actual_sz = check_call_ret ( unsafe {
243
- keyctl_read ( self . id ,
244
- buffer. as_mut_ptr ( ) as * mut libc:: c_char ,
245
- sz as usize )
243
+ keyctl_read (
244
+ self . id ,
245
+ buffer. as_mut_ptr ( ) as * mut libc:: c_char ,
246
+ sz as usize ,
247
+ )
246
248
} ) ?;
247
249
unsafe { buffer. set_len ( ( actual_sz as usize ) / mem:: size_of :: < KeyringSerial > ( ) ) } ;
248
250
let keys = buffer. iter ( )
249
251
. map ( |& id| Key :: new_impl ( id) )
250
252
. partition ( |key| key. description ( ) . unwrap ( ) . type_ == "keyring" ) ;
251
- Ok ( ( keys. 1 ,
253
+ Ok ( (
254
+ keys. 1 ,
252
255
keys. 0
253
256
. iter ( )
254
257
. map ( |key| Keyring :: new_impl ( key. id ) )
@@ -285,11 +288,13 @@ impl Keyring {
285
288
let desc_cstr = CString :: new ( description. description ( ) . as_bytes ( ) ) . unwrap ( ) ;
286
289
let payload = payload. payload ( ) ;
287
290
let res = unsafe {
288
- add_key ( type_cstr. as_ptr ( ) ,
289
- desc_cstr. as_ptr ( ) ,
290
- payload. as_ptr ( ) as * const libc:: c_void ,
291
- payload. len ( ) ,
292
- self . id )
291
+ add_key (
292
+ type_cstr. as_ptr ( ) ,
293
+ desc_cstr. as_ptr ( ) ,
294
+ payload. as_ptr ( ) as * const libc:: c_void ,
295
+ payload. len ( ) ,
296
+ self . id ,
297
+ )
293
298
} ;
294
299
check_call ( i64:: from ( res) , Key :: new_impl ( res) )
295
300
}
@@ -343,10 +348,12 @@ impl Keyring {
343
348
let desc_cstr = CString :: new ( description) . unwrap ( ) ;
344
349
let info_cstr = CString :: new ( info) . unwrap ( ) ;
345
350
check_call_ret_serial ( unsafe {
346
- request_key ( type_cstr. as_ptr ( ) ,
347
- desc_cstr. as_ptr ( ) ,
348
- info_cstr. as_ptr ( ) ,
349
- self . id )
351
+ request_key (
352
+ type_cstr. as_ptr ( ) ,
353
+ desc_cstr. as_ptr ( ) ,
354
+ info_cstr. as_ptr ( ) ,
355
+ self . id ,
356
+ )
350
357
} )
351
358
}
352
359
@@ -415,9 +422,11 @@ impl Keyring {
415
422
let sz = check_call_ret ( unsafe { keyctl_describe ( self . id , ptr:: null_mut ( ) , 0 ) } ) ?;
416
423
let mut buffer = Vec :: with_capacity ( sz as usize ) ;
417
424
let actual_sz = check_call_ret ( unsafe {
418
- keyctl_describe ( self . id ,
419
- buffer. as_mut_ptr ( ) as * mut libc:: c_char ,
420
- sz as usize )
425
+ keyctl_describe (
426
+ self . id ,
427
+ buffer. as_mut_ptr ( ) as * mut libc:: c_char ,
428
+ sz as usize ,
429
+ )
421
430
} ) ?;
422
431
unsafe { buffer. set_len ( ( actual_sz - 1 ) as usize ) } ;
423
432
let str_slice = str:: from_utf8 ( & buffer[ ..] ) . unwrap ( ) ;
@@ -439,7 +448,10 @@ impl Keyring {
439
448
/// Any partial seconds are ignored. A timeout of 0 means "no expiration". Requires the
440
449
/// `setattr` permission on the keyring.
441
450
pub fn set_timeout ( & mut self , timeout : Duration ) -> Result < ( ) > {
442
- check_call ( unsafe { keyctl_set_timeout ( self . id , timeout. as_secs ( ) as u32 ) } , ( ) )
451
+ check_call (
452
+ unsafe { keyctl_set_timeout ( self . id , timeout. as_secs ( ) as u32 ) } ,
453
+ ( ) ,
454
+ )
443
455
}
444
456
445
457
/// The security context of the keyring. Depends on the security manager loaded into the kernel
@@ -448,9 +460,11 @@ impl Keyring {
448
460
let sz = check_call_ret ( unsafe { keyctl_get_security ( self . id , ptr:: null_mut ( ) , 0 ) } ) ?;
449
461
let mut buffer = Vec :: with_capacity ( sz as usize ) ;
450
462
let actual_sz = check_call_ret ( unsafe {
451
- keyctl_get_security ( self . id ,
452
- buffer. as_mut_ptr ( ) as * mut libc:: c_char ,
453
- sz as usize )
463
+ keyctl_get_security (
464
+ self . id ,
465
+ buffer. as_mut_ptr ( ) as * mut libc:: c_char ,
466
+ sz as usize ,
467
+ )
454
468
} ) ?;
455
469
unsafe { buffer. set_len ( actual_sz as usize ) } ;
456
470
let str_slice = str:: from_utf8 ( & buffer[ ..] ) . unwrap ( ) ;
@@ -519,10 +533,10 @@ impl Key {
519
533
D : AsRef < [ u8 ] > ,
520
534
{
521
535
let data = data. as_ref ( ) ;
522
- check_call ( unsafe {
523
- keyctl_update ( self . id , data. as_ptr ( ) as * const libc:: c_void , data. len ( ) )
524
- } ,
525
- ( ) )
536
+ check_call (
537
+ unsafe { keyctl_update ( self . id , data. as_ptr ( ) as * const libc:: c_void , data. len ( ) ) } ,
538
+ ( ) ,
539
+ )
526
540
}
527
541
528
542
/// Revokes the key. Requires `write` permission on the key.
@@ -568,9 +582,11 @@ impl Key {
568
582
let sz = check_call_ret ( unsafe { keyctl_read ( self . id , ptr:: null_mut ( ) , 0 ) } ) ?;
569
583
let mut buffer = Vec :: with_capacity ( sz as usize ) ;
570
584
let actual_sz = check_call_ret ( unsafe {
571
- keyctl_read ( self . id ,
572
- buffer. as_mut_ptr ( ) as * mut libc:: c_char ,
573
- sz as usize )
585
+ keyctl_read (
586
+ self . id ,
587
+ buffer. as_mut_ptr ( ) as * mut libc:: c_char ,
588
+ sz as usize ,
589
+ )
574
590
} ) ?;
575
591
unsafe { buffer. set_len ( actual_sz as usize ) } ;
576
592
Ok ( buffer)
@@ -600,15 +616,33 @@ impl Key {
600
616
601
617
/// Create an object to manage a key request.
602
618
pub fn manage ( & mut self ) -> Result < KeyManager > {
603
- check_call ( unsafe { keyctl_assume_authority ( self . id ) } ,
604
- KeyManager :: new ( Key :: new_impl ( self . id ) ) )
619
+ check_call (
620
+ unsafe { keyctl_assume_authority ( self . id ) } ,
621
+ KeyManager :: new ( Key :: new_impl ( self . id ) ) ,
622
+ )
605
623
}
606
624
607
625
/// Compute a Diffie-Hellman prime for use as a shared secret or public key.
608
626
pub fn compute_dh ( private : & Key , prime : & Key , base : & Key ) -> Result < Vec < u8 > > {
609
- let sz = check_call_ret ( unsafe { keyctl_dh_compute ( private. id , prime. id , base. id , ptr:: null_mut ( ) as * mut libc:: c_char , 0 ) } ) ?;
627
+ let sz = check_call_ret ( unsafe {
628
+ keyctl_dh_compute (
629
+ private. id ,
630
+ prime. id ,
631
+ base. id ,
632
+ ptr:: null_mut ( ) as * mut libc:: c_char ,
633
+ 0 ,
634
+ )
635
+ } ) ?;
610
636
let mut buffer = Vec :: with_capacity ( sz as usize ) ;
611
- let actual_sz = check_call_ret ( unsafe { keyctl_dh_compute ( private. id , prime. id , base. id , buffer. as_mut_ptr ( ) as * mut libc:: c_char , sz as usize ) } ) ?;
637
+ let actual_sz = check_call_ret ( unsafe {
638
+ keyctl_dh_compute (
639
+ private. id ,
640
+ prime. id ,
641
+ base. id ,
642
+ buffer. as_mut_ptr ( ) as * mut libc:: c_char ,
643
+ sz as usize ,
644
+ )
645
+ } ) ?;
612
646
unsafe { buffer. set_len ( actual_sz as usize ) } ;
613
647
Ok ( buffer)
614
648
}
@@ -641,15 +675,19 @@ impl Description {
641
675
None
642
676
} else {
643
677
if len > 5 {
644
- error ! ( "New fields detected! Please report this upstream to \
645
- https://github.com/mathstuf/rust-keyutils: {}",
646
- desc) ;
678
+ error ! (
679
+ "New fields detected! Please report this upstream to \
680
+ https://github.com/mathstuf/rust-keyutils: {}",
681
+ desc,
682
+ ) ;
647
683
}
648
684
let bits = KeyPermissions :: from_str_radix ( pieces[ 1 ] , 16 ) . unwrap ( ) ;
649
685
if Permission :: from_bits ( bits) . is_none ( ) {
650
- error ! ( "New permission bits detected! Please report this upstream to \
651
- https://github.com/mathstuf/rust-keyutils: {}",
652
- bits) ;
686
+ error ! (
687
+ "New permission bits detected! Please report this upstream to \
688
+ https://github.com/mathstuf/rust-keyutils: {}",
689
+ bits,
690
+ ) ;
653
691
}
654
692
Some ( Description {
655
693
type_ : pieces[ 4 ] . to_owned ( ) ,
@@ -681,13 +719,17 @@ impl KeyManager {
681
719
P : AsRef < [ u8 ] > ,
682
720
{
683
721
let payload = payload. as_ref ( ) ;
684
- check_call ( unsafe {
685
- keyctl_instantiate ( self . key . id ,
686
- payload. as_ptr ( ) as * const libc:: c_void ,
687
- payload. len ( ) ,
688
- keyring. id )
689
- } ,
690
- ( ) )
722
+ check_call (
723
+ unsafe {
724
+ keyctl_instantiate (
725
+ self . key . id ,
726
+ payload. as_ptr ( ) as * const libc:: c_void ,
727
+ payload. len ( ) ,
728
+ keyring. id ,
729
+ )
730
+ } ,
731
+ ( ) ,
732
+ )
691
733
}
692
734
693
735
/// Reject the key with the given `error`.
@@ -698,8 +740,17 @@ impl KeyManager {
698
740
/// `write` permission on the keyring.
699
741
pub fn reject ( self , keyring : & Keyring , timeout : Duration , error : errno:: Errno ) -> Result < ( ) > {
700
742
let errno:: Errno ( errval) = error;
701
- check_call ( unsafe { keyctl_reject ( self . key . id , timeout. as_secs ( ) as u32 , errval as u32 , keyring. id ) } ,
702
- ( ) )
743
+ check_call (
744
+ unsafe {
745
+ keyctl_reject (
746
+ self . key . id ,
747
+ timeout. as_secs ( ) as u32 ,
748
+ errval as u32 ,
749
+ keyring. id ,
750
+ )
751
+ } ,
752
+ ( ) ,
753
+ )
703
754
}
704
755
705
756
/// Reject the key with `ENOKEY`.
@@ -709,8 +760,10 @@ impl KeyManager {
709
760
/// requesting a non-existant key repeatedly. The requester must have
710
761
/// `write` permission on the keyring.
711
762
pub fn negate ( self , keyring : & Keyring , timeout : Duration ) -> Result < ( ) > {
712
- check_call ( unsafe { keyctl_negate ( self . key . id , timeout. as_secs ( ) as u32 , keyring. id ) } ,
713
- ( ) )
763
+ check_call (
764
+ unsafe { keyctl_negate ( self . key . id , timeout. as_secs ( ) as u32 , keyring. id ) } ,
765
+ ( ) ,
766
+ )
714
767
}
715
768
}
716
769
@@ -734,8 +787,10 @@ mod tests {
734
787
let description = "test:rust-keyutils:add_key" ;
735
788
let payload = "payload" ;
736
789
let key = keyring. add_key :: < keytypes:: User , _ , _ > ( description, payload. as_bytes ( ) ) . unwrap ( ) ;
737
- assert_eq ! ( key. read( ) . unwrap( ) ,
738
- payload. as_bytes( ) . iter( ) . cloned( ) . collect:: <Vec <_>>( ) ) ;
790
+ assert_eq ! (
791
+ key. read( ) . unwrap( ) ,
792
+ payload. as_bytes( ) . iter( ) . cloned( ) . collect:: <Vec <_>>( )
793
+ ) ;
739
794
740
795
// Clean up.
741
796
keyring. unlink_key ( & key) . unwrap ( ) ;
@@ -853,8 +908,10 @@ mod tests {
853
908
let description = "test:rust-keyutils:read_key" ;
854
909
let payload = "payload" ;
855
910
let key = keyring. add_key :: < keytypes:: User , _ , _ > ( description, payload. as_bytes ( ) ) . unwrap ( ) ;
856
- assert_eq ! ( key. read( ) . unwrap( ) ,
857
- payload. as_bytes( ) . iter( ) . cloned( ) . collect:: <Vec <_>>( ) ) ;
911
+ assert_eq ! (
912
+ key. read( ) . unwrap( ) ,
913
+ payload. as_bytes( ) . iter( ) . cloned( ) . collect:: <Vec <_>>( )
914
+ ) ;
858
915
859
916
// Clean up.
860
917
keyring. unlink_key ( & key) . unwrap ( ) ;
@@ -1051,8 +1108,10 @@ mod tests {
1051
1108
let new_payload = "new_payload" ;
1052
1109
let updated_key = keyring. add_key :: < keytypes:: User , _ , _ > ( description, new_payload. as_bytes ( ) ) . unwrap ( ) ;
1053
1110
assert_eq ! ( key, updated_key) ;
1054
- assert_eq ! ( updated_key. read( ) . unwrap( ) ,
1055
- new_payload. as_bytes( ) . iter( ) . cloned( ) . collect:: <Vec <_>>( ) ) ;
1111
+ assert_eq ! (
1112
+ updated_key. read( ) . unwrap( ) ,
1113
+ new_payload. as_bytes( ) . iter( ) . cloned( ) . collect:: <Vec <_>>( )
1114
+ ) ;
1056
1115
1057
1116
// Clean up.
1058
1117
keyring. unlink_key ( & key) . unwrap ( ) ;
0 commit comments