feat: add security-framework

This commit is contained in:
2022-10-16 19:45:34 +08:00
parent e972998e09
commit 9ab7685f2d
3 changed files with 132 additions and 0 deletions

99
__security/security-framework/Cargo.lock generated Normal file
View File

@@ -0,0 +1,99 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "autocfg"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "core-foundation"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146"
dependencies = [
"core-foundation-sys",
"libc",
]
[[package]]
name = "core-foundation-sys"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc"
[[package]]
name = "libc"
version = "0.2.135"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68783febc7782c6c5cb401fbda4de5a9898be1762314da0bb2c10ced61f18b0c"
[[package]]
name = "num-bigint"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f"
dependencies = [
"autocfg",
"num-integer",
"num-traits",
]
[[package]]
name = "num-integer"
version = "0.1.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"
dependencies = [
"autocfg",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
dependencies = [
"autocfg",
]
[[package]]
name = "security-framework"
version = "0.1.0"
dependencies = [
"core-foundation",
"security-framework 2.7.0",
]
[[package]]
name = "security-framework"
version = "2.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bc1bb97804af6631813c55739f771071e0f2ed33ee20b68c86ec505d906356c"
dependencies = [
"bitflags",
"core-foundation",
"core-foundation-sys",
"libc",
"num-bigint",
"security-framework-sys",
]
[[package]]
name = "security-framework-sys"
version = "2.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556"
dependencies = [
"core-foundation-sys",
"libc",
]

View File

@@ -0,0 +1,11 @@
[package]
name = "security-framework"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
core-foundation = "0.9.3"
security-framework = { version = "2.7.0", features = ["OSX_10_14"] }

View File

@@ -0,0 +1,22 @@
use std::io::Read;
use std::sync::Arc;
use core_foundation::data::CFData;
use security_framework::key::SecKey;
use security_framework::os::macos::item::KeyType;
use security_framework::os::macos::keychain::SecKeychain;
fn main() {
let mut sec_keychain = SecKeychain::default().unwrap();
// let sec = sec_keychain.set_generic_password("Test", "test", "helloworld".as_bytes());
// println!("{:?}",sec);
let acc = sec_keychain.find_generic_password("Test", "test");
println!("{:?}", acc);
println!("{:?}", acc.as_ref().unwrap().0);
println!("{:?}", acc.as_ref().unwrap().0.bytes());
// let l = vec![5];
// let cf_data = CFData::from_arc(Arc::new(l));
// let a = security_framework::os::macos::key::SecKeyExt::from_data(
// KeyType::rsa(), &cf_data);
// println!("{:?}", a);
}