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

feat: C509 Name type #604

Merged
merged 204 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
204 commits
Select commit Hold shift + click to select a range
76d78b2
feat: setup c509 lib
bkioshn Apr 8, 2024
ef76f02
fix: update toml file
bkioshn Apr 9, 2024
19db45e
feat: add earthfile
bkioshn Apr 9, 2024
bc5b859
Merge branch 'main' into feat/setup-c509-lib
bkioshn Apr 9, 2024
083c8e7
fix: remove blank line
bkioshn Apr 9, 2024
a25c041
Merge branch 'feat/m3' into feat/setup-c509-lib
bkioshn Apr 10, 2024
34ea755
docs: Add CatalystDataGatewayRepository docs (#388)
coire1 Apr 10, 2024
805482c
adds one more worker and compression for catgateway logs (#400)
kukkok3 Apr 11, 2024
bb245a1
feat: Collect flutter code coverage (#404)
dtscalac Apr 12, 2024
0f8916e
Merge branch 'main' into feat/m3
Mr-Leshiy Apr 15, 2024
6365ce9
refactor: update schema_validation check (#414)
Mr-Leshiy Apr 15, 2024
aaf6809
Merge branch 'feat/m3' into feat/setup-c509-lib
bkioshn Apr 16, 2024
8ebd6ce
fix: update wasm testing
bkioshn Apr 19, 2024
1388eff
fix: remove clippy toml
bkioshn Apr 19, 2024
84ae2c7
Merge branch 'main' into feat/setup-c509-lib
bkioshn Apr 19, 2024
4226d49
fix: update cargo toml
bkioshn Apr 19, 2024
0106768
fix: spelling
bkioshn Apr 19, 2024
3c89375
fix: revert test report
bkioshn Apr 19, 2024
a0ac9ab
chore: add comment
bkioshn Apr 19, 2024
9ad1978
chore: update message
bkioshn Apr 19, 2024
06ae7c5
fix: update cargo.toml
bkioshn Apr 19, 2024
0c61614
chore: fix format
bkioshn Apr 19, 2024
8c045f9
fix: linter
bkioshn Apr 19, 2024
51e5b6e
fix: update cargo toml
bkioshn Apr 19, 2024
6eb77b0
fix: update cargo toml
bkioshn Apr 19, 2024
68e8566
Merge branch 'main' into feat/setup-c509-lib
bkioshn Apr 19, 2024
64622fc
fix: update project dic
bkioshn Apr 19, 2024
842d5d9
fix: remove wasm-pack install
bkioshn Apr 19, 2024
672166a
feat: add config
bkioshn Apr 19, 2024
70485dc
fix: earthly for c509
bkioshn Apr 19, 2024
4127344
Merge branch 'main' into feat/setup-c509-lib
bkioshn Apr 22, 2024
fc5caa4
feat: add regex dependency
bkioshn Apr 22, 2024
43c6ab5
feat: implement c509 type name
bkioshn Apr 22, 2024
1b2180d
fix: clean up lib.rs
bkioshn Apr 23, 2024
0ddf1a2
fix: add c509 cert module
bkioshn Apr 23, 2024
00c0dbf
feat: add x690 der
bkioshn Apr 23, 2024
de1366a
feat: wip TLV extract value
bkioshn May 2, 2024
3bad134
chore: add comment on TLV length
bkioshn May 2, 2024
ffdcb8a
fix (wip): update der parser
bkioshn May 4, 2024
cb95f63
fix (wip): update der parser
bkioshn May 6, 2024
9edb93d
fix (wip): update der parser
bkioshn May 7, 2024
1301ff9
fix (wip): update der parser
bkioshn May 7, 2024
e50f046
fix (wip): dependencies
bkioshn May 20, 2024
668bf5c
feat(wip): add c509 enum
bkioshn May 20, 2024
8fcc891
feat(wip): add cbor encode helper
bkioshn May 20, 2024
79aa5b5
feat(wip): add c509 cert helper
bkioshn May 20, 2024
14c5d13
fix(wip): modify lib
bkioshn May 20, 2024
91eebf6
feat(wip): add subject public key encoder
bkioshn May 26, 2024
4629bc9
fix: add thiserror
bkioshn May 28, 2024
f8b3d10
fix: cbor encode biguint and type name
bkioshn May 28, 2024
f587d7a
fix: cbor encode time
bkioshn May 28, 2024
d86fa68
fix: cleanup
bkioshn May 28, 2024
8c5bc12
fix: add oid crate
bkioshn May 28, 2024
7c63a33
feat: add extensions
bkioshn May 28, 2024
9e52c8d
feat: add alt name
bkioshn May 28, 2024
c6cb9cb
chore: remove fixme
bkioshn May 28, 2024
36d5ea2
fix: clean up c509 enum
bkioshn May 29, 2024
6181188
fix: rewrite cbor encoder
bkioshn May 29, 2024
5f7bd50
fix: move c509 crate folder
bkioshn May 29, 2024
d453981
feat: add gitignore
bkioshn May 29, 2024
ef70902
fix: cargo toml
bkioshn May 29, 2024
e6cc3f2
fix: cbor encoder
bkioshn May 29, 2024
b9c1da1
fix: remove der encoding
bkioshn May 29, 2024
3037e53
feat: add eid encoder
bkioshn May 30, 2024
d3e2e62
fix: ssp encoder
bkioshn Jun 3, 2024
5685716
feat: create genc509cert function
bkioshn Jun 3, 2024
d1c04d2
feat: add sigalgo registry
bkioshn Jun 3, 2024
a0fc33e
fix: altname type visibility
bkioshn Jun 3, 2024
32ed35c
fix: altname encoder
bkioshn Jun 3, 2024
613fd66
feat: add extension encoding func
bkioshn Jun 3, 2024
c079a17
fix: lib.rs
bkioshn Jun 3, 2024
7c3ebf5
fix: gen c509 function
bkioshn Jun 4, 2024
780d02f
fix: cbor encoder
bkioshn Jun 4, 2024
39a2f9c
fix: alt name
bkioshn Jun 4, 2024
7f28e94
fix: extensions
bkioshn Jun 4, 2024
326fe78
Merge branch 'main' into feat/c509-cert
bkioshn Jun 5, 2024
4b19b7a
Merge branch 'main' into feat/c509-cert
stevenj Jun 6, 2024
39b5111
Merge branch 'main' into feat/c509-cert
stevenj Jun 6, 2024
16f3643
Merge branch 'main' into feat/c509-cert
stevenj Jun 6, 2024
6878fe0
docs: update c509 docs
bkioshn Jun 11, 2024
42eb95a
Merge branch 'main' into feat/c509-cert
bkioshn Jun 11, 2024
862013b
fix: name
bkioshn Jun 11, 2024
4f8e63d
chore: remove unnecessary comments
bkioshn Jun 12, 2024
1d21b94
fix: macro definitions location
bkioshn Jun 14, 2024
db8b292
fix: earthly version and cspell
bkioshn Jun 14, 2024
c8fefb2
fix: update rust config file to match cat-ci stdcfg
bkioshn Jun 14, 2024
06ec613
fix: macro definitions location
bkioshn Jun 14, 2024
81e3dd8
feat: add oid encode/decode
bkioshn Jun 16, 2024
a80f477
fix: naming and test
bkioshn Jun 17, 2024
1c36a5d
fix: naming
bkioshn Jun 17, 2024
f740b4a
fix: implement encode and decode trait
bkioshn Jun 17, 2024
867836f
fix: test
bkioshn Jun 17, 2024
ccc6700
feat: add OID PEN encode and decode
bkioshn Jun 18, 2024
091670d
fix: merge
stevenj Jun 18, 2024
2e7b117
fix: merge
stevenj Jun 18, 2024
d572d0d
wip
stevenj Jun 18, 2024
eb6519c
fix: pen decode and encode
bkioshn Jun 18, 2024
4304d91
Merge branch 'main' into feat/c509-cert
stevenj Jun 18, 2024
7fdc8a6
fix: rewrite PEN encode and decode
bkioshn Jun 19, 2024
faeed8a
chore: add comments
bkioshn Jun 20, 2024
48beb67
fix: update c509 extensions
bkioshn Jun 21, 2024
70e5816
fix: add once cell
bkioshn Jun 24, 2024
f7761ca
fix: oid registry and oid extension implementation
bkioshn Jun 24, 2024
34dc486
fix (wip): extension value encoding
bkioshn Jun 24, 2024
d7716ec
fix: value encode and test
bkioshn Jun 25, 2024
dbb9a9a
fix: add decode extension
bkioshn Jun 25, 2024
d9dab5b
fix: extension decode value
bkioshn Jun 25, 2024
2107753
fix: delete files
bkioshn Jun 25, 2024
a0d0f16
Merge branch 'main' into feat/c509-cert
bkioshn Jun 25, 2024
e061532
fix(wip): handle extensions
bkioshn Jun 26, 2024
755c7af
fix: disable extensions encode and decode
bkioshn Jun 26, 2024
95c8db6
fix: cargo toml and add num-derive
bkioshn Jun 27, 2024
27d54e4
fix(wip): refactor tables
bkioshn Jun 27, 2024
d3a8473
feat(wip): add encode decode general name
bkioshn Jun 27, 2024
1c41054
fix: name and type
bkioshn Jun 27, 2024
285ef15
fix(wip): decode and encode generalnames
bkioshn Jun 27, 2024
c9234b1
fix(wip): gn value encode decode
bkioshn Jun 27, 2024
23e60a7
fix: remove unused crate
bkioshn Jun 29, 2024
f69b188
fix: gns encode and decode
bkioshn Jun 29, 2024
090a2ac
fix: remove unused table
bkioshn Jun 29, 2024
1639683
fix: oid lifetime to static
bkioshn Jun 29, 2024
2412156
fix: create extensions mod
bkioshn Jun 29, 2024
97d7aff
fix: general name visibility
bkioshn Jun 30, 2024
3a500fa
feat: add alt name
bkioshn Jun 30, 2024
eb053d9
feat: add alternative name encode and decode
bkioshn Jun 30, 2024
81120b0
fix: minor fixes + cleanup
bkioshn Jun 30, 2024
043171f
chore: use super in test
bkioshn Jul 1, 2024
d62b57f
fix: remove unused ctx type C
bkioshn Jul 1, 2024
581eeec
fix(wip): extensions
bkioshn Jul 2, 2024
0d060d6
feat: add strum crate
bkioshn Jul 3, 2024
1332865
fix: tables
bkioshn Jul 3, 2024
77fb568
fix: extensions
bkioshn Jul 3, 2024
88b9060
fix: general name
bkioshn Jul 3, 2024
59f4737
fix: table
bkioshn Jul 3, 2024
094bef6
fix: alt name
bkioshn Jul 3, 2024
b5faf7c
fix: extensions
bkioshn Jul 3, 2024
520227a
Merge branch 'main' into feat/c509-cert
bkioshn Jul 3, 2024
04cc102
fix: refactor
bkioshn Jul 4, 2024
1ae27dc
feat(wip): add eid
bkioshn Jul 4, 2024
8063042
chore: spelling
bkioshn Jul 4, 2024
d5de46c
chore: spelling
bkioshn Jul 4, 2024
e79c6ea
chore: revert back to main
bkioshn Jul 4, 2024
9c12734
chore: restore file in main
bkioshn Jul 4, 2024
b875235
fix: update rust stdconfig and earthfile
bkioshn Jul 4, 2024
efab558
fix: earthfile
bkioshn Jul 4, 2024
e72f1dc
fix: earthfile
bkioshn Jul 4, 2024
5c2ad44
fix: earthfile
bkioshn Jul 4, 2024
3084934
fix: wrong earthfile
bkioshn Jul 4, 2024
573929c
fix: doc link
bkioshn Jul 4, 2024
660fd6b
Update catalyst-gateway-crates/c509-certificate/src/c509_extensions/m…
Mr-Leshiy Jul 4, 2024
c76e705
Update catalyst-gateway-crates/c509-certificate/src/c509_extensions/m…
Mr-Leshiy Jul 4, 2024
aabe2ab
bump cat-ci
Mr-Leshiy Jul 4, 2024
5817c25
bump deny.toml
Mr-Leshiy Jul 4, 2024
bfda52f
fix fmt
Mr-Leshiy Jul 4, 2024
df01198
fix machete
Mr-Leshiy Jul 4, 2024
093bae5
fix
Mr-Leshiy Jul 4, 2024
f45a151
fix: minor fix and update doc
bkioshn Jul 5, 2024
c59cd19
chore: code format
bkioshn Jul 5, 2024
d68f562
Merge branch 'main' into feat/c509-cert
bkioshn Jul 5, 2024
6b40c22
bump cat-ci
Mr-Leshiy Jul 5, 2024
3830062
update build
Mr-Leshiy Jul 5, 2024
eb87664
fix: doc
bkioshn Jul 5, 2024
608d5fc
test: new cliipy ci fix
bkioshn Jul 5, 2024
4b11a8b
test: new cliipy ci fix fix cargo toml
bkioshn Jul 5, 2024
4606bfe
fix: orphan module
bkioshn Jul 5, 2024
87747e3
fix: remove EID
bkioshn Jul 5, 2024
3349817
fix: comment out wasm pack build
bkioshn Jul 5, 2024
0ccab68
Merge branch 'main' into feat/c509-cert
bkioshn Jul 6, 2024
9b7ba31
feat: c509 name
bkioshn Jul 6, 2024
3de7e51
fix: refactor Name
bkioshn Jul 7, 2024
3476b0a
fix: add chaining
bkioshn Jul 7, 2024
03eefa4
Merge branch 'feat/c509-cert' into feat/c509-name
bkioshn Jul 7, 2024
0665f46
fix: linter
bkioshn Jul 7, 2024
88f4306
Merge branch 'feat/c509-cert' into feat/c509-name
bkioshn Jul 7, 2024
b77cf7d
fix: PR comment
bkioshn Jul 8, 2024
7817f8c
fix: move code section
bkioshn Jul 8, 2024
45d14ee
chore: fix name and comment
bkioshn Jul 8, 2024
ab586ee
fix: format
bkioshn Jul 8, 2024
07337f1
Merge branch 'feat/c509-cert' into feat/c509-name
bkioshn Jul 8, 2024
b405496
test: add zero extensions
bkioshn Jul 8, 2024
b8b2a2a
fix: format
bkioshn Jul 8, 2024
7359c80
fix: attributes
bkioshn Jul 8, 2024
69d2df9
fix: move files
bkioshn Jul 8, 2024
ff49f79
fix: linter
bkioshn Jul 8, 2024
9409cf2
fix: gn type naming
bkioshn Jul 8, 2024
0b3296d
chore: remove unused file
bkioshn Jul 9, 2024
2b069b2
test: add test case for multiples gn type
bkioshn Jul 9, 2024
a8ff97d
fix: dns gn decode special case
bkioshn Jul 9, 2024
bae088a
fix: format
bkioshn Jul 9, 2024
db23d96
fix: data tables
bkioshn Jul 9, 2024
6492464
fix: alt name test case
bkioshn Jul 9, 2024
325430a
fix: cspell
bkioshn Jul 9, 2024
06130fc
fix: table functions
bkioshn Jul 10, 2024
7385da5
Merge branch 'feat/c509-cert' into feat/c509-name
bkioshn Jul 10, 2024
ce4df1e
fix: name special case
bkioshn Jul 10, 2024
8fa35b4
fix: attribute data
bkioshn Jul 10, 2024
115ea48
chore: minor fix
bkioshn Jul 10, 2024
beede95
Merge branch 'main' into feat/c509-name
bkioshn Jul 10, 2024
cb3f379
fix: spelling and format
bkioshn Jul 10, 2024
25a51e2
fix: change DirectoryName type to Name
bkioshn Jul 10, 2024
4cb93af
Merge branch 'main' into feat/c509-name
stevenj Jul 10, 2024
37841c5
fix: naming
bkioshn Jul 11, 2024
14841d8
Merge branch 'main' into feat/c509-name
bkioshn Jul 11, 2024
33e5e9a
Merge branch 'main' into feat/c509-name
bkioshn Jul 12, 2024
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
1 change: 1 addition & 0 deletions catalyst-gateway-crates/c509-certificate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ bimap = "0.6.3"
once_cell = "1.19.0"
strum = "0.26.3"
strum_macros = "0.26.3"
regex = "1.10.5"

[package.metadata.cargo-machete]
ignored = ["strum"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
//! C509 Attribute
//!
//! ```cddl
//! Attribute = ( attributeType: int, attributeValue: text ) //
//! ( attributeType: ~oid, attributeValue: bytes ) //
//! ( attributeType: pen, attributeValue: bytes )
//! ```
//!
//! For more information about Attribute,
//! visit [C509 Certificate](https://datatracker.ietf.org/doc/draft-ietf-cose-cbor-encoded-cert/09/)

use asn1_rs::Oid;
use minicbor::{encode::Write, Decode, Decoder, Encode, Encoder};

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

/// A struct of C509 `Attribute`
#[derive(Debug, Clone, PartialEq)]
pub struct Attribute {
/// A registered OID of C509 `Attribute`.
registered_oid: C509oidRegistered,
/// A flag to indicate whether the value can have multiple value.
multi_value: bool,
/// A value of C509 `Attribute` can be a vector of text or bytes.
value: Vec<AttributeValue>,
}

impl Attribute {
/// Create a new instance of `Attribute`.
#[must_use]
pub fn new(oid: Oid<'static>) -> Self {
Self {
registered_oid: C509oidRegistered::new(oid, ATTRIBUTES_LOOKUP.get_int_to_oid_table()),
multi_value: false,
value: Vec::new(),
}
}

/// Add a value to `Attribute`.
pub fn add_value(&mut self, value: AttributeValue) {
self.value.push(value);
}

/// Get the registered OID of `Attribute`.
pub(crate) fn get_registered_oid(&self) -> &C509oidRegistered {
&self.registered_oid
}

/// Get the value of `Attribute`.
pub(crate) fn get_value(&self) -> &Vec<AttributeValue> {
&self.value
}

/// Set whether `Attribute` can be PEN encoded.
pub(crate) fn set_pen_supported(self) -> Self {
Self {
registered_oid: self.registered_oid.pen_encoded(),
multi_value: self.multi_value,
value: self.value,
}
}

/// Set whether `Attribute` can have multiple value.
pub(crate) fn set_multi_value(mut self) -> Self {
self.multi_value = true;
self
}
}

impl Encode<()> for Attribute {
fn encode<W: Write>(
&self, e: &mut Encoder<W>, ctx: &mut (),
) -> Result<(), minicbor::encode::Error<W::Error>> {
// Encode CBOR int if available
if let Some(&oid) = self
.registered_oid
.get_table()
.get_map()
.get_by_right(&self.registered_oid.get_c509_oid().get_oid())
{
e.i16(oid)?;
} else {
// Encode unwrapped CBOR OID or CBOR PEN
self.registered_oid.get_c509_oid().encode(e, ctx)?;
}

// Check if the attribute value is empty
if self.value.is_empty() {
return Err(minicbor::encode::Error::message("Attribute value is empty"));
}

// If multi-value attributes, encode it as array
if self.multi_value {
e.array(self.value.len() as u64)?;
}

// Encode each value in the attribute
for value in &self.value {
value.encode(e, ctx)?;
}

Ok(())
}
}

impl Decode<'_, ()> for Attribute {
fn decode(d: &mut Decoder<'_>, ctx: &mut ()) -> Result<Self, minicbor::decode::Error> {
// Handle CBOR int
let mut attr = if d.datatype()? == minicbor::data::Type::U8 {
let i = d.i16()?;
let oid = get_oid_from_int(i).map_err(minicbor::decode::Error::message)?;
Attribute::new(oid.clone())
} else {
// Handle unwrapped CBOR OID or CBOR PEN
let c509_oid: C509oid = d.decode()?;
Attribute::new(c509_oid.get_oid())
};

// Handle attribute value
if d.datatype()? == minicbor::data::Type::Array {
// When multi-value attribute
let len = d.array()?.ok_or_else(|| {
minicbor::decode::Error::message("Failed to get array length for attribute value")
})?;

if len == 0 {
return Err(minicbor::decode::Error::message("Attribute value is empty"));
}

for _ in 0..len {
attr.add_value(AttributeValue::decode(d, ctx)?);
}
attr = attr.set_multi_value();
} else {
let value = AttributeValue::decode(d, ctx)?;
attr.add_value(value);
}
Ok(attr)
}
}

// ------------------AttributeValue----------------------

/// An enum of possible value types for `Attribute`.
#[allow(clippy::module_name_repetitions)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum AttributeValue {
/// A text string.
Text(String),
/// A byte vector.
Bytes(Vec<u8>),
}

impl Encode<()> for AttributeValue {
fn encode<W: Write>(
&self, e: &mut Encoder<W>, _ctx: &mut (),
) -> Result<(), minicbor::encode::Error<W::Error>> {
match self {
AttributeValue::Text(text) => e.str(text)?,
AttributeValue::Bytes(bytes) => e.bytes(bytes)?,
};
Ok(())
}
}

impl Decode<'_, ()> for AttributeValue {
fn decode(d: &mut Decoder<'_>, _ctx: &mut ()) -> Result<Self, minicbor::decode::Error> {
match d.datatype()? {
minicbor::data::Type::String => Ok(AttributeValue::Text(d.str()?.to_string())),
minicbor::data::Type::Bytes => Ok(AttributeValue::Bytes(d.bytes()?.to_vec())),
_ => {
Err(minicbor::decode::Error::message(
"Invalid AttributeValue, value should be either String or Bytes",
))
},
}
}
}

// ------------------Test----------------------

#[cfg(test)]
mod test_attribute {
use asn1_rs::oid;

use super::*;

#[test]
fn encode_decode_attribute_int() {
let mut buffer = Vec::new();
let mut encoder = Encoder::new(&mut buffer);
let mut attribute = Attribute::new(oid!(1.2.840 .113549 .1 .9 .1));
attribute.add_value(AttributeValue::Text("example@example.com".to_string()));
attribute
.encode(&mut encoder, &mut ())
.expect("Failed to encode Attribute");
// Email Address example@example.com: 0x00736578616d706c65406578616d706c652e636f6d
assert_eq!(
hex::encode(buffer.clone()),
"00736578616d706c65406578616d706c652e636f6d"
);

let mut decoder = Decoder::new(&buffer);
let attribute_decoded =
Attribute::decode(&mut decoder, &mut ()).expect("Failed to decode Attribute");
assert_eq!(attribute_decoded, attribute);
}

#[test]
fn empty_attribute_value() {
let mut buffer = Vec::new();
let mut encoder = Encoder::new(&mut buffer);
let attribute = Attribute::new(oid!(1.2.840 .113549 .1 .9 .1));
attribute
.encode(&mut encoder, &mut ())
.expect_err("Failed to encode Attribute");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//! Attribute data provides a necessary information for encoding and decoding of C509
//! Attribute. See [C509 Certificate](https://datatracker.ietf.org/doc/draft-ietf-cose-cbor-encoded-cert/09/)
//! Section 9.3 C509 Attributes Registry for more information.

use anyhow::Error;
use asn1_rs::{oid, Oid};
use once_cell::sync::Lazy;

use crate::tables::IntegerToOidTable;

/// Type of `Attribute` data
/// Int | OID | Name
type AttributeDataTuple = (i16, Oid<'static>, &'static str);

/// `Attribute` data table
#[rustfmt::skip]
const ATTRIBUTE_DATA: [AttributeDataTuple; 30] = [
// Int | OID | Name
(0, oid!(1.2.840.113549.1.9.1), "Email Address"),
(1, oid!(2.5.4.3), "Common Name"),
(2, oid!(2.5.4.4), "Surname"),
(3, oid!(2.5.4.5), "Serial Number"),
(4, oid!(2.5.4.6), "Country"),
(5, oid!(2.5.4.7), "Locality"),
(6, oid!(2.5.4.8), "State or Province"),
(7, oid!(2.5.4.9), "Street Address"),
(8, oid!(2.5.4.10), "Organization"),
(9, oid!(2.5.4.11), "Organizational Unit"),
(10, oid!(2.5.4.12), "Title"),
(11, oid!(2.5.4.15), "Business Category"),
(12, oid!(2.5.4.17), "Postal Code"),
(13, oid!(2.5.4.42), "Given Name"),
(14, oid!(2.5.4.43), "Initials"),
(15, oid!(2.5.4.44), "Generation Qualifier"),
(16, oid!(2.5.4.46), "DN Qualifier"),
(17, oid!(2.5.4.65), "Pseudonym"),
(18, oid!(2.5.4.97), "Organization Identifier"),
(19, oid!(1.3.6.1.4.1.311.60.2.1.1), "Inc. Locality"),
(20, oid!(1.3.6.1.4.1.311.60.2.1.2), "Inc. State or Province"),
(21, oid!(1.3.6.1.4.1.311.60.2.1.3), "Inc. Country"),
(22, oid!(0.9.2342.19200300.100.1.25), "Domain Component"),
(23, oid!(2.5.4.16), "Postal Address"),
(24, oid!(2.5.4.41), "Name"),
(25, oid!(2.5.4.20), "Telephone Number"),
(26, oid!(2.5.4.54), "Directory Management Domain Name"),
(27, oid!(0.9.2342.19200300.100.1.1), "userid"),
(28, oid!(1.2.840.113549.1.9.2), "Unstructured Name"),
(29, oid!(1.2.840.113549.1.9.8), "Unstructured Address"),
];

/// A struct of data that contains lookup tables for `Attribute`.
pub(crate) struct AttributeData {
/// A table of integer to OID, provide a bidirectional lookup.
int_to_oid_table: IntegerToOidTable,
}

impl AttributeData {
/// Get the `IntegerToOidTable`.
pub(crate) fn get_int_to_oid_table(&self) -> &IntegerToOidTable {
&self.int_to_oid_table
}
}

/// Define static lookup for attributes table
static ATTRIBUTES_TABLES: Lazy<AttributeData> = Lazy::new(|| {
let mut int_to_oid_table = IntegerToOidTable::new();

for data in ATTRIBUTE_DATA {
int_to_oid_table.add(data.0, data.1);
}

AttributeData { int_to_oid_table }
});

/// Static reference to the `AttributeData` lookup table.
pub(crate) static ATTRIBUTES_LOOKUP: &Lazy<AttributeData> = &ATTRIBUTES_TABLES;
stevenj marked this conversation as resolved.
Show resolved Hide resolved

/// Get the OID from the int value.
pub(crate) fn get_oid_from_int(i: i16) -> Result<Oid<'static>, Error> {
ATTRIBUTES_TABLES
.get_int_to_oid_table()
.get_map()
.get_by_left(&i)
.ok_or(Error::msg(format!(
"OID int not found in the attribute registry table given {i}"
)))
.cloned()
}
Loading
Loading