pub struct LAPersistedRight { /* private fields */ }Expand description
Managed wrapper around Apple’s LAPersistedRight.
Implementations§
Source§impl LAPersistedRight
impl LAPersistedRight
Sourcepub fn state(&self) -> Result<LARightState>
pub fn state(&self) -> Result<LARightState>
Examples found in repository?
12fn main() -> Result<(), Box<dyn std::error::Error>> {
13 let store = LARightStore::shared()?;
14 let right = LARight::new()?;
15 let identifier = unique_identifier("store");
16
17 match store.save_right(&right, &identifier) {
18 Ok(persisted) => {
19 println!("saved state: {:?}", persisted.state()?);
20 store.remove_right(&persisted)?;
21 }
22 Err(error) => {
23 println!("save_right expectedly failed in unsigned/headless environments: {error}");
24 }
25 }
26
27 println!("✅ right-store smoke OK");
28 Ok(())
29}More examples
12fn main() -> Result<(), Box<dyn std::error::Error>> {
13 let store = LARightStore::shared()?;
14 let right = LARight::new()?;
15 let identifier = unique_identifier("persisted");
16
17 match store.save_right_with_secret(&right, &identifier, b"top-secret") {
18 Ok(persisted) => {
19 persisted.set_tag(7)?;
20 println!("persisted state: {:?}", persisted.state()?);
21 println!("persisted tag: {}", persisted.tag()?);
22 println!("persisted preflight: {:?}", persisted.check_can_authorize());
23 println!("secret bytes: {}", persisted.secret()?.load_data()?.len());
24 store.remove_right(&persisted)?;
25 }
26 Err(error) => {
27 println!("persisted-right APIs need entitlements on many systems: {error}");
28 }
29 }
30
31 println!("✅ persisted-right smoke OK");
32 Ok(())
33}Sourcepub fn tag(&self) -> Result<i64>
pub fn tag(&self) -> Result<i64>
Application-controlled integer tag.
§Errors
Returns an error if the Swift bridge rejects the request.
Examples found in repository?
12fn main() -> Result<(), Box<dyn std::error::Error>> {
13 let store = LARightStore::shared()?;
14 let right = LARight::new()?;
15 let identifier = unique_identifier("persisted");
16
17 match store.save_right_with_secret(&right, &identifier, b"top-secret") {
18 Ok(persisted) => {
19 persisted.set_tag(7)?;
20 println!("persisted state: {:?}", persisted.state()?);
21 println!("persisted tag: {}", persisted.tag()?);
22 println!("persisted preflight: {:?}", persisted.check_can_authorize());
23 println!("secret bytes: {}", persisted.secret()?.load_data()?.len());
24 store.remove_right(&persisted)?;
25 }
26 Err(error) => {
27 println!("persisted-right APIs need entitlements on many systems: {error}");
28 }
29 }
30
31 println!("✅ persisted-right smoke OK");
32 Ok(())
33}Sourcepub fn set_tag(&self, tag: i64) -> Result<()>
pub fn set_tag(&self, tag: i64) -> Result<()>
Update the application-controlled integer tag.
§Errors
Returns an error if the Swift bridge rejects the request.
Examples found in repository?
12fn main() -> Result<(), Box<dyn std::error::Error>> {
13 let store = LARightStore::shared()?;
14 let right = LARight::new()?;
15 let identifier = unique_identifier("persisted");
16
17 match store.save_right_with_secret(&right, &identifier, b"top-secret") {
18 Ok(persisted) => {
19 persisted.set_tag(7)?;
20 println!("persisted state: {:?}", persisted.state()?);
21 println!("persisted tag: {}", persisted.tag()?);
22 println!("persisted preflight: {:?}", persisted.check_can_authorize());
23 println!("secret bytes: {}", persisted.secret()?.load_data()?.len());
24 store.remove_right(&persisted)?;
25 }
26 Err(error) => {
27 println!("persisted-right APIs need entitlements on many systems: {error}");
28 }
29 }
30
31 println!("✅ persisted-right smoke OK");
32 Ok(())
33}Attempt to authorize the persisted right.
§Errors
Returns a mapped framework or bridge error when authorization fails.
Preflight whether the persisted right can eventually be authorized.
§Errors
Returns a mapped framework or bridge error when authorization is not possible.
Examples found in repository?
12fn main() -> Result<(), Box<dyn std::error::Error>> {
13 let store = LARightStore::shared()?;
14 let right = LARight::new()?;
15 let identifier = unique_identifier("persisted");
16
17 match store.save_right_with_secret(&right, &identifier, b"top-secret") {
18 Ok(persisted) => {
19 persisted.set_tag(7)?;
20 println!("persisted state: {:?}", persisted.state()?);
21 println!("persisted tag: {}", persisted.tag()?);
22 println!("persisted preflight: {:?}", persisted.check_can_authorize());
23 println!("secret bytes: {}", persisted.secret()?.load_data()?.len());
24 store.remove_right(&persisted)?;
25 }
26 Err(error) => {
27 println!("persisted-right APIs need entitlements on many systems: {error}");
28 }
29 }
30
31 println!("✅ persisted-right smoke OK");
32 Ok(())
33}Sourcepub fn key(&self) -> Result<LAPrivateKey>
pub fn key(&self) -> Result<LAPrivateKey>
Borrow the managed private key associated with this persisted right.
§Errors
Returns an error if the Swift bridge rejects the request.
Examples found in repository?
12fn main() -> Result<(), Box<dyn std::error::Error>> {
13 let store = LARightStore::shared()?;
14 let right = LARight::new()?;
15 let identifier = unique_identifier("public-key");
16
17 match store.save_right(&right, &identifier) {
18 Ok(persisted) => {
19 let public_key = persisted.public_key()?;
20 let sign = SecKeyAlgorithm::ecdsa_signature_message_x962_sha256();
21 let encrypt =
22 SecKeyAlgorithm::ecies_encryption_cofactor_variable_iv_x963_sha256_aes_gcm();
23
24 println!("public key bytes: {}", public_key.export_bytes()?.len());
25 println!("can verify: {}", public_key.can_verify_using(&sign)?);
26 println!("can encrypt: {}", public_key.can_encrypt_using(&encrypt)?);
27 println!(
28 "private key can sign: {}",
29 persisted.key()?.can_sign_using(&sign)?
30 );
31 store.remove_right(&persisted)?;
32 }
33 Err(error) => {
34 println!("public-key APIs need entitlements on many systems: {error}");
35 }
36 }
37
38 println!("✅ public-key smoke OK");
39 Ok(())
40}Sourcepub fn secret(&self) -> Result<LASecret>
pub fn secret(&self) -> Result<LASecret>
Borrow the generic secret associated with this persisted right.
§Errors
Returns an error if the Swift bridge rejects the request.
Examples found in repository?
12fn main() -> Result<(), Box<dyn std::error::Error>> {
13 let store = LARightStore::shared()?;
14 let right = LARight::new()?;
15 let identifier = unique_identifier("persisted");
16
17 match store.save_right_with_secret(&right, &identifier, b"top-secret") {
18 Ok(persisted) => {
19 persisted.set_tag(7)?;
20 println!("persisted state: {:?}", persisted.state()?);
21 println!("persisted tag: {}", persisted.tag()?);
22 println!("persisted preflight: {:?}", persisted.check_can_authorize());
23 println!("secret bytes: {}", persisted.secret()?.load_data()?.len());
24 store.remove_right(&persisted)?;
25 }
26 Err(error) => {
27 println!("persisted-right APIs need entitlements on many systems: {error}");
28 }
29 }
30
31 println!("✅ persisted-right smoke OK");
32 Ok(())
33}Sourcepub fn public_key(&self) -> Result<LAPublicKey>
pub fn public_key(&self) -> Result<LAPublicKey>
Convenience helper returning self.key()?.public_key().
§Errors
Returns an error if the Swift bridge rejects the request.
Examples found in repository?
12fn main() -> Result<(), Box<dyn std::error::Error>> {
13 let store = LARightStore::shared()?;
14 let right = LARight::new()?;
15 let identifier = unique_identifier("public-key");
16
17 match store.save_right(&right, &identifier) {
18 Ok(persisted) => {
19 let public_key = persisted.public_key()?;
20 let sign = SecKeyAlgorithm::ecdsa_signature_message_x962_sha256();
21 let encrypt =
22 SecKeyAlgorithm::ecies_encryption_cofactor_variable_iv_x963_sha256_aes_gcm();
23
24 println!("public key bytes: {}", public_key.export_bytes()?.len());
25 println!("can verify: {}", public_key.can_verify_using(&sign)?);
26 println!("can encrypt: {}", public_key.can_encrypt_using(&encrypt)?);
27 println!(
28 "private key can sign: {}",
29 persisted.key()?.can_sign_using(&sign)?
30 );
31 store.remove_right(&persisted)?;
32 }
33 Err(error) => {
34 println!("public-key APIs need entitlements on many systems: {error}");
35 }
36 }
37
38 println!("✅ public-key smoke OK");
39 Ok(())
40}