Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add set_secret() and get_secret() for iOS impl. #188

Merged
merged 5 commits into from
Jul 13, 2024

Conversation

tmpfs
Copy link
Contributor

@tmpfs tmpfs commented Jul 13, 2024

Closes #187.

Copy link
Collaborator

@brotskydotcom brotskydotcom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your definitions of set_secret and get_secret are perfect.

But, like the macOS implementation, you should have set_password call set_secret like this:

    fn set_password(&self, password: &str) -> Result<()> {
        self.set_secret(password.as_bytes())
    }

and you should have get_password call get_secret like this:

    fn get_password(&self) -> Result<String> {
        let password_bytes = self.get_secret()?;
        decode_password(password_bytes.to_vec())
    }

@brotskydotcom brotskydotcom self-assigned this Jul 13, 2024
@tmpfs
Copy link
Contributor Author

tmpfs commented Jul 13, 2024

Good call @brotskydotcom , thats done!

Copy link
Collaborator

@brotskydotcom brotskydotcom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent! Thank you so much!

@tmpfs
Copy link
Contributor Author

tmpfs commented Jul 13, 2024

I notice you convert to Vec<u8> when calling decode_password() but std::str::from_utf8 will take a slice so you can just pass to without the calls to to_vec().

Edit: so if you prefer std::str::from_utf8 to String::from_utf8 then we could avoid the allocations here make the code a bit tidier.

@brotskydotcom
Copy link
Collaborator

Can you please update README.md to add your name in the contributor's list?

@brotskydotcom
Copy link
Collaborator

I notice you convert to Vec<u8> when calling decode_password() but std::str::from_utf8 will take a slice so you can just pass to without the calls to to_vec().

Edit: so if you prefer std::str::from_utf8 to String::from_utf8 then we could avoid the allocations here.

Well the definition of decode_password is shared across platforms and most of the others have already done the vector conversion. But I still like the optimization you suggest in the iOS case, because password_bytes is already a Vec when it comes back from get_secret, so there's really no reason to have the .to_vec() redundant copy made. It should just be decode_password(password_bytes).

src/ios.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@brotskydotcom brotskydotcom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one last fix needed.

@brotskydotcom
Copy link
Collaborator

brotskydotcom commented Jul 13, 2024

Whoops. Just noticed one more fix needed to get the example library working on iOS:

You need to change line 92 from

    use keyring::default::IosCredential;

to

    use keyring::ios::IosCredential;

Copy link
Collaborator

@brotskydotcom brotskydotcom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thanks for keeping at it!

@brotskydotcom brotskydotcom merged commit 58c11f3 into hwchen:master Jul 13, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IosCredentials is missing trait methods in v3
2 participants