Skip to content

Commit a240237

Browse files
committed
Don't repeat bad APIs
1 parent 878034e commit a240237

File tree

12 files changed

+33
-3
lines changed

12 files changed

+33
-3
lines changed

security-framework/src/authorization.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ impl Authorization {
359359
///
360360
/// If `name` isn't convertable to a `CString` it will return
361361
/// Err(errSecConversionError).
362+
// TODO: deprecate and remove. CFDictionary should not be exposed in public Rust APIs.
362363
pub fn get_right<T: Into<Vec<u8>>>(name: T) -> Result<CFDictionary<CFString, CFTypeRef>> {
363364
let name = cstring_or_err!(name)?;
364365
let mut dict = MaybeUninit::<CFDictionaryRef>::uninit();

security-framework/src/item.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ impl ItemSearchOptions {
294294
}
295295

296296
/// Populates a `CFDictionary` to be passed to `update_item` or `delete_item`.
297+
// CFDictionary should not be exposed in public Rust APIs.
297298
#[inline]
298299
fn to_dictionary(&self) -> CFDictionary {
299300
unsafe {
@@ -676,6 +677,7 @@ impl ItemAddOptions {
676677
}
677678
/// Populates a `CFDictionary` to be passed to `add_item`.
678679
#[deprecated(since = "3.0.0", note = "use `ItemAddOptions::add` instead")]
680+
// CFDictionary should not be exposed in public Rust APIs.
679681
pub fn to_dictionary(&self) -> CFDictionary {
680682
let mut dict = CFMutableDictionary::from_CFType_pairs(&[]);
681683

@@ -873,6 +875,7 @@ impl ItemUpdateOptions {
873875
self
874876
}
875877
/// Populates a `CFDictionary` to be passed to `update_item`.
878+
// CFDictionary should not be exposed in public Rust APIs.
876879
#[inline]
877880
fn to_dictionary(&self) -> CFDictionary {
878881
let mut dict = CFMutableDictionary::from_CFType_pairs(&[]);

security-framework/src/key.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ impl SecKey {
176176

177177
#[cfg(any(feature = "OSX_10_12", target_os = "ios", target_os = "tvos", target_os = "watchos", target_os = "visionos"))]
178178
/// Translates to `SecKeyCopyAttributes`
179+
// TODO: deprecate and remove. CFDictionary should not be exposed in public Rust APIs.
179180
#[must_use]
180181
pub fn attributes(&self) -> CFDictionary {
181182
let pka = unsafe { SecKeyCopyAttributes(self.to_void() as _) };
@@ -184,6 +185,7 @@ impl SecKey {
184185

185186
#[cfg(any(feature = "OSX_10_12", target_os = "ios", target_os = "tvos", target_os = "watchos", target_os = "visionos"))]
186187
/// Translates to `SecKeyCopyExternalRepresentation`
188+
// TODO: deprecate and remove. CFData should not be exposed in public Rust APIs.
187189
#[must_use]
188190
pub fn external_representation(&self) -> Option<CFData> {
189191
let mut error: CFErrorRef = ::std::ptr::null_mut();
@@ -406,6 +408,7 @@ impl GenerateKeyOptions {
406408
}
407409

408410
/// Collect options into a `CFDictioanry`
411+
// CFDictionary should not be exposed in public Rust APIs.
409412
#[deprecated(note = "Pass the options to SecKey::new")]
410413
pub fn to_dictionary(&self) -> CFDictionary {
411414
#[cfg(target_os = "macos")]

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ impl CertificateOid {
1919
/// Returns the underlying raw pointer corresponding to this OID.
2020
#[inline(always)]
2121
#[must_use]
22+
// FIXME: Don't expose CFStringRef in Rust APIs
2223
pub fn as_ptr(&self) -> CFStringRef {
2324
self.0
2425
}
2526

2627
/// Returns the string representation of the OID.
2728
#[inline]
2829
#[must_use]
30+
// FIXME: Don't expose CFString in Rust APIs
2931
pub fn to_str(&self) -> CFString {
3032
unsafe { CFString::wrap_under_get_rule(self.0) }
3133
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ impl SecCode {
249249

250250
/// Retrieves the location on disk of signed code, given a code or static
251251
/// code object.
252+
// FIXME: Don't expose CFURL in Rust APIs.
252253
pub fn path(&self, flags: Flags) -> Result<CFURL> {
253254
let mut url = MaybeUninit::uninit();
254255

@@ -290,6 +291,7 @@ impl SecStaticCode {
290291

291292
/// Retrieves the location on disk of signed code, given a code or static
292293
/// code object.
294+
// FIXME: Don't expose CFURL in Rust APIs.
293295
pub fn path(&self, flags: Flags) -> Result<CFURL> {
294296
let mut url = MaybeUninit::uninit();
295297

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ impl Builder {
128128
}
129129

130130
/// Computes the digest of the data.
131+
// FIXME: deprecate and remove: don't expose CFData in Rust APIs.
131132
pub fn execute(&self, data: &CFData) -> Result<CFData, CFError> {
132133
unsafe {
133134
let digest_type = match self.digest_type {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ impl Builder {
146146
}
147147

148148
/// Encrypts data with a provided key.
149+
// FIXME: deprecate and remove: don't expose CFData in Rust APIs.
149150
pub fn encrypt(&self, key: &SecKey, data: &CFData) -> Result<CFData, CFError> {
150151
unsafe {
151152
let mut error = ptr::null_mut();
@@ -160,6 +161,7 @@ impl Builder {
160161
}
161162

162163
/// Decrypts data with a provided key.
164+
// FIXME: deprecate and remove: don't expose CFData in Rust APIs.
163165
pub fn decrypt(&self, key: &SecKey, data: &CFData) -> Result<CFData, CFError> {
164166
unsafe {
165167
let mut error = ptr::null_mut();

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub mod secure_transport;
1717
pub mod transform;
1818

1919
#[cfg(test)]
20-
pub mod test {
20+
pub(crate) mod test {
2121
use crate::identity::SecIdentity;
2222
use crate::item::{ItemClass, ItemSearchOptions, Reference, SearchResult};
2323
use crate::os::macos::item::ItemSearchOptionsExt;
@@ -26,7 +26,8 @@ pub mod test {
2626
use std::io::prelude::*;
2727
use std::path::Path;
2828

29-
#[must_use] pub fn identity(dir: &Path) -> SecIdentity {
29+
#[must_use]
30+
pub(crate) fn identity(dir: &Path) -> SecIdentity {
3031
// FIXME https://github.com/rust-lang/rust/issues/30018
3132
let keychain = keychain(dir);
3233
let mut items = p!(ItemSearchOptions::new()
@@ -39,7 +40,8 @@ pub mod test {
3940
}
4041
}
4142

42-
#[must_use] pub fn keychain(dir: &Path) -> SecKeychain {
43+
#[must_use]
44+
pub(crate) fn keychain(dir: &Path) -> SecKeychain {
4345
let path = dir.join("server.keychain");
4446
let mut file = p!(File::create(&path));
4547
p!(file.write_all(include_bytes!("../../../test/server.keychain")));

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ impl SecTransform {
4040
/// Executes the transform.
4141
///
4242
/// The return type depends on the type of transform.
43+
// FIXME: deprecate and remove: don't expose CFType in Rust APIs.
4344
pub fn execute(&mut self) -> Result<CFType, CFError> {
4445
unsafe {
4546
let mut error = ptr::null_mut();

security-framework/src/passwords.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ pub fn set_generic_password_options(
3939
/// keychain entry exists, fails with error code `errSecItemNotFound`.
4040
pub fn get_generic_password(service: &str, account: &str) -> Result<Vec<u8>> {
4141
let mut options = PasswordOptions::new_generic_password(service, account);
42+
#[allow(deprecated)]
4243
options.query.push((
4344
unsafe { CFString::wrap_under_get_rule(kSecReturnData) },
4445
CFBoolean::from(true).into_CFType(),
4546
));
47+
#[allow(deprecated)]
4648
let params = CFDictionary::from_CFType_pairs(&options.query);
4749
let mut ret: CFTypeRef = std::ptr::null();
4850
cvt(unsafe { SecItemCopyMatching(params.as_concrete_TypeRef(), &mut ret) })?;
@@ -53,6 +55,7 @@ pub fn get_generic_password(service: &str, account: &str) -> Result<Vec<u8>> {
5355
/// If none exists, fails with error code `errSecItemNotFound`.
5456
pub fn delete_generic_password(service: &str, account: &str) -> Result<()> {
5557
let options = PasswordOptions::new_generic_password(service, account);
58+
#[allow(deprecated)]
5659
let params = CFDictionary::from_CFType_pairs(&options.query);
5760
cvt(unsafe { SecItemDelete(params.as_concrete_TypeRef()) })
5861
}
@@ -102,10 +105,12 @@ pub fn get_internet_password(
102105
protocol,
103106
authentication_type,
104107
);
108+
#[allow(deprecated)]
105109
options.query.push((
106110
unsafe { CFString::wrap_under_get_rule(kSecReturnData) },
107111
CFBoolean::from(true).into_CFType(),
108112
));
113+
#[allow(deprecated)]
109114
let params = CFDictionary::from_CFType_pairs(&options.query);
110115
let mut ret: CFTypeRef = std::ptr::null();
111116
cvt(unsafe { SecItemCopyMatching(params.as_concrete_TypeRef(), &mut ret) })?;
@@ -132,12 +137,14 @@ pub fn delete_internet_password(
132137
protocol,
133138
authentication_type,
134139
);
140+
#[allow(deprecated)]
135141
let params = CFDictionary::from_CFType_pairs(&options.query);
136142
cvt(unsafe { SecItemDelete(params.as_concrete_TypeRef()) })
137143
}
138144

139145
// This starts by trying to create the password with the given query params.
140146
// If the creation attempt reveals that one exists, its password is updated.
147+
#[allow(deprecated)]
141148
fn set_password_internal(options: &mut PasswordOptions, password: &[u8]) -> Result<()> {
142149
let query_len = options.query.len();
143150
options.query.push((

0 commit comments

Comments
 (0)