@@ -11,7 +11,7 @@ use core_foundation::string::CFString;
11
11
use core_foundation_sys:: base:: { CFCopyDescription , CFGetTypeID , CFRelease , CFTypeRef } ;
12
12
use core_foundation_sys:: string:: CFStringRef ;
13
13
use security_framework_sys:: item:: * ;
14
- use security_framework_sys:: keychain_item:: { SecItemCopyMatching , SecItemAdd } ;
14
+ use security_framework_sys:: keychain_item:: { SecItemAdd , SecItemCopyMatching } ;
15
15
use std:: collections:: HashMap ;
16
16
use std:: fmt;
17
17
use std:: ptr;
@@ -31,31 +31,36 @@ pub struct ItemClass(CFStringRef);
31
31
impl ItemClass {
32
32
/// Look for `SecKeychainItem`s corresponding to generic passwords.
33
33
#[ inline( always) ]
34
- #[ must_use] pub fn generic_password ( ) -> Self {
34
+ #[ must_use]
35
+ pub fn generic_password ( ) -> Self {
35
36
unsafe { Self ( kSecClassGenericPassword) }
36
37
}
37
38
38
39
/// Look for `SecKeychainItem`s corresponding to internet passwords.
39
40
#[ inline( always) ]
40
- #[ must_use] pub fn internet_password ( ) -> Self {
41
+ #[ must_use]
42
+ pub fn internet_password ( ) -> Self {
41
43
unsafe { Self ( kSecClassInternetPassword) }
42
44
}
43
45
44
46
/// Look for `SecCertificate`s.
45
47
#[ inline( always) ]
46
- #[ must_use] pub fn certificate ( ) -> Self {
48
+ #[ must_use]
49
+ pub fn certificate ( ) -> Self {
47
50
unsafe { Self ( kSecClassCertificate) }
48
51
}
49
52
50
53
/// Look for `SecKey`s.
51
54
#[ inline( always) ]
52
- #[ must_use] pub fn key ( ) -> Self {
55
+ #[ must_use]
56
+ pub fn key ( ) -> Self {
53
57
unsafe { Self ( kSecClassKey) }
54
58
}
55
59
56
60
/// Look for `SecIdentity`s.
57
61
#[ inline( always) ]
58
- #[ must_use] pub fn identity ( ) -> Self {
62
+ #[ must_use]
63
+ pub fn identity ( ) -> Self {
59
64
unsafe { Self ( kSecClassIdentity) }
60
65
}
61
66
@@ -152,7 +157,8 @@ impl crate::ItemSearchOptionsInternals for ItemSearchOptions {
152
157
impl ItemSearchOptions {
153
158
/// Creates a new builder with default options.
154
159
#[ inline( always) ]
155
- #[ must_use] pub fn new ( ) -> Self {
160
+ #[ must_use]
161
+ pub fn new ( ) -> Self {
156
162
Self :: default ( )
157
163
}
158
164
@@ -234,8 +240,8 @@ impl ItemSearchOptions {
234
240
}
235
241
236
242
/// Search for a certificate with the given public key hash.
237
- ///
238
- /// This is only compatible with [ItemClass::certificate], to search for
243
+ ///
244
+ /// This is only compatible with [ItemClass::certificate], to search for
239
245
/// a key by public key hash use [ItemSearchOptions::application_label]
240
246
/// instead.
241
247
#[ inline( always) ]
@@ -245,9 +251,9 @@ impl ItemSearchOptions {
245
251
}
246
252
247
253
/// Search for a key with the given public key hash.
248
- ///
249
- /// This is only compatible with [ItemClass::key], to search for a
250
- /// certificate by the public key hash use [ItemSearchOptions::pub_key_hash]
254
+ ///
255
+ /// This is only compatible with [ItemClass::key], to search for a
256
+ /// certificate by the public key hash use [ItemSearchOptions::pub_key_hash]
251
257
/// instead.
252
258
#[ inline( always) ]
253
259
pub fn application_label ( & mut self , app_label : & [ u8 ] ) -> & mut Self {
@@ -474,7 +480,8 @@ impl SearchResult {
474
480
/// `HashMap<String, String>`. This transformation isn't
475
481
/// comprehensive, it only supports `CFString`, `CFDate`, and `CFData`
476
482
/// value types.
477
- #[ must_use] pub fn simplify_dict ( & self ) -> Option < HashMap < String , String > > {
483
+ #[ must_use]
484
+ pub fn simplify_dict ( & self ) -> Option < HashMap < String , String > > {
478
485
match * self {
479
486
Self :: Dict ( ref d) => unsafe {
480
487
let mut retmap = HashMap :: new ( ) ;
@@ -544,25 +551,27 @@ impl ItemAddOptions {
544
551
ItemAddValue :: Data { class, .. } => Some ( * class) ,
545
552
} ;
546
553
if let Some ( class) = class_opt {
547
- dict. add ( & unsafe { kSecClass} . to_void ( ) , & class. 0 . to_void ( ) ) ;
554
+ dict. add ( & unsafe { kSecClass } . to_void ( ) , & class. 0 . to_void ( ) ) ;
548
555
}
549
556
550
- let value_pair = match & self . value {
551
- ItemAddValue :: Ref ( ref_) => ( unsafe { kSecValueRef} . to_void ( ) , ref_. ref_ ( ) ) ,
552
- ItemAddValue :: Data { data, ..} => ( unsafe { kSecValueData} . to_void ( ) , data. to_void ( ) ) ,
557
+ let value_pair = match & self . value {
558
+ ItemAddValue :: Ref ( ref_) => ( unsafe { kSecValueRef } . to_void ( ) , ref_. ref_ ( ) ) ,
559
+ ItemAddValue :: Data { data, .. } => ( unsafe { kSecValueData } . to_void ( ) , data. to_void ( ) ) ,
553
560
} ;
554
561
dict. add ( & value_pair. 0 , & value_pair. 1 ) ;
555
562
556
-
557
563
if let Some ( location) = & self . location {
558
- match location{
559
- #[ cfg( any( feature = "OSX_10_15" , target_os= "ios" ) ) ]
564
+ match location {
565
+ #[ cfg( any( feature = "OSX_10_15" , target_os = "ios" ) ) ]
560
566
Location :: DataProtectionKeychain => {
561
- dict. add ( & unsafe { kSecUseDataProtectionKeychain } . to_void ( ) , & CFBoolean :: true_value ( ) . to_void ( ) ) ;
562
- } ,
563
- #[ cfg( target_os="macos" ) ]
564
- Location :: DefaultFileKeychain => { } ,
565
- #[ cfg( target_os="macos" ) ]
567
+ dict. add (
568
+ & unsafe { kSecUseDataProtectionKeychain } . to_void ( ) ,
569
+ & CFBoolean :: true_value ( ) . to_void ( ) ,
570
+ ) ;
571
+ }
572
+ #[ cfg( target_os = "macos" ) ]
573
+ Location :: DefaultFileKeychain => { }
574
+ #[ cfg( target_os = "macos" ) ]
566
575
Location :: FileKeychain ( keychain) => {
567
576
dict. add ( & unsafe { kSecUseKeychain } . to_void ( ) , & keychain. to_void ( ) ) ;
568
577
} ,
@@ -571,7 +580,7 @@ impl ItemAddOptions {
571
580
572
581
let label = self . label . as_deref ( ) . map ( CFString :: from) ;
573
582
if let Some ( label) = & label {
574
- dict. add ( & unsafe { kSecAttrLabel} . to_void ( ) , & label. to_void ( ) ) ;
583
+ dict. add ( & unsafe { kSecAttrLabel } . to_void ( ) , & label. to_void ( ) ) ;
575
584
}
576
585
577
586
dict. to_immutable ( )
@@ -583,15 +592,14 @@ pub enum ItemAddValue {
583
592
/// Pass item by Ref (kSecValueRef)
584
593
Ref ( AddRef ) ,
585
594
/// Pass item by Data (kSecValueData)
586
- Data {
595
+ Data {
587
596
/// The item class (kSecClass).
588
597
class : ItemClass ,
589
598
/// The item data.
590
- data : CFData
599
+ data : CFData ,
591
600
} ,
592
601
}
593
602
594
-
595
603
/// Type of Ref to add to the keychain.
596
604
pub enum AddRef {
597
605
/// SecKey
@@ -633,15 +641,15 @@ pub enum Location {
633
641
/// This keychain requires the calling binary to be codesigned with
634
642
/// entitlements for the KeychainAccessGroups it is supposed to
635
643
/// access.
636
- #[ cfg( any( feature = "OSX_10_15" , target_os= "ios" ) ) ]
644
+ #[ cfg( any( feature = "OSX_10_15" , target_os = "ios" ) ) ]
637
645
DataProtectionKeychain ,
638
646
/// Store the key in the default file-based keychain. On macOS, defaults to
639
647
/// the Login keychain.
640
- #[ cfg( target_os= "macos" ) ]
648
+ #[ cfg( target_os = "macos" ) ]
641
649
DefaultFileKeychain ,
642
650
/// Store the key in a specific file-based keychain.
643
- #[ cfg( target_os= "macos" ) ]
644
- FileKeychain ( crate :: os:: macos:: keychain:: SecKeychain )
651
+ #[ cfg( target_os = "macos" ) ]
652
+ FileKeychain ( crate :: os:: macos:: keychain:: SecKeychain ) ,
645
653
}
646
654
647
655
/// Translates to SecItemAdd. Use `ItemAddOptions` to build an `add_params`
0 commit comments