Skip to content

Commit

Permalink
rename some fields, change some documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
bitfl0wer committed Apr 15, 2024
1 parent 5032f41 commit 835b8b9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 23 deletions.
8 changes: 3 additions & 5 deletions src/certs/capabilities/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,10 @@ pub const OID_BASIC_CONSTRAINTS: &str = "2.5.29.19";
pub const OID_KEY_USAGE: &str = "2.5.29.15";

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
/// Capabilities which an ID-Cert or ID-CSR might have. For ID-Certs, you'd find these capabilities
/// in the `Extensions` field of a certificate. ID-CSRs store these capabilities as part of the
/// `Attributes` field.
/// An abstraction over X.509 Extensions and PKCS#10 Attributes, representing the capabilities
/// of a certificate. Capabilities can be converted from and to both [Attributes] and [Extensions].
///
/// This struct only covers the CertCapability subtype trees of which at least one of the subtypes
/// are relevant to polyproto certificates.
/// This struct only covers the Attributes/Extensions currently relevant to polyproto.
pub struct Capabilities {
/// The key usage extension defines the purpose of the key contained in the certificate.
pub key_usage: KeyUsages,
Expand Down
18 changes: 9 additions & 9 deletions src/certs/idcerttbs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ pub struct IdCertTbs<S: Signature, P: PublicKey<S>> {
pub validity: Validity,
/// X.501 name, identifying the subject (actor) of the certificate.
pub subject: Name,
/// Information regarding the subjects' public key.
pub subject_public_key_info: P,
/// X.509 Extensions matching what is described in the polyproto specification document.
/// The subjects' public key: [PublicKey].
pub subject_public_key: P,
/// Capabilities assigned to the subject of the certificate.
pub capabilities: Capabilities,
/// PhantomData
s: std::marker::PhantomData<S>,
Expand Down Expand Up @@ -84,7 +84,7 @@ impl<S: Signature, P: PublicKey<S>> IdCertTbs<S, P> {
id_csr.validate()?;
issuer.validate()?;
// Verify if signature of IdCsr matches contents
id_csr.inner_csr.subject_public_key_info.verify_signature(
id_csr.inner_csr.subject_public_key.verify_signature(
&id_csr.signature,
id_csr.inner_csr.clone().to_der()?.as_slice(),
)?;
Expand All @@ -94,7 +94,7 @@ impl<S: Signature, P: PublicKey<S>> IdCertTbs<S, P> {
issuer,
validity,
subject: id_csr.inner_csr.subject,
subject_public_key_info: id_csr.inner_csr.subject_public_key_info,
subject_public_key: id_csr.inner_csr.subject_public_key,
capabilities: id_csr.inner_csr.capabilities,
s: std::marker::PhantomData,
})
Expand All @@ -120,7 +120,7 @@ impl<S: Signature, P: PublicKey<S>> IdCertTbs<S, P> {
}
id_csr.validate()?;
// Verify if signature of IdCsr matches contents
id_csr.inner_csr.subject_public_key_info.verify_signature(
id_csr.inner_csr.subject_public_key.verify_signature(
&id_csr.signature,
id_csr.inner_csr.clone().to_der()?.as_slice(),
)?;
Expand All @@ -130,7 +130,7 @@ impl<S: Signature, P: PublicKey<S>> IdCertTbs<S, P> {
issuer,
validity,
subject: id_csr.inner_csr.subject,
subject_public_key_info: id_csr.inner_csr.subject_public_key_info,
subject_public_key: id_csr.inner_csr.subject_public_key,
capabilities: id_csr.inner_csr.capabilities,
s: std::marker::PhantomData,
})
Expand Down Expand Up @@ -177,7 +177,7 @@ impl<P: Profile, S: Signature, Q: PublicKey<S>> TryFrom<TbsCertificateInner<P>>
issuer: value.issuer,
validity: value.validity,
subject: value.subject,
subject_public_key_info,
subject_public_key: subject_public_key_info,
capabilities,
s: std::marker::PhantomData,
})
Expand Down Expand Up @@ -214,7 +214,7 @@ impl<P: Profile, S: Signature, Q: PublicKey<S>> TryFrom<IdCertTbs<S, Q>>
issuer: value.issuer,
validity: value.validity,
subject: value.subject,
subject_public_key_info: value.subject_public_key_info.public_key_info().into(),
subject_public_key_info: value.subject_public_key.public_key_info().into(),
issuer_unique_id: None,
subject_unique_id: None,
extensions: Some(Extensions::try_from(value.capabilities)?),
Expand Down
13 changes: 6 additions & 7 deletions src/certs/idcsr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,9 @@ pub struct IdCsrInner<S: Signature, P: PublicKey<S>> {
pub version: PkcsVersion,
/// Information about the subject (actor).
pub subject: Name,
/// The subjects' public key and related metadata.
pub subject_public_key_info: P,
/// attributes is a collection of attributes providing additional
/// information about the subject of the certificate.
/// The subjects' public key: [PublicKey].
pub subject_public_key: P,
/// Capabilities requested by the subject.
pub capabilities: Capabilities,
phantom_data: PhantomData<S>,
}
Expand All @@ -155,7 +154,7 @@ impl<S: Signature, P: PublicKey<S>> IdCsrInner<S, P> {
Ok(IdCsrInner {
version: PkcsVersion::V1,
subject,
subject_public_key_info,
subject_public_key: subject_public_key_info,
capabilities: capabilities.clone(),
phantom_data: PhantomData,
})
Expand Down Expand Up @@ -198,7 +197,7 @@ impl<S: Signature, P: PublicKey<S>> TryFrom<CertReqInfo> for IdCsrInner<S, P> {
Ok(IdCsrInner {
version: PkcsVersion::V1,
subject: rdn_sequence,
subject_public_key_info: PublicKey::try_from_public_key_info(public_key_info)?,
subject_public_key: PublicKey::try_from_public_key_info(public_key_info)?,
capabilities: Capabilities::try_from(value.attributes)?,
phantom_data: PhantomData,
})
Expand All @@ -223,7 +222,7 @@ impl<S: Signature, P: PublicKey<S>> TryFrom<IdCsrInner<S, P>> for CertReqInfo {
Ok(CertReqInfo {
version: x509_cert::request::Version::V1,
subject: value.subject,
public_key: value.subject_public_key_info.public_key_info().into(),
public_key: value.subject_public_key.public_key_info().into(),
attributes: Attributes::try_from(value.capabilities)?,
})
}
Expand Down
4 changes: 2 additions & 2 deletions src/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl<S: Signature, P: PublicKey<S>> Constrained for IdCsr<S, P> {
fn validate(&self) -> Result<(), ConstraintError> {
self.inner_csr.capabilities.validate()?;
self.inner_csr.subject.validate()?;
match self.inner_csr.subject_public_key_info.verify_signature(
match self.inner_csr.subject_public_key.verify_signature(
&self.signature,
match &self.inner_csr.clone().to_der() {
Ok(data) => data,
Expand All @@ -224,7 +224,7 @@ impl<S: Signature, P: PublicKey<S>> Constrained for IdCsr<S, P> {
impl<S: Signature, P: PublicKey<S>> Constrained for IdCert<S, P> {
fn validate(&self) -> Result<(), ConstraintError> {
self.id_cert_tbs.validate()?;
match self.id_cert_tbs.subject_public_key_info.verify_signature(
match self.id_cert_tbs.subject_public_key.verify_signature(
&self.signature,
match &self.id_cert_tbs.clone().to_der() {
Ok(data) => data,
Expand Down

0 comments on commit 835b8b9

Please sign in to comment.