Skip to content

Commit 362832f

Browse files
committed
Clippy
1 parent 30aa35d commit 362832f

File tree

17 files changed

+80
-83
lines changed

17 files changed

+80
-83
lines changed

iostest/src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn test_missing_generic_password() {
4444
};
4545
let result = get_generic_password(name, name);
4646
match result {
47-
Ok(bytes) => panic!("test_missing_password: get returned {:?}", bytes),
47+
Ok(bytes) => panic!("test_missing_password: get returned {bytes:?}"),
4848
Err(err) if err.code() == errSecItemNotFound => (),
4949
Err(err) => panic!("test_missing_generic_password: get failed with status: {}", err.code()),
5050
};
@@ -60,7 +60,7 @@ fn test_missing_generic_password() {
6060
fn test_round_trip_empty_generic_password() {
6161
println!("test_round_trip_empty_generic_password: start");
6262
let name = "test_empty_generic_password_input";
63-
let in_pass = "".as_bytes();
63+
let in_pass = b"";
6464
set_generic_password(name, name, in_pass).unwrap();
6565
let out_pass = get_generic_password(name, name).unwrap();
6666
assert_eq!(in_pass, out_pass);
@@ -71,7 +71,7 @@ fn test_round_trip_empty_generic_password() {
7171
fn test_round_trip_ascii_generic_password() {
7272
println!("test_round_trip_ascii_generic_password: start");
7373
let name = "test_round_trip_ascii_generic_password";
74-
let password = "test ascii password".as_bytes();
74+
let password = b"test ascii password";
7575
set_generic_password(name, name, password).unwrap();
7676
let stored_password = get_generic_password(name, name).unwrap();
7777
assert_eq!(stored_password, password);
@@ -104,7 +104,7 @@ fn test_round_trip_non_utf8_generic_password() {
104104
fn test_update_generic_password() {
105105
println!("test_update_generic_password: start");
106106
let name = "test_update_generic_password";
107-
let password = "test ascii password".as_bytes();
107+
let password = b"test ascii password";
108108
set_generic_password(name, name, password).unwrap();
109109
let stored_password = get_generic_password(name, name).unwrap();
110110
assert_eq!(stored_password, password);
@@ -127,7 +127,7 @@ fn test_missing_internet_password() {
127127
};
128128
let result = get_internet_password(name, None, name, "/test", None, HTTP, Any);
129129
match result {
130-
Ok(bytes) => panic!("test_missing_password: get returned {:?}", bytes),
130+
Ok(bytes) => panic!("test_missing_password: get returned {bytes:?}"),
131131
Err(err) if err.code() == errSecItemNotFound => (),
132132
Err(err) => panic!("test_missing_internet_password: get failed with status: {}", err.code()),
133133
};
@@ -143,7 +143,7 @@ fn test_missing_internet_password() {
143143
fn test_round_trip_empty_internet_password() {
144144
println!("test_round_trip_empty_internet_password: start");
145145
let name = "test_empty_internet_password_input";
146-
let in_pass = "".as_bytes();
146+
let in_pass = b"";
147147
set_internet_password(name, None, name, "/test", None, HTTP, Any, in_pass).unwrap();
148148
let out_pass = get_internet_password(name, None, name, "/test", None, HTTP, Any).unwrap();
149149
assert_eq!(in_pass, out_pass);
@@ -154,7 +154,7 @@ fn test_round_trip_empty_internet_password() {
154154
fn test_round_trip_ascii_internet_password() {
155155
println!("test_round_trip_ascii_internet_password: start");
156156
let name = "test_round_trip_ascii_internet_password";
157-
let password = "test ascii password".as_bytes();
157+
let password = b"test ascii password";
158158
set_internet_password(name, None, name, "/test", None, HTTP, Any, password).unwrap();
159159
let stored_password = get_internet_password(name, None, name, "/test", None, HTTP, Any).unwrap();
160160
assert_eq!(stored_password, password);
@@ -187,7 +187,7 @@ fn test_round_trip_non_utf8_internet_password() {
187187
fn test_update_internet_password() {
188188
println!("test_update_internet_password: start");
189189
let name = "test_update_internet_password";
190-
let password = "test ascii password".as_bytes();
190+
let password = b"test ascii password";
191191
set_internet_password(name, None, name, "/test", None, HTTP, Any, password).unwrap();
192192
let stored_password = get_internet_password(name, None, name, "/test", None, HTTP, Any).unwrap();
193193
assert_eq!(stored_password, password);

security-framework/src/authorization.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ bitflags::bitflags! {
7070

7171
impl Default for Flags {
7272
#[inline(always)]
73-
fn default() -> Flags {
74-
Flags::DEFAULTS
73+
fn default() -> Self {
74+
Self::DEFAULTS
7575
}
7676
}
7777

@@ -116,11 +116,11 @@ pub struct AuthorizationItemSet<'a> {
116116
phantom: PhantomData<&'a sys::AuthorizationItemSet>,
117117
}
118118

119-
impl<'a> Drop for AuthorizationItemSet<'a> {
119+
impl Drop for AuthorizationItemSet<'_> {
120120
#[inline]
121121
fn drop(&mut self) {
122122
unsafe {
123-
sys::AuthorizationFreeItemSet(self.inner as *mut sys::AuthorizationItemSet);
123+
sys::AuthorizationFreeItemSet(self.inner.cast_mut());
124124
}
125125
}
126126
}
@@ -146,7 +146,7 @@ pub struct AuthorizationItemSetStorage {
146146
impl Default for AuthorizationItemSetStorage {
147147
#[inline]
148148
fn default() -> Self {
149-
AuthorizationItemSetStorage {
149+
Self {
150150
names: Vec::new(),
151151
values: Vec::new(),
152152
items: Vec::new(),
@@ -171,7 +171,7 @@ impl AuthorizationItemSetBuilder {
171171
/// owned vectors of `AuthorizationItem`s.
172172
#[inline(always)]
173173
#[must_use]
174-
pub fn new() -> AuthorizationItemSetBuilder {
174+
pub fn new() -> Self {
175175
Default::default()
176176
}
177177

@@ -237,7 +237,7 @@ impl AuthorizationItemSetBuilder {
237237

238238
self.storage.set = sys::AuthorizationItemSet {
239239
count: self.storage.items.len() as u32,
240-
items: self.storage.items.as_ptr() as *mut sys::AuthorizationItem,
240+
items: self.storage.items.as_ptr().cast_mut(),
241241
};
242242

243243
self.storage
@@ -278,7 +278,7 @@ impl TryFrom<AuthorizationExternalForm> for Authorization {
278278
return Err(Error::from_code(status));
279279
}
280280

281-
let auth = Authorization {
281+
let auth = Self {
282282
handle: unsafe { handle.assume_init() },
283283
free_flags: Flags::default(),
284284
};
@@ -331,7 +331,7 @@ impl Authorization {
331331
return Err(Error::from_code(status));
332332
}
333333

334-
Ok(Authorization {
334+
Ok(Self {
335335
handle: unsafe { handle.assume_init() },
336336
free_flags: Default::default(),
337337
})

security-framework/src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl Error {
6161
/// Returns the code of the current error.
6262
#[inline(always)]
6363
#[must_use]
64-
pub fn code(self) -> OSStatus {
64+
pub const fn code(self) -> OSStatus {
6565
self.0.get() as _
6666
}
6767
}

security-framework/src/certificate.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ use core_foundation::error::{CFError, CFErrorRef};
2727
#[cfg(any(feature = "OSX_10_12", target_os = "ios", target_os = "tvos", target_os = "watchos", target_os = "visionos"))]
2828
use core_foundation::number::CFNumber;
2929
use security_framework_sys::item::kSecValueRef;
30-
#[cfg(any(feature = "OSX_10_12", target_os = "ios", target_os = "tvos", target_os = "watchos", target_os = "visionos"))]
31-
use std::ops::Deref;
3230

3331
declare_TCFType! {
3432
/// A type representing a certificate.
@@ -160,10 +158,10 @@ impl SecCertificate {
160158
.find(unsafe { kSecAttrKeyType }.cast::<std::os::raw::c_void>())?;
161159
let public_keysize = public_key_attributes
162160
.find(unsafe { kSecAttrKeySizeInBits }.cast::<std::os::raw::c_void>())?;
163-
let public_keysize = unsafe { CFNumber::from_void(*public_keysize.deref()) };
161+
let public_keysize = unsafe { CFNumber::from_void(*public_keysize) };
164162
let public_keysize_val = public_keysize.to_i64()? as u32;
165163
let hdr_bytes = get_asn1_header_bytes(
166-
unsafe { CFString::wrap_under_get_rule(*public_key_type.deref() as _) },
164+
unsafe { CFString::wrap_under_get_rule(*public_key_type as _) },
167165
public_keysize_val,
168166
)?;
169167
let public_key_data = public_key.external_representation()?;

security-framework/src/cipher_suite.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ macro_rules! make_suites {
1616

1717
#[inline(always)]
1818
#[must_use]
19-
pub fn from_raw(raw: SSLCipherSuite) -> Self {
19+
pub const fn from_raw(raw: SSLCipherSuite) -> Self {
2020
Self(raw)
2121
}
2222

2323
#[inline(always)]
2424
#[must_use]
25-
pub fn to_raw(&self) -> SSLCipherSuite {
25+
pub const fn to_raw(&self) -> SSLCipherSuite {
2626
self.0
2727
}
2828
}

security-framework/src/cms.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ mod encoder {
215215

216216
/// Feeds content bytes into the encoder
217217
pub fn update_content(&self, content: &[u8]) -> Result<()> {
218-
cvt(unsafe { CMSEncoderUpdateContent(self.0, content.as_ptr() as _, content.len()) })?;
218+
cvt(unsafe { CMSEncoderUpdateContent(self.0, content.as_ptr().cast(), content.len()) })?;
219219
Ok(())
220220
}
221221

@@ -273,7 +273,7 @@ mod encoder {
273273
content_type_oid.as_ref().map(|oid| oid.as_CFTypeRef()).unwrap_or(ptr::null()),
274274
detached_content.into(),
275275
signed_attributes.bits(),
276-
content.as_ptr() as _,
276+
content.as_ptr().cast(),
277277
content.len(),
278278
&mut out,
279279
)
@@ -322,7 +322,7 @@ mod decoder {
322322

323323
/// Feeds raw bytes of the message to be decoded into the decoder
324324
pub fn update_message(&self, message: &[u8]) -> Result<()> {
325-
cvt(unsafe { CMSDecoderUpdateMessage(self.0, message.as_ptr() as _, message.len()) })?;
325+
cvt(unsafe { CMSDecoderUpdateMessage(self.0, message.as_ptr().cast(), message.len()) })?;
326326
Ok(())
327327
}
328328

security-framework/src/item.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ unsafe fn get_item(item: CFTypeRef) -> SearchResult {
480480
}
481481

482482
/// An enum including all objects whose references can be returned from a search.
483+
///
483484
/// Note that generic _Keychain Items_, such as passwords and preferences, do
484485
/// not have specific object types; they are modeled using dictionaries and so
485486
/// are available directly as search results in variant `SearchResult::Dict`.
@@ -758,19 +759,19 @@ pub enum AddRef {
758759
impl AddRef {
759760
fn class(&self) -> Option<ItemClass> {
760761
match self {
761-
AddRef::Key(_) => Some(ItemClass::key()),
762+
Self::Key(_) => Some(ItemClass::key()),
762763
// kSecClass should not be specified when adding a SecIdentityRef:
763764
// https://developer.apple.com/forums/thread/25751
764-
AddRef::Identity(_) => None,
765-
AddRef::Certificate(_) => Some(ItemClass::certificate()),
765+
Self::Identity(_) => None,
766+
Self::Certificate(_) => Some(ItemClass::certificate()),
766767
}
767768
}
768769

769770
fn ref_(&self) -> CFTypeRef {
770771
match self {
771-
AddRef::Key(key) => key.as_CFTypeRef(),
772-
AddRef::Identity(id) => id.as_CFTypeRef(),
773-
AddRef::Certificate(cert) => cert.as_CFTypeRef(),
772+
Self::Key(key) => key.as_CFTypeRef(),
773+
Self::Identity(id) => id.as_CFTypeRef(),
774+
Self::Certificate(cert) => cert.as_CFTypeRef(),
774775
}
775776
}
776777
}
@@ -954,13 +955,13 @@ pub enum ItemUpdateValue {
954955
///
955956
/// <https://developer.apple.com/documentation/technotes/tn3137-on-mac-keychains>
956957
pub enum Location {
957-
/// Store the item in the newer DataProtectionKeychain. This is the only
958+
/// Store the item in the newer `DataProtectionKeychain`. This is the only
958959
/// keychain on iOS. On macOS, this is the newer and more consistent
959960
/// keychain implementation. Keys stored in the Secure Enclave _must_ use
960961
/// this keychain.
961962
///
962963
/// This keychain requires the calling binary to be codesigned with
963-
/// entitlements for the KeychainAccessGroups it is supposed to
964+
/// entitlements for the `KeychainAccessGroups` it is supposed to
964965
/// access.
965966
#[cfg(any(feature = "OSX_10_15", target_os = "ios", target_os = "tvos", target_os = "watchos", target_os = "visionos"))]
966967
DataProtectionKeychain,

security-framework/src/key.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,15 @@ impl SecKey {
159159
if !error.is_null() {
160160
Err(unsafe { CFError::wrap_under_create_rule(error) })
161161
} else {
162-
Ok(unsafe { SecKey::wrap_under_create_rule(sec_key) })
162+
Ok(unsafe { Self::wrap_under_create_rule(sec_key) })
163163
}
164164
}
165165

166166
/// Returns the programmatic identifier for the key. For keys of class
167167
/// kSecAttrKeyClassPublic and kSecAttrKeyClassPrivate, the value is the
168168
/// hash of the public key.
169169
#[cfg(any(feature = "OSX_10_12", target_os = "ios", target_os = "tvos", target_os = "watchos", target_os = "visionos"))]
170+
#[must_use]
170171
pub fn application_label(&self) -> Option<Vec<u8>> {
171172
self.attributes()
172173
.find(unsafe { kSecAttrApplicationLabel.to_void() })
@@ -204,7 +205,7 @@ impl SecKey {
204205
return None;
205206
}
206207

207-
Some(unsafe { SecKey::wrap_under_create_rule(pub_seckey) })
208+
Some(unsafe { Self::wrap_under_create_rule(pub_seckey) })
208209
}
209210

210211
#[cfg(any(feature = "OSX_10_12", target_os = "ios", target_os = "tvos", target_os = "watchos", target_os = "visionos"))]
@@ -216,11 +217,11 @@ impl SecKey {
216217
SecKeyCreateEncryptedData(self.as_concrete_TypeRef(), algorithm.into(), CFData::from_buffer(input).as_concrete_TypeRef(), &mut error)
217218
};
218219

219-
if !error.is_null() {
220-
Err(unsafe { CFError::wrap_under_create_rule(error) })
221-
} else {
220+
if error.is_null() {
222221
let output = unsafe { CFData::wrap_under_create_rule(output) };
223222
Ok(output.to_vec())
223+
} else {
224+
Err(unsafe { CFError::wrap_under_create_rule(error) })
224225
}
225226
}
226227

@@ -233,11 +234,11 @@ impl SecKey {
233234
SecKeyCreateDecryptedData(self.as_concrete_TypeRef(), algorithm.into(), CFData::from_buffer(input).as_concrete_TypeRef(), &mut error)
234235
};
235236

236-
if !error.is_null() {
237-
Err(unsafe { CFError::wrap_under_create_rule(error) })
238-
} else {
237+
if error.is_null() {
239238
let output = unsafe { CFData::wrap_under_create_rule(output) };
240239
Ok(output.to_vec())
240+
} else {
241+
Err(unsafe { CFError::wrap_under_create_rule(error) })
241242
}
242243
}
243244

@@ -256,11 +257,11 @@ impl SecKey {
256257
)
257258
};
258259

259-
if !error.is_null() {
260-
Err(unsafe { CFError::wrap_under_create_rule(error) })
261-
} else {
260+
if error.is_null() {
262261
let output = unsafe { CFData::wrap_under_create_rule(output) };
263262
Ok(output.to_vec())
263+
} else {
264+
Err(unsafe { CFError::wrap_under_create_rule(error) })
264265
}
265266
}
266267

@@ -292,7 +293,7 @@ impl SecKey {
292293
pub fn key_exchange(
293294
&self,
294295
algorithm: Algorithm,
295-
public_key: &SecKey,
296+
public_key: &Self,
296297
requested_size: usize,
297298
shared_info: Option<&[u8]>,
298299
) -> Result<Vec<u8>, CFError> {
@@ -311,7 +312,7 @@ impl SecKey {
311312
params.push((
312313
CFString::wrap_under_get_rule(kSecKeyKeyExchangeParameterSharedInfo),
313314
CFData::from_buffer(shared_info).as_CFType(),
314-
))
315+
));
315316
};
316317

317318
let parameters = CFDictionary::from_CFType_pairs(&params);
@@ -326,11 +327,11 @@ impl SecKey {
326327
&mut error,
327328
);
328329

329-
if !error.is_null() {
330-
Err(CFError::wrap_under_create_rule(error))
331-
} else {
330+
if error.is_null() {
332331
let output = CFData::wrap_under_create_rule(output);
333332
Ok(output.to_vec())
333+
} else {
334+
Err(CFError::wrap_under_create_rule(error))
334335
}
335336
}
336337
}

security-framework/src/os/macos/certificate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl<'a> IntoIterator for &'a PropertySection {
173173
/// An iterator over the properties in a section.
174174
pub struct PropertySectionIter<'a>(CFArrayIterator<'a, CFDictionary>);
175175

176-
impl<'a> Iterator for PropertySectionIter<'a> {
176+
impl Iterator for PropertySectionIter<'_> {
177177
type Item = CertificateProperty;
178178

179179
#[inline]

0 commit comments

Comments
 (0)