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

secrecy: make integer primitive SecretSlices cloneable #1236

Merged

Conversation

tony-iqlusion
Copy link
Member

Impls Clone for SecretSlice when the S generic type is CloneableSecret + Zeroize.

As originally requested in #1070, also marks the integer primitive types as CloneableSecret, which makes it possible to clone a SecretSlice<u8>.

Closes #1233

@tony-iqlusion tony-iqlusion force-pushed the secrecy/make-integer-primitive-secret-slices-clonable branch from aea9ccf to 66611cd Compare October 9, 2024 18:32
Impls `Clone` for `SecretSlice` when the `S` generic type is
`CloneableSecret + Zeroize`.

As originally requested in #1070, also marks the integer primitive types
as `CloneableSecret`, which makes it possible to clone a
`SecretSlice<u8>`.

Closes #1233
@tony-iqlusion tony-iqlusion force-pushed the secrecy/make-integer-primitive-secret-slices-clonable branch from 66611cd to faa5866 Compare October 9, 2024 18:51
@tony-iqlusion tony-iqlusion merged commit 08977b5 into main Oct 9, 2024
10 checks passed
@tony-iqlusion tony-iqlusion deleted the secrecy/make-integer-primitive-secret-slices-clonable branch October 9, 2024 18:53
@tony-iqlusion tony-iqlusion mentioned this pull request Oct 9, 2024
@nbari
Copy link

nbari commented Oct 28, 2024

Hi @tony-iqlusion before this used to work Secret<[u8, 32]> I am trying now SecretSlice<[u8; 32]> but I get:

the trait `Zeroize` is not implemented for `[[u8; 32]]`

my trait function looks like:

// Define a trait for cryptographic algorithms
pub trait Crypto {
    fn new(key: SecretSlice<[u8; 32]>) -> Self;
    fn encrypt(&self, data: &[u8], fingerprint: &[u8]) -> Result<Vec<u8>>;
    fn decrypt(&self, data: &[u8], fingerprint: &[u8]) -> Result<Vec<u8>>;
}

Any ideas on how to make it work of how to migrate from secret 0.8?

@tony-iqlusion
Copy link
Member Author

You'd probably want SecretBox in this case, not SecretSlice, since that would create a slice of arrays.

I think the best fix here might be to impl ClonableSecret for all arrays whose inner T is a ClonableSecret.

@nbari
Copy link

nbari commented Oct 28, 2024

Hi @tony-iqlusion I ended up using SecretSlice<u8> seems to be doing the trick, If I understand it is just a vector of unspecified size the one I can later just fill with <[u8, 32>] or am I missing something? Just in case I am using it here:
https://github.com/ssh-vault/ssh-vault/blob/develop/src/vault/crypto/mod.rs#L13

That is allowing me to use .clone() https://github.com/ssh-vault/ssh-vault/blob/develop/src/vault/ssh/ed25519.rs#L62-L63

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.

secrecy: cannot clone SecretSlice
2 participants