-
Notifications
You must be signed in to change notification settings - Fork 146
spki: make AlgorithmIdentifier
generic around Params
#769
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
Conversation
efc5b1a
to
c98cbee
Compare
@@ -36,7 +39,7 @@ use der::pem::PemLabel; | |||
#[derive(Copy, Clone, Debug, Eq, PartialEq)] | |||
pub struct SubjectPublicKeyInfo<'a> { | |||
/// X.509 [`AlgorithmIdentifier`] for the public key type | |||
pub algorithm: AlgorithmIdentifier<'a>, | |||
pub algorithm: AlgorithmIdentifierRef<'a>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this would be a lot more useful if Params
were also added to SubjectPublicKeyInfo
, i.e. this were changed to AlgorithmIdentifier<Params>
.
It should probably get tackled as part of this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise it should be changed on PrivateKeyInfo
in the pkcs8
crate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be some type bound rather than generic <Params>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After trying to implement generic arguments to SPKI or to Certificate/TBSCertificate, I think that Params
might need to be bound with something like Into<AnyRef>
, or any other generic enough type, so that there would be no need to add type parameters to these structures. I might be wrong with the SPKI, but handling type parameters for Certificate looks like a complete mess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't follow what you mean by "type bound" if not a generic parameter.
If you need additional bounds you can always specify them. But requiring one would be rather onerous I think, especially as the conversion for e.g. ObjectIdentifier
only works for &ObjectIdentifier
.
Certificate/TBSCertificate
...those should be using a concrete type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still playing here. I have the feeling that TBSCertitificate & company should not have generic parameters per se. Otherwise handling them easily becomes a mess. I'm still trying to fit SPKI / SPKIRef properly into my code. Maybe this will flow better once I update RSA crate to return specific SPKI rather than generic SPKIRef.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, they should use a concrete type. The only things I think it makes sense parameterizing are AlgorithmIdentifier
, SubjectPublicKeyInfo
, and PrivateKeyInfo
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any easy way to perform the Into<AnyRef>
or TryInto<AnyRef>
conversion? The only way I have at this moment is to encode the AlgorithmIndeifier<Params>
into DER format and then reparse it again into AlgorithmIndentifierRef
.
impl<'a> AlgorithmIdentifierRef<'a> { | ||
/// Assert the `algorithm` OID is an expected value. | ||
pub fn assert_algorithm_oid(&self, expected_oid: ObjectIdentifier) -> Result<ObjectIdentifier> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left the inherent methods unchanged for now, however it's now possible to use AlgorithmIdentifier<ObjectIdentifier>
which eliminates the need for many of them, since the main thing they provide is type conversions to/from ObjectIdentifier
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assert_algorithm_oid should be implemented for the generic type, not for the AlgorithmIdentifierRef
b5c715d
to
630514d
Compare
This is a weird failure: https://github.com/RustCrypto/formats/actions/runs/3551054810/jobs/5964957749
|
@@ -75,7 +75,7 @@ pub struct RevokedCert<'a> { | |||
#[allow(missing_docs)] | |||
pub struct TbsCertList<'a> { | |||
pub version: Version, | |||
pub signature: AlgorithmIdentifier<'a>, | |||
pub signature: AlgorithmIdentifierRef<'a>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should also allow AlgorithmIdentifier<...>
(and in Certificate
/CertificateList
) too.
I can not come with the good enough argument at this moment.
@tarcieri please consider also merging https://pastebin.com/fNszVrjA I tried generalizing |
I think some of that looks good but would rather hold off on doing those sorts of updates in follow-up PRs. Maybe you can PR them separately after this is merged? This PR isn't done yet and it's going to get more complex with changes to |
This is a regression on nightly. Temporary fix here: |
@tarcieri sure, I can update |
@lumag b09ff11 makes Unfortunately this isn't enough to eliminate the lifetime and allow a fully owned form. That would require making the public key data generic around e.g. a |
ffb9092
to
b09ff11
Compare
I've played a bit with the PR. patch on `x509-cert/src/certificate.rs`
I'm not sure the |
@baloo I don't think it makes sense to parameterize Instead they can use owned/allocating |
Ha, right, I missed the intention of the |
I think it allows for a number of cross-cutting concerns, including using a concrete type like We're also trying to solve the problem of having |
Previously `AlgorithmIdentifier::parameters` were always `AnyRef`. This commit changes them to a generic parameter `Params`. An alias `AlgorithmIdentifierRef` provides a type identical to the original with `AnyRef` as its `parameters`, which is used in all of the other crates in this repo.
b09ff11
to
d6741cb
Compare
AlgorithmIdentifier
generic around Params
AlgorithmIdentifier
generic around Params
NOTE: breaking change.
Previously
AlgorithmIdentifier::parameters
were alwaysAnyRef
. This commit changes them to a generic parameterParams
.An alias
AlgorithmIdentifierRef
provides a type identical to the original withAnyRef
as itsparameters
, which is used in all of the other crates in this repo.cc @baloo @lumag