Skip to content

Commit 01c2430

Browse files
committed
x509-cert: document AsExtension trait
1 parent 26af13f commit 01c2430

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

x509-cert/src/ext.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,45 @@ pub type Extensions = alloc::vec::Vec<Extension>;
4646

4747
/// Trait to be implemented by extensions to allow them to be formatted as x509 v3 extensions by
4848
/// builder.
49+
///
50+
/// # Examples
51+
///
52+
/// ```
53+
/// use const_oid::{AssociatedOid, ObjectIdentifier};
54+
/// use x509_cert::{der::Sequence, ext, name};
55+
///
56+
/// /// This extension indicates the age of the captain at the time of signature
57+
/// #[derive(Clone, Debug, Eq, PartialEq, Sequence)]
58+
/// pub struct CaptainAge {
59+
/// pub age: u32,
60+
/// }
61+
///
62+
/// impl AssociatedOid for CaptainAge {
63+
/// # // https://datatracker.ietf.org/doc/html/rfc5612
64+
/// # // 32473 is the private OID reserved for documentation.
65+
/// const OID: ObjectIdentifier = ObjectIdentifier::new_unwrap("1.3.6.1.4.1.32473.1");
66+
/// }
67+
///
68+
/// impl ext::AsExtension for CaptainAge {
69+
/// fn critical(&self, _subject: &name::Name, _extensions: &[ext::Extension]) -> bool {
70+
/// false
71+
/// }
72+
/// }
73+
/// ```
4974
pub trait AsExtension: AssociatedOid + der::Encode {
5075
/// Should the extension be marked critical
76+
///
77+
/// This affects the behavior of a validator when using the generated certificate.
78+
/// See [RFC 5280 Section 4.2]:
79+
/// ```text
80+
/// A certificate-using system MUST reject the certificate if it encounters
81+
/// a critical extension it does not recognize or a critical extension
82+
/// that contains information that it cannot process. A non-critical
83+
/// extension MAY be ignored if it is not recognized, but MUST be
84+
/// processed if it is recognized.
85+
/// ```
86+
///
87+
/// [RFC 5280 Section 4.2]: https://www.rfc-editor.org/rfc/rfc5280#section-4.2
5188
fn critical(&self, subject: &crate::name::Name, extensions: &[Extension]) -> bool;
5289

5390
/// Returns the Extension with the content encoded.

0 commit comments

Comments
 (0)