Skip to content

Commit 4be5ee1

Browse files
committed
fmt
1 parent 6efe5a9 commit 4be5ee1

28 files changed

+294
-237
lines changed

security-framework-sys/src/access_control.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use core_foundation_sys::base::{CFAllocatorRef, CFTypeRef, CFTypeID};
2-
use core_foundation_sys::error::CFErrorRef;
31
use core_foundation_sys::base::CFOptionFlags;
2+
use core_foundation_sys::base::{CFAllocatorRef, CFTypeID, CFTypeRef};
3+
use core_foundation_sys::error::CFErrorRef;
44

55
use crate::base::SecAccessControlRef;
66

@@ -27,6 +27,6 @@ extern "C" {
2727
allocator: CFAllocatorRef,
2828
protection: CFTypeRef,
2929
flags: CFOptionFlags,
30-
error: *mut CFErrorRef
30+
error: *mut CFErrorRef,
3131
) -> SecAccessControlRef;
3232
}

security-framework-sys/src/item.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,13 @@ extern "C" {
3232
pub static kSecAttrKeyClassSymmetric: CFStringRef;
3333

3434
pub static kSecUseKeychain: CFStringRef;
35-
#[cfg(any(feature = "OSX_10_15", target_os="ios"))]
35+
#[cfg(any(feature = "OSX_10_15", target_os = "ios"))]
3636
pub static kSecUseDataProtectionKeychain: CFStringRef;
37-
#[cfg(any(feature = "OSX_10_12", target_os="ios"))]
37+
#[cfg(any(feature = "OSX_10_12", target_os = "ios"))]
3838
pub static kSecAttrTokenID: CFStringRef;
39-
#[cfg(any(feature = "OSX_10_12", target_os="ios"))]
39+
#[cfg(any(feature = "OSX_10_12", target_os = "ios"))]
4040
pub static kSecAttrTokenIDSecureEnclave: CFStringRef;
4141

42-
4342
pub static kSecAttrKeySizeInBits: CFStringRef;
4443

4544
pub static kSecAttrKeyTypeECSECPrimeRandom: CFStringRef;
@@ -58,7 +57,7 @@ extern "C" {
5857
pub static kSecAttrKeyTypeRC2: CFStringRef;
5958
#[cfg(target_os = "macos")]
6059
pub static kSecAttrKeyTypeCAST: CFStringRef;
61-
#[cfg(any(feature = "OSX_10_9", target_os="ios"))]
60+
#[cfg(any(feature = "OSX_10_9", target_os = "ios"))]
6261
pub static kSecAttrKeyTypeEC: CFStringRef;
6362

6463
pub static kSecAttrAccessGroup: CFStringRef;

security-framework-sys/src/key.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ extern "C" {
1414
pub fn SecKeyGetTypeID() -> CFTypeID;
1515

1616
#[cfg(any(feature = "OSX_10_12", target_os = "ios"))]
17-
pub fn SecKeyCreateRandomKey(
18-
parameters: CFDictionaryRef,
19-
error: *mut CFErrorRef,
20-
) -> SecKeyRef;
17+
pub fn SecKeyCreateRandomKey(parameters: CFDictionaryRef, error: *mut CFErrorRef) -> SecKeyRef;
2118

2219
#[cfg(target_os = "macos")]
2320
pub fn SecKeyCreateFromData(

security-framework-sys/src/policy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use core_foundation_sys::base::{Boolean, CFTypeID};
21
#[cfg(any(feature = "OSX_10_9", target_os = "ios"))]
32
use core_foundation_sys::base::CFOptionFlags;
3+
use core_foundation_sys::base::{Boolean, CFTypeID};
44
use core_foundation_sys::string::CFStringRef;
55

66
use crate::base::SecPolicyRef;

security-framework-sys/src/trust.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ pub const kSecTrustResultRecoverableTrustFailure: SecTrustResultType = 5;
1616
pub const kSecTrustResultFatalTrustFailure: SecTrustResultType = 6;
1717
pub const kSecTrustResultOtherError: SecTrustResultType = 7;
1818

19-
2019
#[cfg(target_os = "macos")]
2120
mod flags {
2221
pub type SecTrustOptionFlags = u32;
@@ -25,9 +24,9 @@ mod flags {
2524
pub const kSecTrustOptionLeafIsCA: SecTrustOptionFlags = 0x0000_0002;
2625
pub const kSecTrustOptionFetchIssuerFromNet: SecTrustOptionFlags = 0x0000_0004;
2726
pub const kSecTrustOptionAllowExpiredRoot: SecTrustOptionFlags = 0x0000_0008;
28-
pub const kSecTrustOptionRequireRevPerCert: SecTrustOptionFlags= 0x0000_0010;
29-
pub const kSecTrustOptionUseTrustSettings: SecTrustOptionFlags= 0x0000_0020;
30-
pub const kSecTrustOptionImplicitAnchors: SecTrustOptionFlags= 0x0000_0040;
27+
pub const kSecTrustOptionRequireRevPerCert: SecTrustOptionFlags = 0x0000_0010;
28+
pub const kSecTrustOptionUseTrustSettings: SecTrustOptionFlags = 0x0000_0020;
29+
pub const kSecTrustOptionImplicitAnchors: SecTrustOptionFlags = 0x0000_0040;
3130
}
3231

3332
#[cfg(target_os = "macos")]
@@ -73,6 +72,9 @@ extern "C" {
7372
#[cfg(any(feature = "OSX_10_9", target_os = "ios"))]
7473
pub fn SecTrustSetOCSPResponse(trust: SecTrustRef, responseData: CFTypeRef) -> OSStatus;
7574
#[cfg(any(feature = "OSX_10_14", target_os = "ios"))]
76-
pub fn SecTrustSetSignedCertificateTimestamps(trust: SecTrustRef, sctArray: CFArrayRef) -> OSStatus;
75+
pub fn SecTrustSetSignedCertificateTimestamps(
76+
trust: SecTrustRef,
77+
sctArray: CFArrayRef,
78+
) -> OSStatus;
7779
pub fn SecTrustCopyPublicKey(trust: SecTrustRef) -> SecKeyRef;
7880
}

security-framework/src/access_control.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,30 @@ declare_TCFType! {
1111
/// A type representing sec access control settings.
1212
SecAccessControl, SecAccessControlRef
1313
}
14-
impl_TCFType!(SecAccessControl, SecAccessControlRef, SecAccessControlGetTypeID);
14+
impl_TCFType!(
15+
SecAccessControl,
16+
SecAccessControlRef,
17+
SecAccessControlGetTypeID
18+
);
1519

1620
unsafe impl Sync for SecAccessControl {}
1721
unsafe impl Send for SecAccessControl {}
1822

19-
2023
impl SecAccessControl {
21-
2224
/// Create `AccessControl` object from flags
2325
pub fn create_with_flags(flags: CFOptionFlags) -> Result<Self> {
24-
unsafe {
25-
let access_control = SecAccessControlCreateWithFlags(kCFAllocatorDefault, null(), flags, ptr::null_mut());
26+
unsafe {
27+
let access_control = SecAccessControlCreateWithFlags(
28+
kCFAllocatorDefault,
29+
null(),
30+
flags,
31+
ptr::null_mut(),
32+
);
2633
if access_control.is_null() {
2734
Err(Error::from_code(errSecParam))
2835
} else {
2936
Ok(Self::wrap_under_create_rule(access_control))
3037
}
3138
}
3239
}
33-
}
40+
}

security-framework/src/authorization.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
/// * `AuthorizationCopyRightsAsync`
88
/// * Provide constants for well known item names
99
use crate::base::{Error, Result};
10+
#[cfg(all(target_os = "macos", feature = "job-bless"))]
11+
use core_foundation::base::Boolean;
1012
use core_foundation::base::{CFTypeRef, TCFType};
1113
use core_foundation::bundle::CFBundleRef;
1214
use core_foundation::dictionary::{CFDictionary, CFDictionaryRef};
13-
use core_foundation::string::{CFString, CFStringRef};
1415
#[cfg(all(target_os = "macos", feature = "job-bless"))]
1516
use core_foundation::error::CFError;
1617
#[cfg(all(target_os = "macos", feature = "job-bless"))]
1718
use core_foundation::error::CFErrorRef;
18-
#[cfg(all(target_os = "macos", feature = "job-bless"))]
19-
use core_foundation::base::Boolean;
19+
use core_foundation::string::{CFString, CFStringRef};
2020
use security_framework_sys::authorization as sys;
2121
use security_framework_sys::base::errSecConversionError;
2222
use std::convert::TryFrom;
@@ -170,7 +170,8 @@ impl AuthorizationItemSetBuilder {
170170
/// Creates a new `AuthorizationItemSetStore`, which simplifies creating
171171
/// owned vectors of `AuthorizationItem`s.
172172
#[inline(always)]
173-
#[must_use] pub fn new() -> AuthorizationItemSetBuilder {
173+
#[must_use]
174+
pub fn new() -> AuthorizationItemSetBuilder {
174175
Default::default()
175176
}
176177

@@ -217,7 +218,8 @@ impl AuthorizationItemSetBuilder {
217218

218219
/// Creates the `sys::AuthorizationItemSet`, and gives you ownership of the
219220
/// data it points to.
220-
#[must_use] pub fn build(mut self) -> AuthorizationItemSetStorage {
221+
#[must_use]
222+
pub fn build(mut self) -> AuthorizationItemSetStorage {
221223
self.storage.items = self
222224
.storage
223225
.names
@@ -558,7 +560,6 @@ impl Authorization {
558560
/// Submits the executable for the given label as a `launchd` job.
559561
#[cfg(all(target_os = "macos", feature = "job-bless"))]
560562
pub fn job_bless(&self, label: &str) -> Result<(), CFError> {
561-
562563
#[link(name = "ServiceManagement", kind = "framework")]
563564
extern "C" {
564565
static kSMDomainSystemLaunchd: CFStringRef;
@@ -577,7 +578,7 @@ impl Authorization {
577578
kSMDomainSystemLaunchd,
578579
CFString::new(label).as_concrete_TypeRef(),
579580
self.handle,
580-
&mut error
581+
&mut error,
581582
);
582583
if !error.is_null() {
583584
return Err(CFError::wrap_under_create_rule(error));

security-framework/src/certificate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use core_foundation::data::CFData;
66
use core_foundation::dictionary::CFMutableDictionary;
77
use core_foundation::string::CFString;
88
use core_foundation_sys::base::kCFAllocatorDefault;
9-
use security_framework_sys::base::{errSecParam, SecCertificateRef};
109
#[cfg(target_os = "ios")]
11-
use security_framework_sys::base::{errSecSuccess, errSecNotTrusted};
10+
use security_framework_sys::base::{errSecNotTrusted, errSecSuccess};
11+
use security_framework_sys::base::{errSecParam, SecCertificateRef};
1212
use security_framework_sys::certificate::*;
1313
use security_framework_sys::keychain_item::SecItemDelete;
1414
use std::fmt;

security-framework/src/item.rs

+41-33
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use core_foundation::string::CFString;
1111
use core_foundation_sys::base::{CFCopyDescription, CFGetTypeID, CFRelease, CFTypeRef};
1212
use core_foundation_sys::string::CFStringRef;
1313
use security_framework_sys::item::*;
14-
use security_framework_sys::keychain_item::{SecItemCopyMatching, SecItemAdd};
14+
use security_framework_sys::keychain_item::{SecItemAdd, SecItemCopyMatching};
1515
use std::collections::HashMap;
1616
use std::fmt;
1717
use std::ptr;
@@ -31,31 +31,36 @@ pub struct ItemClass(CFStringRef);
3131
impl ItemClass {
3232
/// Look for `SecKeychainItem`s corresponding to generic passwords.
3333
#[inline(always)]
34-
#[must_use] pub fn generic_password() -> Self {
34+
#[must_use]
35+
pub fn generic_password() -> Self {
3536
unsafe { Self(kSecClassGenericPassword) }
3637
}
3738

3839
/// Look for `SecKeychainItem`s corresponding to internet passwords.
3940
#[inline(always)]
40-
#[must_use] pub fn internet_password() -> Self {
41+
#[must_use]
42+
pub fn internet_password() -> Self {
4143
unsafe { Self(kSecClassInternetPassword) }
4244
}
4345

4446
/// Look for `SecCertificate`s.
4547
#[inline(always)]
46-
#[must_use] pub fn certificate() -> Self {
48+
#[must_use]
49+
pub fn certificate() -> Self {
4750
unsafe { Self(kSecClassCertificate) }
4851
}
4952

5053
/// Look for `SecKey`s.
5154
#[inline(always)]
52-
#[must_use] pub fn key() -> Self {
55+
#[must_use]
56+
pub fn key() -> Self {
5357
unsafe { Self(kSecClassKey) }
5458
}
5559

5660
/// Look for `SecIdentity`s.
5761
#[inline(always)]
58-
#[must_use] pub fn identity() -> Self {
62+
#[must_use]
63+
pub fn identity() -> Self {
5964
unsafe { Self(kSecClassIdentity) }
6065
}
6166

@@ -152,7 +157,8 @@ impl crate::ItemSearchOptionsInternals for ItemSearchOptions {
152157
impl ItemSearchOptions {
153158
/// Creates a new builder with default options.
154159
#[inline(always)]
155-
#[must_use] pub fn new() -> Self {
160+
#[must_use]
161+
pub fn new() -> Self {
156162
Self::default()
157163
}
158164

@@ -234,8 +240,8 @@ impl ItemSearchOptions {
234240
}
235241

236242
/// 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
239245
/// a key by public key hash use [ItemSearchOptions::application_label]
240246
/// instead.
241247
#[inline(always)]
@@ -245,9 +251,9 @@ impl ItemSearchOptions {
245251
}
246252

247253
/// 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]
251257
/// instead.
252258
#[inline(always)]
253259
pub fn application_label(&mut self, app_label: &[u8]) -> &mut Self {
@@ -474,7 +480,8 @@ impl SearchResult {
474480
/// `HashMap<String, String>`. This transformation isn't
475481
/// comprehensive, it only supports `CFString`, `CFDate`, and `CFData`
476482
/// 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>> {
478485
match *self {
479486
Self::Dict(ref d) => unsafe {
480487
let mut retmap = HashMap::new();
@@ -544,25 +551,27 @@ impl ItemAddOptions {
544551
ItemAddValue::Data { class, .. } => Some(*class),
545552
};
546553
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());
548555
}
549556

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()),
553560
};
554561
dict.add(&value_pair.0, &value_pair.1);
555562

556-
557563
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"))]
560566
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")]
566575
Location::FileKeychain(keychain) => {
567576
dict.add(&unsafe { kSecUseKeychain }.to_void(), &keychain.to_void());
568577
},
@@ -571,7 +580,7 @@ impl ItemAddOptions {
571580

572581
let label = self.label.as_deref().map(CFString::from);
573582
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());
575584
}
576585

577586
dict.to_immutable()
@@ -583,15 +592,14 @@ pub enum ItemAddValue {
583592
/// Pass item by Ref (kSecValueRef)
584593
Ref(AddRef),
585594
/// Pass item by Data (kSecValueData)
586-
Data{
595+
Data {
587596
/// The item class (kSecClass).
588597
class: ItemClass,
589598
/// The item data.
590-
data: CFData
599+
data: CFData,
591600
},
592601
}
593602

594-
595603
/// Type of Ref to add to the keychain.
596604
pub enum AddRef {
597605
/// SecKey
@@ -633,15 +641,15 @@ pub enum Location {
633641
/// This keychain requires the calling binary to be codesigned with
634642
/// entitlements for the KeychainAccessGroups it is supposed to
635643
/// access.
636-
#[cfg(any(feature = "OSX_10_15", target_os="ios"))]
644+
#[cfg(any(feature = "OSX_10_15", target_os = "ios"))]
637645
DataProtectionKeychain,
638646
/// Store the key in the default file-based keychain. On macOS, defaults to
639647
/// the Login keychain.
640-
#[cfg(target_os="macos")]
648+
#[cfg(target_os = "macos")]
641649
DefaultFileKeychain,
642650
/// 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),
645653
}
646654

647655
/// Translates to SecItemAdd. Use `ItemAddOptions` to build an `add_params`

0 commit comments

Comments
 (0)