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

pkcs8: provide PrivateKeyInfoRef/PrivateKeyInfoOwned #1483

Merged
merged 14 commits into from
Sep 4, 2024

Conversation

baloo
Copy link
Member

@baloo baloo commented Aug 18, 2024

#1183 mark 2

This makes the PrivateKeyInfo generic over its backing storage, and this provides two version of it, namely PrivateKeyInfoRef and PrivateKeyInfoOwned respectively borrowing the value and owning the storage of the value.

followup PRs:

reader.read_nested(header.length, |reader| {
// Parse and validate `version` INTEGER.
let version = Version::decode(reader)?;
let algorithm = reader.decode()?;
let private_key = OctetStringRef::decode(reader)?.into();
let private_key: &[u8] = OctetStringRef::decode(reader)?.into();
let private_key = Key::try_from(private_key)?;
Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, this could be an OctetString or OctetStringRef instead. I don't know what I was thinking last year.

Copy link
Member

Choose a reason for hiding this comment

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

clippy seems to suggest From over TryFrom

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, clippy lead me to rethink my position on OctetString actually.
I rewrote the backing storage in the follow up commit.

@baloo baloo force-pushed the baloo/pkcs8/owned-ref-private-key branch from 71c9927 to 8191fb6 Compare August 19, 2024 07:14
@baloo
Copy link
Member Author

baloo commented Aug 19, 2024

and that is now causing problems all over the place, sweet.

baloo added a commit to baloo/signatures that referenced this pull request Aug 19, 2024
baloo added a commit to baloo/RSA that referenced this pull request Aug 19, 2024
baloo added a commit to baloo/traits that referenced this pull request Aug 19, 2024
@baloo baloo force-pushed the baloo/pkcs8/owned-ref-private-key branch from 5e9b14d to bcf2035 Compare August 19, 2024 17:32
Comment on lines +374 to +385
pub trait BitStringLike {
fn as_bit_string(&self) -> BitStringRef<'_>;
}

impl<'a> BitStringLike for BitStringRef<'a> {
fn as_bit_string(&self) -> BitStringRef<'_> {
BitStringRef::from(self)
}
}
Copy link
Member Author

@baloo baloo Aug 19, 2024

Choose a reason for hiding this comment

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

I could not figure out a way to express this with the traits implemented by both BitStringRef and BitString.

Copy link
Member

Choose a reason for hiding this comment

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

In the interest of getting this PR across the finish line I'll go ahead and merge this, but I think we should definitely find a better solution, and it should go in the der crate.

Something like OwnedToRef but impl'd for both the owned and reference types so it can be used interchangeably, and for any of the *Ref types and not just specialized to BitString*.

@baloo baloo force-pushed the baloo/pkcs8/owned-ref-private-key branch from fb4becf to 3400a03 Compare August 19, 2024 22:36
@baloo baloo requested a review from tarcieri August 20, 2024 16:21
Copy link
Member

@tarcieri tarcieri left a comment

Choose a reason for hiding this comment

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

Approved with mild dissatisfaction in BitStringLike. Hopefully we can find a better, more general solution.

@tarcieri tarcieri merged commit 6877a3e into RustCrypto:master Sep 4, 2024
165 checks passed
@baloo baloo deleted the baloo/pkcs8/owned-ref-private-key branch September 4, 2024 23:47
baloo added a commit to baloo/traits that referenced this pull request Sep 5, 2024
baloo added a commit to baloo/signatures that referenced this pull request Sep 5, 2024
baloo added a commit to baloo/traits that referenced this pull request Sep 5, 2024
baloo added a commit to baloo/traits that referenced this pull request Sep 5, 2024
baloo added a commit to baloo/traits that referenced this pull request Sep 5, 2024
baloo added a commit to baloo/signatures that referenced this pull request Sep 5, 2024
tarcieri pushed a commit to RustCrypto/traits that referenced this pull request Sep 5, 2024
baloo added a commit to baloo/RSA that referenced this pull request Sep 5, 2024
tarcieri pushed a commit to RustCrypto/RSA that referenced this pull request Sep 5, 2024
baloo added a commit to baloo/formats that referenced this pull request Sep 6, 2024
 - pkcs1 `0.8.0-rc.1`
 - pkcs8 `0.11.0-rc.1`
 - sec1 `0.8.0-rc.1`

This comes after the merge of API breaks on pkcs8 ([RustCrypto#1483])

[RustCrypto#1483]: RustCrypto#1483
baloo added a commit that referenced this pull request Sep 6, 2024
- pkcs1 `0.8.0-rc.1`
 - pkcs8 `0.11.0-rc.1`
 - sec1 `0.8.0-rc.1`

This comes after the merge of API breaks on pkcs8 ([#1483])

[#1483]: #1483
baloo added a commit to baloo/signatures that referenced this pull request Sep 6, 2024
This bump the following dependencies:
 - pkcs8 0.11.0-rc.0 -> 0.11.0-rc.1
 - elliptic-curve 0.14.0-pre.6 -> 0.14.0-rc.0

This is a followup on breaking changes made on pkcs8
(RustCrypto/formats#1483).
tarcieri pushed a commit to RustCrypto/signatures that referenced this pull request Sep 6, 2024
This bump the following dependencies:
 - pkcs8 0.11.0-rc.0 -> 0.11.0-rc.1
 - elliptic-curve 0.14.0-pre.6 -> 0.14.0-rc.0

This is a followup on breaking changes made on pkcs8
(RustCrypto/formats#1483).
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.

2 participants