Skip to content

Commit 085d32c

Browse files
committed
fmt
1 parent a240237 commit 085d32c

31 files changed

+277
-520
lines changed

iostest/tests/ios_macos.rs

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ use serial_test::serial;
2222
#[test]
2323
#[serial]
2424
fn insert_then_find_generic() {
25-
let service_key = format!("{}", unsafe {
26-
CFString::wrap_under_get_rule(kSecAttrService)
27-
});
25+
let service_key = format!("{}", unsafe { CFString::wrap_under_get_rule(kSecAttrService) });
2826
let mut names = vec![];
2927
for _ in 0..4 {
3028
let name = generate_random_string();
@@ -48,7 +46,7 @@ fn insert_then_find_generic() {
4846
found += 1;
4947
}
5048
}
51-
}
49+
},
5250
_ => panic!("Got a non-dictionary from a password search"),
5351
}
5452
}
@@ -63,16 +61,12 @@ fn insert_then_find_generic() {
6361
#[cfg(target_os = "macos")]
6462
fn insert_then_find_generic_legacy() {
6563
let keychain = SecKeychain::default().unwrap();
66-
let service_key = format!("{}", unsafe {
67-
CFString::wrap_under_get_rule(kSecAttrService)
68-
});
64+
let service_key = format!("{}", unsafe { CFString::wrap_under_get_rule(kSecAttrService) });
6965
// create 4 legacy and 4 modern generic passwords
7066
let mut legacy_names = vec![];
7167
for _ in 0..4 {
7268
let name = generate_random_string();
73-
keychain
74-
.set_generic_password(&name, &name, name.as_bytes())
75-
.unwrap();
69+
keychain.set_generic_password(&name, &name, name.as_bytes()).unwrap();
7670
legacy_names.push(name);
7771
}
7872
let mut modern_names = vec![];
@@ -99,7 +93,7 @@ fn insert_then_find_generic_legacy() {
9993
found += 1;
10094
}
10195
}
102-
}
96+
},
10397
_ => panic!("Got a non-dictionary from a password search"),
10498
}
10599
}
@@ -121,12 +115,8 @@ fn insert_then_find_generic_legacy() {
121115
#[test]
122116
#[serial]
123117
fn find_leftover_test_generic_passwords() {
124-
let service_key = format!("{}", unsafe {
125-
CFString::wrap_under_get_rule(kSecAttrService)
126-
});
127-
let username_key = format!("{}", unsafe {
128-
CFString::wrap_under_get_rule(kSecAttrAccount)
129-
});
118+
let service_key = format!("{}", unsafe { CFString::wrap_under_get_rule(kSecAttrService) });
119+
let username_key = format!("{}", unsafe { CFString::wrap_under_get_rule(kSecAttrAccount) });
130120
let mut found: Vec<String> = vec![];
131121
let results = ItemSearchOptions::new()
132122
.class(ItemClass::generic_password())
@@ -148,7 +138,7 @@ fn find_leftover_test_generic_passwords() {
148138
}
149139
}
150140
}
151-
}
141+
},
152142
_ => panic!("Got a non-dictionary from a password search"),
153143
}
154144
}

security-framework-sys/src/cms.rs

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub enum CMSSignerStatus {
2828
kCMSSignerInvalidIndex = 5,
2929
}
3030

31-
pub type CMSSignedAttributes = u32;
31+
pub type CMSSignedAttributes = u32;
3232
pub const kCMSAttrNone: CMSSignedAttributes = 0x0000;
3333
pub const kCMSAttrSmimeCapabilities: CMSSignedAttributes = 0x0001;
3434
pub const kCMSAttrSmimeEncryptionKeyPrefs: CMSSignedAttributes = 0x0002;
@@ -111,15 +111,9 @@ extern "C" {
111111
content_type_out: *mut CFDataRef,
112112
) -> OSStatus;
113113

114-
pub fn CMSDecoderCopyAllCerts(
115-
decoder: CMSDecoderRef,
116-
certs_out: *mut CFArrayRef,
117-
) -> OSStatus;
114+
pub fn CMSDecoderCopyAllCerts(decoder: CMSDecoderRef, certs_out: *mut CFArrayRef) -> OSStatus;
118115

119-
pub fn CMSDecoderCopyContent(
120-
decoder: CMSDecoderRef,
121-
content_out: *mut CFDataRef,
122-
) -> OSStatus;
116+
pub fn CMSDecoderCopyContent(decoder: CMSDecoderRef, content_out: *mut CFDataRef) -> OSStatus;
123117

124118
pub fn CMSDecoderCopySignerSigningTime(
125119
decoder: CMSDecoderRef,
@@ -146,7 +140,6 @@ extern "C" {
146140
certificate_refs: *mut CFArrayRef,
147141
) -> OSStatus;
148142

149-
150143
// CMS encoder
151144

152145
pub static kCMSEncoderDigestAlgorithmSHA1: CFStringRef;
@@ -161,15 +154,9 @@ extern "C" {
161154
digest_alogrithm: CFStringRef,
162155
) -> OSStatus;
163156

164-
pub fn CMSEncoderAddSigners(
165-
encoder: CMSEncoderRef,
166-
signer_or_array: CFTypeRef,
167-
) -> OSStatus;
157+
pub fn CMSEncoderAddSigners(encoder: CMSEncoderRef, signer_or_array: CFTypeRef) -> OSStatus;
168158

169-
pub fn CMSEncoderCopySigners(
170-
encoder: CMSEncoderRef,
171-
signers_out: *mut CFArrayRef,
172-
) -> OSStatus;
159+
pub fn CMSEncoderCopySigners(encoder: CMSEncoderRef, signers_out: *mut CFArrayRef) -> OSStatus;
173160

174161
pub fn CMSEncoderAddRecipients(
175162
encoder: CMSEncoderRef,

security-framework-sys/src/item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ extern "C" {
1414
pub static kSecMatchTrustedOnly: CFStringRef;
1515
pub static kSecMatchCaseInsensitive: CFStringRef;
1616
#[cfg(target_os = "macos")]
17-
pub static kSecMatchSubjectWholeString: CFStringRef;
17+
pub static kSecMatchSubjectWholeString: CFStringRef;
1818

1919
pub static kSecReturnData: CFStringRef;
2020
pub static kSecReturnAttributes: CFStringRef;

security-framework/examples/client.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,9 @@ use std::net::TcpStream;
44

55
fn main() {
66
let stream = TcpStream::connect("google.com:443").unwrap();
7-
let mut stream = ClientBuilder::new()
8-
.handshake("google.com", stream)
9-
.unwrap();
10-
println!(
11-
"negotiated chipher: {:?}",
12-
stream.context().negotiated_cipher().unwrap()
13-
);
14-
println!(
15-
"negotiated version: {:?}",
16-
stream.context().negotiated_protocol_version().unwrap()
17-
);
7+
let mut stream = ClientBuilder::new().handshake("google.com", stream).unwrap();
8+
println!("negotiated chipher: {:?}", stream.context().negotiated_cipher().unwrap());
9+
println!("negotiated version: {:?}", stream.context().negotiated_protocol_version().unwrap());
1810

1911
stream.write_all(b"GET / HTTP/1.0\r\n\r\n").unwrap();
2012
stream.flush().unwrap();

security-framework/src/access_control.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@
22
33
use std::ptr::{self, null};
44

5+
use crate::base::{Error, Result};
6+
use core_foundation::base::{kCFAllocatorDefault, CFOptionFlags, TCFType};
57
use core_foundation::string::CFString;
6-
use core_foundation::base::{TCFType, CFOptionFlags, kCFAllocatorDefault};
78
use security_framework_sys::access_control::{
8-
SecAccessControlGetTypeID, SecAccessControlCreateWithFlags,
9-
kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly,
10-
kSecAttrAccessibleWhenUnlockedThisDeviceOnly,
11-
kSecAttrAccessibleWhenUnlocked,
12-
kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly,
13-
kSecAttrAccessibleAfterFirstUnlock
9+
kSecAttrAccessibleAfterFirstUnlock, kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly,
10+
kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly, kSecAttrAccessibleWhenUnlocked,
11+
kSecAttrAccessibleWhenUnlockedThisDeviceOnly, SecAccessControlCreateWithFlags,
12+
SecAccessControlGetTypeID,
1413
};
15-
use security_framework_sys::base::{SecAccessControlRef, errSecParam};
16-
use crate::base::{Error, Result};
14+
use security_framework_sys::base::{errSecParam, SecAccessControlRef};
1715

1816
declare_TCFType! {
1917
/// A type representing sec access control settings.

security-framework/src/authorization.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
33
/// # Potential improvements
44
///
5-
/// * When generic specialization stabilizes prevent copying from `CString`
6-
/// arguments.
5+
/// * When generic specialization stabilizes prevent copying from `CString` arguments.
76
/// * `AuthorizationCopyRightsAsync`
87
/// * Provide constants for well known item names
9-
108
use crate::base::{Error, Result};
119
#[cfg(all(target_os = "macos", feature = "job-bless"))]
1210
use core_foundation::base::Boolean;
@@ -22,10 +20,10 @@ use security_framework_sys::authorization as sys;
2220
use security_framework_sys::base::errSecConversionError;
2321
use std::ffi::{CStr, CString};
2422
use std::fs::File;
23+
use std::marker::PhantomData;
2524
use std::mem::MaybeUninit;
2625
use std::os::raw::c_void;
2726
use std::ptr::addr_of;
28-
use std::marker::PhantomData;
2927
use sys::AuthorizationExternalForm;
3028

3129
macro_rules! optional_str_to_cfref {
@@ -86,7 +84,8 @@ impl AuthorizationItem {
8684
///
8785
/// If `name` isn't convertable to a `CString` it will return
8886
/// Err(errSecConversionError).
89-
#[must_use] pub fn name(&self) -> &str {
87+
#[must_use]
88+
pub fn name(&self) -> &str {
9089
unsafe {
9190
CStr::from_ptr(self.0.name)
9291
.to_str()
@@ -97,13 +96,13 @@ impl AuthorizationItem {
9796
/// The information pertaining to the name field. Do not rely on NULL
9897
/// termination of string data.
9998
#[inline]
100-
#[must_use] pub fn value(&self) -> Option<&[u8]> {
99+
#[must_use]
100+
pub fn value(&self) -> Option<&[u8]> {
101101
if self.0.value.is_null() {
102102
return None;
103103
}
104104

105-
let value =
106-
unsafe { std::slice::from_raw_parts(self.0.value as *const u8, self.0.valueLength) };
105+
let value = unsafe { std::slice::from_raw_parts(self.0.value as *const u8, self.0.valueLength) };
107106

108107
Some(value)
109108
}
@@ -441,7 +440,7 @@ impl Authorization {
441440
RightDefinition::FromExistingRight(def) => {
442441
definition_cfstring = CFString::new(def);
443442
definition_cfstring.as_CFTypeRef()
444-
}
443+
},
445444
};
446445

447446
let status = unsafe {
@@ -478,14 +477,13 @@ impl Authorization {
478477
Some(tag) => {
479478
tag_with_nul = cstring_or_err!(tag)?;
480479
tag_with_nul.as_ptr()
481-
}
480+
},
482481
None => std::ptr::null(),
483482
};
484483

485484
let mut inner = MaybeUninit::<*mut sys::AuthorizationItemSet>::uninit();
486485

487-
let status =
488-
unsafe { sys::AuthorizationCopyInfo(self.handle, tag_ptr, inner.as_mut_ptr()) };
486+
let status = unsafe { sys::AuthorizationCopyInfo(self.handle, tag_ptr, inner.as_mut_ptr()) };
489487

490488
if status != sys::errAuthorizationSuccess {
491489
return Err(Error::from(status));
@@ -504,8 +502,7 @@ impl Authorization {
504502
pub fn make_external_form(&self) -> Result<sys::AuthorizationExternalForm> {
505503
let mut external_form = MaybeUninit::<sys::AuthorizationExternalForm>::uninit();
506504

507-
let status =
508-
unsafe { sys::AuthorizationMakeExternalForm(self.handle, external_form.as_mut_ptr()) };
505+
let status = unsafe { sys::AuthorizationMakeExternalForm(self.handle, external_form.as_mut_ptr()) };
509506

510507
if status != sys::errAuthorizationSuccess {
511508
return Err(Error::from(status));

security-framework/src/certificate.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ impl SecCertificate {
5353
pub fn from_der(der_data: &[u8]) -> Result<Self> {
5454
let der_data = CFData::from_buffer(der_data);
5555
unsafe {
56-
let certificate =
57-
SecCertificateCreateWithData(kCFAllocatorDefault, der_data.as_concrete_TypeRef());
56+
let certificate = SecCertificateCreateWithData(kCFAllocatorDefault, der_data.as_concrete_TypeRef());
5857
if certificate.is_null() {
5958
Err(Error::from_code(errSecParam))
6059
} else {
@@ -73,7 +72,7 @@ impl SecCertificate {
7372
}
7473

7574
/// Adds a certificate to a keychain.
76-
#[cfg(target_os="macos")]
75+
#[cfg(target_os = "macos")]
7776
pub fn add_to_keychain(&self, keychain: Option<SecKeychain>) -> Result<()> {
7877
let kch = match keychain {
7978
Some(kch) => kch,
@@ -154,8 +153,7 @@ impl SecCertificate {
154153
#[cfg(any(feature = "OSX_10_12", target_os = "ios", target_os = "tvos", target_os = "watchos", target_os = "visionos"))]
155154
#[must_use]
156155
fn pk_to_der(&self, public_key: key::SecKey) -> Option<Vec<u8>> {
157-
use security_framework_sys::item::kSecAttrKeyType;
158-
use security_framework_sys::item::kSecAttrKeySizeInBits;
156+
use security_framework_sys::item::{kSecAttrKeySizeInBits, kSecAttrKeyType};
159157

160158
let public_key_attributes = public_key.attributes();
161159
let public_key_type = public_key_attributes
@@ -208,23 +206,18 @@ impl SecCertificate {
208206

209207
#[cfg(any(feature = "OSX_10_12", target_os = "ios", target_os = "tvos", target_os = "watchos", target_os = "visionos"))]
210208
fn get_asn1_header_bytes(pkt: CFString, ksz: u32) -> Option<&'static [u8]> {
211-
use security_framework_sys::item::kSecAttrKeyTypeRSA;
212-
use security_framework_sys::item::kSecAttrKeyTypeECSECPrimeRandom;
209+
use security_framework_sys::item::{kSecAttrKeyTypeECSECPrimeRandom, kSecAttrKeyTypeRSA};
213210

214211
if pkt == unsafe { CFString::wrap_under_get_rule(kSecAttrKeyTypeRSA) } && ksz == 2048 {
215212
return Some(&RSA_2048_ASN1_HEADER);
216213
}
217214
if pkt == unsafe { CFString::wrap_under_get_rule(kSecAttrKeyTypeRSA) } && ksz == 4096 {
218215
return Some(&RSA_4096_ASN1_HEADER);
219216
}
220-
if pkt == unsafe { CFString::wrap_under_get_rule(kSecAttrKeyTypeECSECPrimeRandom) }
221-
&& ksz == 256
222-
{
217+
if pkt == unsafe { CFString::wrap_under_get_rule(kSecAttrKeyTypeECSECPrimeRandom) } && ksz == 256 {
223218
return Some(&EC_DSA_SECP_256_R1_ASN1_HEADER);
224219
}
225-
if pkt == unsafe { CFString::wrap_under_get_rule(kSecAttrKeyTypeECSECPrimeRandom) }
226-
&& ksz == 384
227-
{
220+
if pkt == unsafe { CFString::wrap_under_get_rule(kSecAttrKeyTypeECSECPrimeRandom) } && ksz == 384 {
228221
return Some(&EC_DSA_SECP_384_R1_ASN1_HEADER);
229222
}
230223
None

0 commit comments

Comments
 (0)