• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use der::{asn1::ObjectIdentifier, AnyRef, 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)]
15 pub struct OtherName<'a> {
16     pub type_id: ObjectIdentifier,
17 
18     #[asn1(context_specific = "0", tag_mode = "EXPLICIT")]
19     pub value: AnyRef<'a>,
20 }
21 
22 #[test]
23 #[cfg(test)]
test()24 fn test() {
25     use alloc::string::ToString;
26     use der::{Decode, Encode};
27     use hex_literal::hex;
28 
29     let input = hex!("3021060A2B060104018237140203A0130C1155706E5F323134393530313330406D696C");
30     let decoded = OtherName::from_der(&input).unwrap();
31 
32     let onval = decoded.value.utf8_string().unwrap();
33     assert_eq!(onval.to_string(), "Upn_214950130@mil");
34 
35     let encoded = decoded.to_vec().unwrap();
36     assert_eq!(&input[..], &encoded);
37 }
38