x509_cert/ext/pkix/name/
other.rs

1use der::{asn1::ObjectIdentifier, Any, Sequence, ValueOrd};
2
3/// OtherName as defined in [RFC 5280 Section 4.2.1.6].
4///
5/// ```text
6/// OtherName ::= SEQUENCE {
7///     type-id    OBJECT IDENTIFIER,
8///     value      [0] EXPLICIT ANY DEFINED BY type-id
9/// }
10/// ```
11///
12/// [RFC 5280 Section 4.2.1.6]: https://datatracker.ietf.org/doc/html/rfc5280#section-4.2.1.6
13#[derive(Clone, Debug, Eq, PartialEq, Sequence, ValueOrd)]
14#[allow(missing_docs)]
15pub struct OtherName {
16    pub type_id: ObjectIdentifier,
17
18    #[asn1(context_specific = "0", tag_mode = "EXPLICIT")]
19    pub value: Any,
20}
21
22#[test]
23#[cfg(test)]
24#[allow(clippy::unwrap_used)]
25fn test() {
26    use alloc::string::ToString;
27    use der::{asn1::Utf8StringRef, Decode, Encode};
28    use hex_literal::hex;
29
30    let input = hex!("3021060A2B060104018237140203A0130C1155706E5F323134393530313330406D696C");
31    let decoded = OtherName::from_der(&input).unwrap();
32
33    let onval = Utf8StringRef::try_from(&decoded.value).unwrap();
34    assert_eq!(onval.to_string(), "Upn_214950130@mil");
35
36    let encoded = decoded.to_der().unwrap();
37    assert_eq!(&input[..], &encoded);
38}