Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions rust/c509-certificate/examples/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ use std::{

use asn1_rs::{oid, Oid};
use c509_certificate::{
c509_big_uint::UnwrappedBigUint,
c509_extensions::Extensions,
c509_issuer_sig_algo::IssuerSignatureAlgorithm,
c509_name::{rdn::RelativeDistinguishedName, Name, NameValue},
c509_subject_pub_key_algo::SubjectPubKeyAlgorithm,
c509_time::Time,
big_uint::UnwrappedBigUint,
extensions::Extensions,
issuer_sig_algo::IssuerSignatureAlgorithm,
name::{rdn::RelativeDistinguishedName, Name, NameValue},
signing::{PrivateKey, PublicKey},
subject_pub_key_algo::SubjectPubKeyAlgorithm,
tbs_cert::TbsCert,
time::Time,
};
use chrono::{DateTime, Utc};
use clap::Parser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use asn1_rs::Oid;
use minicbor::{encode::Write, Decode, Decoder, Encode, Encoder};
use serde::{Deserialize, Serialize};

use crate::c509_oid::C509oid;
use crate::oid::C509oid;

/// A struct represents the `AlgorithmIdentifier` type.
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use minicbor::{encode::Write, Decode, Decoder, Encode, Encoder};
use serde::{Deserialize, Deserializer, Serialize};

use super::data::{get_oid_from_int, ATTRIBUTES_LOOKUP};
use crate::c509_oid::{C509oid, C509oidRegistered};
use crate::oid::{C509oid, C509oidRegistered};

/// A struct of C509 `Attribute`
#[derive(Debug, Clone, PartialEq)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use minicbor::{encode::Write, Decode, Decoder, Encode, Encoder};
use serde::{Deserialize, Serialize};

/// A struct representing an unwrapped CBOR unsigned bignum.
#[allow(clippy::module_name_repetitions)]
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct UnwrappedBigUint(u64);

Expand Down
2 changes: 1 addition & 1 deletion rust/c509-certificate/src/c509.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};

use crate::tbs_cert::TbsCert;

#[derive(Deserialize, Serialize)]
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
/// A struct represents the `C509` Certificate.
pub struct C509 {
/// A TBS Certificate.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use minicbor::{encode::Write, Decode, Decoder, Encode, Encoder};
use serde::{Deserialize, Serialize};

use crate::c509_general_names::{
use crate::general_names::{
general_name::{GeneralName, GeneralNameTypeRegistry, GeneralNameValue},
GeneralNames,
};
Expand All @@ -20,6 +20,12 @@ impl AlternativeName {
pub fn new(value: GeneralNamesOrText) -> Self {
Self(value)
}

/// Get the inner of Alternative Name.
#[must_use]
pub fn get_inner(&self) -> &GeneralNamesOrText {
&self.0
}
}

impl Encode<()> for AlternativeName {
Expand Down Expand Up @@ -55,11 +61,11 @@ impl Encode<()> for GeneralNamesOrText {
match self {
GeneralNamesOrText::GeneralNames(gns) => {
let gn = gns
.get_gns()
.get_inner()
.first()
.ok_or(minicbor::encode::Error::message("GeneralNames is empty"))?;
// Check whether there is only 1 item in the array which is a DNSName
if gns.get_gns().len() == 1 && gn.get_gn_type().is_dns_name() {
if gns.get_inner().len() == 1 && gn.get_gn_type().is_dns_name() {
gn.get_gn_value().encode(e, ctx)?;
} else {
gns.encode(e, ctx)?;
Expand Down Expand Up @@ -105,7 +111,7 @@ impl Decode<'_, ()> for GeneralNamesOrText {
#[cfg(test)]
mod test_alt_name {
use super::*;
use crate::c509_general_names::general_name::{
use crate::general_names::general_name::{
GeneralName, GeneralNameTypeRegistry, GeneralNameValue,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use serde::{Deserialize, Deserializer, Serialize};
use strum_macros::EnumDiscriminants;

use super::alt_name::AlternativeName;
use crate::c509_oid::{C509oid, C509oidRegistered};
use crate::oid::{C509oid, C509oidRegistered};

/// A struct of C509 `Extension`
#[derive(Debug, Clone, PartialEq)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ impl Extensions {
pub fn add_ext(&mut self, extension: Extension) {
self.0.push(extension);
}

/// Get the inner vector of `Extensions`.
#[must_use]
pub fn get_inner(&self) -> &Vec<Extension> {
&self.0
}
}

impl Encode<()> for Extensions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use super::{
data::{get_gn_from_int, get_gn_value_type_from_int, get_int_from_gn},
other_name_hw_module::OtherNameHardwareModuleName,
};
use crate::{c509_name::Name, c509_oid::C509oid};
use crate::{name::Name, oid::C509oid};

/// A struct represents a `GeneralName`.
/// ```cddl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ impl GeneralNames {
self.0.push(gn);
}

/// Get the a vector of `GeneralName`.
pub(crate) fn get_gns(&self) -> &Vec<GeneralName> {
/// Get the inner of `GeneralName`.
#[must_use]
pub fn get_inner(&self) -> &Vec<GeneralName> {
&self.0
}
}
Expand Down Expand Up @@ -85,7 +86,7 @@ mod test_general_names {
use other_name_hw_module::OtherNameHardwareModuleName;

use super::*;
use crate::c509_oid::C509oid;
use crate::oid::C509oid;

#[test]
fn encode_decode_gns() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use asn1_rs::Oid;
use minicbor::{encode::Write, Decode, Decoder, Encode, Encoder};
use serde::{Deserialize, Serialize};

use crate::c509_oid::C509oid;
use crate::oid::C509oid;

/// A struct represents the hardwareModuleName type of otherName.
/// Containing a pair of ( hwType, hwSerialNum ) as mentioned in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use data::{get_oid_from_int, ISSUER_SIG_ALGO_LOOKUP};
use minicbor::{encode::Write, Decode, Decoder, Encode, Encoder};
use serde::{Deserialize, Deserializer, Serialize};

use crate::{c509_algo_identifier::AlgorithmIdentifier, c509_oid::C509oidRegistered};
use crate::{algorithm_identifier::AlgorithmIdentifier, oid::C509oidRegistered};

/// A struct represents the `IssuerSignatureAlgorithm`
#[derive(Debug, Clone, PartialEq)]
Expand Down
20 changes: 10 additions & 10 deletions rust/c509-certificate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ use c509::C509;
use minicbor::{Decode, Encode};
use signing::{PrivateKey, PublicKey};
use tbs_cert::TbsCert;
pub mod algorithm_identifier;
pub mod attributes;
pub mod big_uint;
pub mod c509;
pub mod c509_algo_identifier;
pub mod c509_attributes;
pub mod c509_big_uint;
pub mod c509_extensions;
pub mod c509_general_names;
pub mod c509_issuer_sig_algo;
pub mod c509_name;
pub mod c509_oid;
pub mod c509_subject_pub_key_algo;
pub mod c509_time;
pub mod extensions;
pub mod general_names;
pub mod issuer_sig_algo;
pub mod name;
pub mod oid;
pub mod signing;
pub mod subject_pub_key_algo;
mod tables;
pub mod tbs_cert;
pub mod time;
pub mod wasm_binding;

/// Generate a signed or unsigned C509 certificate.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use rdn::RelativeDistinguishedName;
use regex::Regex;
use serde::{Deserialize, Serialize};

use crate::c509_attributes::attribute::{Attribute, AttributeValue};
use crate::attributes::attribute::{Attribute, AttributeValue};

/// OID of `CommonName` attribute.
const COMMON_NAME_OID: Oid<'static> = oid!(2.5.4 .3);
Expand Down Expand Up @@ -73,6 +73,7 @@ impl Decode<'_, ()> for Name {
// ------------------NameValue----------------------

/// An enum of possible value types for `Name`.
#[allow(clippy::module_name_repetitions)]
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum NameValue {
Expand Down Expand Up @@ -283,7 +284,7 @@ fn create_rdn_with_cn_attr(text: String) -> NameValue {
#[cfg(test)]
pub(crate) mod test_name {
use super::*;
use crate::c509_attributes::attribute::Attribute;
use crate::attributes::attribute::Attribute;

// Test data from https://datatracker.ietf.org/doc/draft-ietf-cose-cbor-encoded-cert/09/
// A.1.1. Example C509 Certificate Encoding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use minicbor::{encode::Write, Decode, Decoder, Encode, Encoder};
use serde::{Deserialize, Serialize};

use crate::c509_attributes::attribute::Attribute;
use crate::attributes::attribute::Attribute;

/// A struct represents a Relative Distinguished Name containing vector of `Attribute`.
///
Expand Down Expand Up @@ -104,7 +104,7 @@ mod test_relative_distinguished_name {
use asn1_rs::oid;

use super::*;
use crate::c509_attributes::attribute::AttributeValue;
use crate::attributes::attribute::AttributeValue;

#[test]
fn encode_decode_rdn() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ impl C509oidRegistered {
}

/// Get the `C509oid`.
pub(crate) fn get_c509_oid(&self) -> C509oid {
#[must_use]
pub fn get_c509_oid(&self) -> C509oid {
self.oid.clone()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use data::{get_oid_from_int, SUBJECT_PUB_KEY_ALGO_LOOKUP};
use minicbor::{encode::Write, Decode, Decoder, Encode, Encoder};
use serde::{Deserialize, Deserializer, Serialize};

use crate::{c509_algo_identifier::AlgorithmIdentifier, c509_oid::C509oidRegistered};
use crate::{algorithm_identifier::AlgorithmIdentifier, oid::C509oidRegistered};

/// A struct represents the `SubjectPubKeyAlgorithm`
#[derive(Debug, Clone, PartialEq)]
Expand Down
13 changes: 6 additions & 7 deletions rust/c509-certificate/src/tbs_cert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ use minicbor::{encode::Write, Decode, Decoder, Encode, Encoder};
use serde::{Deserialize, Serialize};

use crate::{
c509_big_uint::UnwrappedBigUint, c509_extensions::Extensions,
c509_issuer_sig_algo::IssuerSignatureAlgorithm, c509_name::Name,
c509_subject_pub_key_algo::SubjectPubKeyAlgorithm, c509_time::Time,
big_uint::UnwrappedBigUint, extensions::Extensions, issuer_sig_algo::IssuerSignatureAlgorithm,
name::Name, subject_pub_key_algo::SubjectPubKeyAlgorithm, time::Time,
};

/// A struct represents a To Be Signed Certificate (TBS Certificate).
Expand Down Expand Up @@ -182,17 +181,17 @@ pub(crate) mod test_tbs_cert {

use super::*;
use crate::{
c509_attributes::attribute::{Attribute, AttributeValue},
c509_extensions::{
attributes::attribute::{Attribute, AttributeValue},
extensions::{
alt_name::{AlternativeName, GeneralNamesOrText},
extension::{Extension, ExtensionValue},
},
c509_general_names::{
general_names::{
general_name::{GeneralName, GeneralNameTypeRegistry, GeneralNameValue},
other_name_hw_module::OtherNameHardwareModuleName,
GeneralNames,
},
c509_name::{
name::{
rdn::RelativeDistinguishedName,
test_name::{name_cn_eui_mac, name_cn_text, names},
NameValue,
Expand Down