Skip to content

Commit

Permalink
chore: fix name and comment
Browse files Browse the repository at this point in the history
  • Loading branch information
bkioshn committed Jul 8, 2024
1 parent 7817f8c commit 45d14ee
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl Decode<'_, ()> for GeneralNamesOrText {
mod test_alt_name {
use super::*;
use crate::c509_general_names::general_name::{
GeneralName, GeneralNameRegistry, GeneralNameValue,
GeneralName, GeneralNameTypeRegistry, GeneralNameValue,
};

#[test]
Expand All @@ -102,7 +102,7 @@ mod test_alt_name {
let mut encoder = Encoder::new(&mut buffer);
let mut gns = GeneralNames::new();
gns.add_gn(GeneralName::new(
GeneralNameRegistry::DNSName,
GeneralNameTypeRegistry::DNSName,
GeneralNameValue::Text("example.com".to_string()),
));
let alt_name = AlternativeName::new(GeneralNamesOrText::GeneralNames(gns));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,6 @@ impl Extension {
pub fn get_registered_oid(&self) -> &C509oidRegistered {
&self.registered_oid
}

/// Set the critical flag of the `Extension`.
#[must_use]
pub fn set_critical(mut self) -> Self {
self.critical = true;
self
}
}

impl Encode<()> for Extension {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,66 +7,66 @@ use std::collections::HashMap;
use bimap::BiMap;
use once_cell::sync::Lazy;

use super::general_name::{GeneralNameRegistry, GeneralNameValueType};
use super::general_name::{GeneralNameTypeRegistry, GeneralNameValueType};
use crate::tables::{IntTable, TableTrait};

/// Type of `GeneralName` data.
/// Int | Name | Type
type GeneralNameDataTuple = (i16, GeneralNameRegistry, GeneralNameValueType);
type GeneralNameDataTuple = (i16, GeneralNameTypeRegistry, GeneralNameValueType);

/// `GeneralName` data table.
const GENERAL_NAME_DATA: [GeneralNameDataTuple; 10] = [
(
-3,
GeneralNameRegistry::OtherNameBundleEID,
GeneralNameTypeRegistry::OtherNameBundleEID,
GeneralNameValueType::Unsupported,
),
(
-2,
GeneralNameRegistry::OtherNameSmtpUTF8Mailbox,
GeneralNameTypeRegistry::OtherNameSmtpUTF8Mailbox,
GeneralNameValueType::Text,
),
(
-1,
GeneralNameRegistry::OtherNameHardwareModuleName,
GeneralNameTypeRegistry::OtherNameHardwareModuleName,
GeneralNameValueType::OtherNameHWModuleName,
),
(
0,
GeneralNameRegistry::OtherName,
GeneralNameTypeRegistry::OtherName,
GeneralNameValueType::OtherNameHWModuleName,
),
(
1,
GeneralNameRegistry::Rfc822Name,
GeneralNameTypeRegistry::Rfc822Name,
GeneralNameValueType::Text,
),
(2, GeneralNameRegistry::DNSName, GeneralNameValueType::Text),
(2, GeneralNameTypeRegistry::DNSName, GeneralNameValueType::Text),
(
4,
GeneralNameRegistry::DirectoryName,
GeneralNameTypeRegistry::DirectoryName,
GeneralNameValueType::Unsupported,
),
(
6,
GeneralNameRegistry::UniformResourceIdentifier,
GeneralNameTypeRegistry::UniformResourceIdentifier,
GeneralNameValueType::Text,
),
(
7,
GeneralNameRegistry::IPAddress,
GeneralNameTypeRegistry::IPAddress,
GeneralNameValueType::Bytes,
),
(
8,
GeneralNameRegistry::RegisteredID,
GeneralNameTypeRegistry::RegisteredID,
GeneralNameValueType::Oid,
),
];

/// A struct of data that contains lookup table for `GeneralName`.
pub(crate) struct GeneralNameData {
/// A table of integer to `GeneralNameRegistry`, provide a bidirectional lookup.
/// A table of integer to `GeneralNameTypeRegistry`, provide a bidirectional lookup.
int_to_name_table: IntegerToGNTable,
/// A table of integer to `GeneralNameValueType`, provide a lookup for the type of
/// `GeneralName` value.
Expand All @@ -85,23 +85,23 @@ impl GeneralNameData {
}
}

/// A struct of integer to `GeneralNameRegistry` table.
/// A struct of integer to `GeneralNameTypeRegistry` table.
#[derive(Debug, Clone, PartialEq)]
pub(crate) struct IntegerToGNTable(IntTable<GeneralNameRegistry>);
pub(crate) struct IntegerToGNTable(IntTable<GeneralNameTypeRegistry>);

impl IntegerToGNTable {
/// Create a new instance of `IntegerToGNTable`.
pub(crate) fn new() -> Self {
Self(IntTable::<GeneralNameRegistry>::new())
Self(IntTable::<GeneralNameTypeRegistry>::new())
}

/// Add a new integer to `GeneralNameRegistry` map table.
pub(crate) fn add(&mut self, k: i16, v: GeneralNameRegistry) {
/// Add a new integer to `GeneralNameTypeRegistry` map table.
pub(crate) fn add(&mut self, k: i16, v: GeneralNameTypeRegistry) {
self.0.add(k, v);
}

/// Get the map table of integer to `GeneralNameRegistry`.
pub(crate) fn get_map(&self) -> &BiMap<i16, GeneralNameRegistry> {
/// Get the map table of integer to `GeneralNameTypeRegistry`.
pub(crate) fn get_map(&self) -> &BiMap<i16, GeneralNameTypeRegistry> {
self.0.get_map()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@ use crate::c509_oid::C509oid;
/// ```
#[derive(Debug, Clone, PartialEq)]
pub struct GeneralName {
/// An enum of registered `GeneralName`.
gn: GeneralNameRegistry,
/// The value of the `GeneralName` in `GeneralNameValue`.
/// A registered general name type.
gn: GeneralNameTypeRegistry,
/// A general name value.
value: GeneralNameValue,
}

#[allow(dead_code)]
impl GeneralName {
/// Create a new instance of `GeneralName`.
#[must_use]
pub fn new(gn: GeneralNameRegistry, value: GeneralNameValue) -> Self {
pub fn new(gn: GeneralNameTypeRegistry, value: GeneralNameValue) -> Self {
Self { gn, value }
}

/// Get the `GeneralName` type.
#[must_use]
pub fn get_gn(&self) -> &GeneralNameRegistry {
pub fn get_gn(&self) -> &GeneralNameTypeRegistry {
&self.gn
}

Expand Down Expand Up @@ -93,12 +93,12 @@ impl Decode<'_, ()> for GeneralName {
}
}

// -----------------GeneralNameRegistry------------------------
// -----------------GeneralNameTypeRegistry------------------------

/// Enum of `GeneralName` registered in table Section 9.9 C509.
#[allow(clippy::module_name_repetitions)]
#[derive(Debug, Copy, PartialEq, Clone, Eq, Hash, EnumIs)]
pub enum GeneralNameRegistry {
pub enum GeneralNameTypeRegistry {
/// An otherName with `BundleEID`.
OtherNameBundleEID, // EID
/// An otherName with `SmtpUTF8Mailbox`.
Expand All @@ -121,8 +121,8 @@ pub enum GeneralNameRegistry {
RegisteredID,
}

impl GeneralNameRegistry {
/// Get the integer value associated with the `GeneralNameRegistry`.
impl GeneralNameTypeRegistry {
/// Get the integer value associated with the `GeneralNameTypeRegistry`.
pub(crate) fn get_int(self) -> Result<i16, Error> {
let i = GENERAL_NAME_TABLES
.get_int_to_name_table()
Expand Down Expand Up @@ -238,7 +238,7 @@ mod test_general_name {
let mut encoder = Encoder::new(&mut buffer);

let gn = GeneralName::new(
GeneralNameRegistry::DNSName,
GeneralNameTypeRegistry::DNSName,
GeneralNameValue::Text("example.com".to_string()),
);
gn.encode(&mut encoder, &mut ())
Expand All @@ -262,7 +262,7 @@ mod test_general_name {
0x01, 0x02, 0x03, 0x04,
]);
let gn = GeneralName::new(
GeneralNameRegistry::OtherNameHardwareModuleName,
GeneralNameTypeRegistry::OtherNameHardwareModuleName,
GeneralNameValue::OtherNameHWModuleName(hw),
);
gn.encode(&mut encoder, &mut ())
Expand All @@ -287,7 +287,7 @@ mod test_general_name {

let ipv4 = Ipv4Addr::new(192, 168, 1, 1);
let gn = GeneralName::new(
GeneralNameRegistry::IPAddress,
GeneralNameTypeRegistry::IPAddress,
GeneralNameValue::Bytes(ipv4.octets().to_vec()),
);

Expand All @@ -309,7 +309,7 @@ mod test_general_name {
let mut encoder = Encoder::new(&mut buffer);

let gn = GeneralName::new(
GeneralNameRegistry::RegisteredID,
GeneralNameTypeRegistry::RegisteredID,
GeneralNameValue::Oid(C509oid::new(oid!(2.16.840 .1 .101 .3 .4 .2 .1))),
);
gn.encode(&mut encoder, &mut ())
Expand All @@ -330,7 +330,7 @@ mod test_general_name {
let mut encoder = Encoder::new(&mut buffer);

let gn = GeneralName::new(
GeneralNameRegistry::OtherNameSmtpUTF8Mailbox,
GeneralNameTypeRegistry::OtherNameSmtpUTF8Mailbox,
GeneralNameValue::Oid(C509oid::new(oid!(2.16.840 .1 .101 .3 .4 .2 .1))),
);
gn.encode(&mut encoder, &mut ())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ mod test_general_names {
use std::net::Ipv4Addr;

use asn1_rs::oid;
use general_name::{GeneralNameRegistry, GeneralNameValue};
use general_name::{GeneralNameTypeRegistry, GeneralNameValue};
use other_name_hw_module::OtherNameHardwareModuleName;

use super::*;
Expand All @@ -93,22 +93,22 @@ mod test_general_names {

let mut gns = GeneralNames::new();
gns.add_gn(GeneralName::new(
GeneralNameRegistry::DNSName,
GeneralNameTypeRegistry::DNSName,
GeneralNameValue::Text("example.com".to_string()),
));
gns.add_gn(GeneralName::new(
GeneralNameRegistry::OtherNameHardwareModuleName,
GeneralNameTypeRegistry::OtherNameHardwareModuleName,
GeneralNameValue::OtherNameHWModuleName(OtherNameHardwareModuleName::new(
oid!(2.16.840 .1 .101 .3 .4 .2 .1),
vec![0x01, 0x02, 0x03, 0x04],
)),
));
gns.add_gn(GeneralName::new(
GeneralNameRegistry::IPAddress,
GeneralNameTypeRegistry::IPAddress,
GeneralNameValue::Bytes(Ipv4Addr::new(192, 168, 1, 1).octets().to_vec()),
));
gns.add_gn(GeneralName::new(
GeneralNameRegistry::RegisteredID,
GeneralNameTypeRegistry::RegisteredID,
GeneralNameValue::Oid(C509oid::new(oid!(2.16.840 .1 .101 .3 .4 .2 .1))),
));
gns.encode(&mut encoder, &mut ())
Expand Down

0 comments on commit 45d14ee

Please sign in to comment.