Skip to content

Commit

Permalink
Clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Jan 6, 2025
1 parent 30aa35d commit 362832f
Show file tree
Hide file tree
Showing 17 changed files with 80 additions and 83 deletions.
16 changes: 8 additions & 8 deletions iostest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn test_missing_generic_password() {
};
let result = get_generic_password(name, name);
match result {
Ok(bytes) => panic!("test_missing_password: get returned {:?}", bytes),
Ok(bytes) => panic!("test_missing_password: get returned {bytes:?}"),
Err(err) if err.code() == errSecItemNotFound => (),
Err(err) => panic!("test_missing_generic_password: get failed with status: {}", err.code()),
};
Expand All @@ -60,7 +60,7 @@ fn test_missing_generic_password() {
fn test_round_trip_empty_generic_password() {
println!("test_round_trip_empty_generic_password: start");
let name = "test_empty_generic_password_input";
let in_pass = "".as_bytes();
let in_pass = b"";
set_generic_password(name, name, in_pass).unwrap();
let out_pass = get_generic_password(name, name).unwrap();
assert_eq!(in_pass, out_pass);
Expand All @@ -71,7 +71,7 @@ fn test_round_trip_empty_generic_password() {
fn test_round_trip_ascii_generic_password() {
println!("test_round_trip_ascii_generic_password: start");
let name = "test_round_trip_ascii_generic_password";
let password = "test ascii password".as_bytes();
let password = b"test ascii password";
set_generic_password(name, name, password).unwrap();
let stored_password = get_generic_password(name, name).unwrap();
assert_eq!(stored_password, password);
Expand Down Expand Up @@ -104,7 +104,7 @@ fn test_round_trip_non_utf8_generic_password() {
fn test_update_generic_password() {
println!("test_update_generic_password: start");
let name = "test_update_generic_password";
let password = "test ascii password".as_bytes();
let password = b"test ascii password";
set_generic_password(name, name, password).unwrap();
let stored_password = get_generic_password(name, name).unwrap();
assert_eq!(stored_password, password);
Expand All @@ -127,7 +127,7 @@ fn test_missing_internet_password() {
};
let result = get_internet_password(name, None, name, "/test", None, HTTP, Any);
match result {
Ok(bytes) => panic!("test_missing_password: get returned {:?}", bytes),
Ok(bytes) => panic!("test_missing_password: get returned {bytes:?}"),
Err(err) if err.code() == errSecItemNotFound => (),
Err(err) => panic!("test_missing_internet_password: get failed with status: {}", err.code()),
};
Expand All @@ -143,7 +143,7 @@ fn test_missing_internet_password() {
fn test_round_trip_empty_internet_password() {
println!("test_round_trip_empty_internet_password: start");
let name = "test_empty_internet_password_input";
let in_pass = "".as_bytes();
let in_pass = b"";
set_internet_password(name, None, name, "/test", None, HTTP, Any, in_pass).unwrap();
let out_pass = get_internet_password(name, None, name, "/test", None, HTTP, Any).unwrap();
assert_eq!(in_pass, out_pass);
Expand All @@ -154,7 +154,7 @@ fn test_round_trip_empty_internet_password() {
fn test_round_trip_ascii_internet_password() {
println!("test_round_trip_ascii_internet_password: start");
let name = "test_round_trip_ascii_internet_password";
let password = "test ascii password".as_bytes();
let password = b"test ascii password";
set_internet_password(name, None, name, "/test", None, HTTP, Any, password).unwrap();
let stored_password = get_internet_password(name, None, name, "/test", None, HTTP, Any).unwrap();
assert_eq!(stored_password, password);
Expand Down Expand Up @@ -187,7 +187,7 @@ fn test_round_trip_non_utf8_internet_password() {
fn test_update_internet_password() {
println!("test_update_internet_password: start");
let name = "test_update_internet_password";
let password = "test ascii password".as_bytes();
let password = b"test ascii password";
set_internet_password(name, None, name, "/test", None, HTTP, Any, password).unwrap();
let stored_password = get_internet_password(name, None, name, "/test", None, HTTP, Any).unwrap();
assert_eq!(stored_password, password);
Expand Down
18 changes: 9 additions & 9 deletions security-framework/src/authorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ bitflags::bitflags! {

impl Default for Flags {
#[inline(always)]
fn default() -> Flags {
Flags::DEFAULTS
fn default() -> Self {
Self::DEFAULTS
}
}

Expand Down Expand Up @@ -116,11 +116,11 @@ pub struct AuthorizationItemSet<'a> {
phantom: PhantomData<&'a sys::AuthorizationItemSet>,
}

impl<'a> Drop for AuthorizationItemSet<'a> {
impl Drop for AuthorizationItemSet<'_> {
#[inline]
fn drop(&mut self) {
unsafe {
sys::AuthorizationFreeItemSet(self.inner as *mut sys::AuthorizationItemSet);
sys::AuthorizationFreeItemSet(self.inner.cast_mut());
}
}
}
Expand All @@ -146,7 +146,7 @@ pub struct AuthorizationItemSetStorage {
impl Default for AuthorizationItemSetStorage {
#[inline]
fn default() -> Self {
AuthorizationItemSetStorage {
Self {
names: Vec::new(),
values: Vec::new(),
items: Vec::new(),
Expand All @@ -171,7 +171,7 @@ impl AuthorizationItemSetBuilder {
/// owned vectors of `AuthorizationItem`s.
#[inline(always)]
#[must_use]
pub fn new() -> AuthorizationItemSetBuilder {
pub fn new() -> Self {
Default::default()
}

Expand Down Expand Up @@ -237,7 +237,7 @@ impl AuthorizationItemSetBuilder {

self.storage.set = sys::AuthorizationItemSet {
count: self.storage.items.len() as u32,
items: self.storage.items.as_ptr() as *mut sys::AuthorizationItem,
items: self.storage.items.as_ptr().cast_mut(),
};

self.storage
Expand Down Expand Up @@ -278,7 +278,7 @@ impl TryFrom<AuthorizationExternalForm> for Authorization {
return Err(Error::from_code(status));
}

let auth = Authorization {
let auth = Self {
handle: unsafe { handle.assume_init() },
free_flags: Flags::default(),
};
Expand Down Expand Up @@ -331,7 +331,7 @@ impl Authorization {
return Err(Error::from_code(status));
}

Ok(Authorization {
Ok(Self {
handle: unsafe { handle.assume_init() },
free_flags: Default::default(),
})
Expand Down
2 changes: 1 addition & 1 deletion security-framework/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Error {
/// Returns the code of the current error.
#[inline(always)]
#[must_use]
pub fn code(self) -> OSStatus {
pub const fn code(self) -> OSStatus {
self.0.get() as _
}
}
Expand Down
6 changes: 2 additions & 4 deletions security-framework/src/certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ use core_foundation::error::{CFError, CFErrorRef};
#[cfg(any(feature = "OSX_10_12", target_os = "ios", target_os = "tvos", target_os = "watchos", target_os = "visionos"))]
use core_foundation::number::CFNumber;
use security_framework_sys::item::kSecValueRef;
#[cfg(any(feature = "OSX_10_12", target_os = "ios", target_os = "tvos", target_os = "watchos", target_os = "visionos"))]
use std::ops::Deref;

declare_TCFType! {
/// A type representing a certificate.
Expand Down Expand Up @@ -160,10 +158,10 @@ impl SecCertificate {
.find(unsafe { kSecAttrKeyType }.cast::<std::os::raw::c_void>())?;
let public_keysize = public_key_attributes
.find(unsafe { kSecAttrKeySizeInBits }.cast::<std::os::raw::c_void>())?;
let public_keysize = unsafe { CFNumber::from_void(*public_keysize.deref()) };
let public_keysize = unsafe { CFNumber::from_void(*public_keysize) };
let public_keysize_val = public_keysize.to_i64()? as u32;
let hdr_bytes = get_asn1_header_bytes(
unsafe { CFString::wrap_under_get_rule(*public_key_type.deref() as _) },
unsafe { CFString::wrap_under_get_rule(*public_key_type as _) },
public_keysize_val,
)?;
let public_key_data = public_key.external_representation()?;
Expand Down
4 changes: 2 additions & 2 deletions security-framework/src/cipher_suite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ macro_rules! make_suites {

#[inline(always)]
#[must_use]
pub fn from_raw(raw: SSLCipherSuite) -> Self {
pub const fn from_raw(raw: SSLCipherSuite) -> Self {
Self(raw)
}

#[inline(always)]
#[must_use]
pub fn to_raw(&self) -> SSLCipherSuite {
pub const fn to_raw(&self) -> SSLCipherSuite {
self.0
}
}
Expand Down
6 changes: 3 additions & 3 deletions security-framework/src/cms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ mod encoder {

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

Expand Down Expand Up @@ -273,7 +273,7 @@ mod encoder {
content_type_oid.as_ref().map(|oid| oid.as_CFTypeRef()).unwrap_or(ptr::null()),
detached_content.into(),
signed_attributes.bits(),
content.as_ptr() as _,
content.as_ptr().cast(),
content.len(),
&mut out,
)
Expand Down Expand Up @@ -322,7 +322,7 @@ mod decoder {

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

Expand Down
17 changes: 9 additions & 8 deletions security-framework/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ unsafe fn get_item(item: CFTypeRef) -> SearchResult {
}

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

fn ref_(&self) -> CFTypeRef {
match self {
AddRef::Key(key) => key.as_CFTypeRef(),
AddRef::Identity(id) => id.as_CFTypeRef(),
AddRef::Certificate(cert) => cert.as_CFTypeRef(),
Self::Key(key) => key.as_CFTypeRef(),
Self::Identity(id) => id.as_CFTypeRef(),
Self::Certificate(cert) => cert.as_CFTypeRef(),
}
}
}
Expand Down Expand Up @@ -954,13 +955,13 @@ pub enum ItemUpdateValue {
///
/// <https://developer.apple.com/documentation/technotes/tn3137-on-mac-keychains>
pub enum Location {
/// Store the item in the newer DataProtectionKeychain. This is the only
/// Store the item in the newer `DataProtectionKeychain`. This is the only
/// keychain on iOS. On macOS, this is the newer and more consistent
/// keychain implementation. Keys stored in the Secure Enclave _must_ use
/// this keychain.
///
/// This keychain requires the calling binary to be codesigned with
/// entitlements for the KeychainAccessGroups it is supposed to
/// entitlements for the `KeychainAccessGroups` it is supposed to
/// access.
#[cfg(any(feature = "OSX_10_15", target_os = "ios", target_os = "tvos", target_os = "watchos", target_os = "visionos"))]
DataProtectionKeychain,
Expand Down
33 changes: 17 additions & 16 deletions security-framework/src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,15 @@ impl SecKey {
if !error.is_null() {
Err(unsafe { CFError::wrap_under_create_rule(error) })
} else {
Ok(unsafe { SecKey::wrap_under_create_rule(sec_key) })
Ok(unsafe { Self::wrap_under_create_rule(sec_key) })
}
}

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

Some(unsafe { SecKey::wrap_under_create_rule(pub_seckey) })
Some(unsafe { Self::wrap_under_create_rule(pub_seckey) })
}

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

if !error.is_null() {
Err(unsafe { CFError::wrap_under_create_rule(error) })
} else {
if error.is_null() {
let output = unsafe { CFData::wrap_under_create_rule(output) };
Ok(output.to_vec())
} else {
Err(unsafe { CFError::wrap_under_create_rule(error) })
}
}

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

if !error.is_null() {
Err(unsafe { CFError::wrap_under_create_rule(error) })
} else {
if error.is_null() {
let output = unsafe { CFData::wrap_under_create_rule(output) };
Ok(output.to_vec())
} else {
Err(unsafe { CFError::wrap_under_create_rule(error) })
}
}

Expand All @@ -256,11 +257,11 @@ impl SecKey {
)
};

if !error.is_null() {
Err(unsafe { CFError::wrap_under_create_rule(error) })
} else {
if error.is_null() {
let output = unsafe { CFData::wrap_under_create_rule(output) };
Ok(output.to_vec())
} else {
Err(unsafe { CFError::wrap_under_create_rule(error) })
}
}

Expand Down Expand Up @@ -292,7 +293,7 @@ impl SecKey {
pub fn key_exchange(
&self,
algorithm: Algorithm,
public_key: &SecKey,
public_key: &Self,
requested_size: usize,
shared_info: Option<&[u8]>,
) -> Result<Vec<u8>, CFError> {
Expand All @@ -311,7 +312,7 @@ impl SecKey {
params.push((
CFString::wrap_under_get_rule(kSecKeyKeyExchangeParameterSharedInfo),
CFData::from_buffer(shared_info).as_CFType(),
))
));
};

let parameters = CFDictionary::from_CFType_pairs(&params);
Expand All @@ -326,11 +327,11 @@ impl SecKey {
&mut error,
);

if !error.is_null() {
Err(CFError::wrap_under_create_rule(error))
} else {
if error.is_null() {
let output = CFData::wrap_under_create_rule(output);
Ok(output.to_vec())
} else {
Err(CFError::wrap_under_create_rule(error))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion security-framework/src/os/macos/certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl<'a> IntoIterator for &'a PropertySection {
/// An iterator over the properties in a section.
pub struct PropertySectionIter<'a>(CFArrayIterator<'a, CFDictionary>);

impl<'a> Iterator for PropertySectionIter<'a> {
impl Iterator for PropertySectionIter<'_> {
type Item = CertificateProperty;

#[inline]
Expand Down
Loading

0 comments on commit 362832f

Please sign in to comment.