Skip to content

Commit 21e723f

Browse files
committed
docs + cleanup
1 parent a94882a commit 21e723f

File tree

4 files changed

+25
-58
lines changed

4 files changed

+25
-58
lines changed

der/src/asn1.rs

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ pub use self::{
4242
},
4343
bit_string::{BitStringIter, BitStringRef},
4444
choice::Choice,
45-
//context_specific::{ContextSpecific, ContextSpecificRef},
4645
context_specific::{
4746
ContextSpecificExplicit, ContextSpecificExplicitRef, ContextSpecificImplicit,
4847
ContextSpecificImplicitRef,

der/src/asn1/any_custom_class.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Less strict Context-specific, Application or Private field.
2+
13
use crate::{
24
Class, Decode, DecodeValue, Encode, EncodeValue, Error, Header, Length, Reader, Tag, TagNumber,
35
Tagged, Writer,
@@ -56,7 +58,7 @@ where
5658
tag_number: TagNumber,
5759
reader: &mut R,
5860
) -> Result<Option<Self>, T::Error> {
59-
decode_peeking(reader, class, tag_number, |reader| {
61+
peek_decode_optional(reader, class, tag_number, |reader| {
6062
Self::decode_checked(class, tag_number, reader)
6163
})
6264
}
@@ -94,7 +96,7 @@ where
9496
tag_number: TagNumber,
9597
reader: &mut R,
9698
) -> Result<Option<Self>, T::Error> {
97-
decode_peeking::<_, _, T::Error, _>(reader, class, tag_number, |reader| {
99+
peek_decode_optional::<_, _, T::Error, _>(reader, class, tag_number, |reader| {
98100
Self::decode_checked(class, tag_number, reader)
99101
})
100102
}
@@ -201,7 +203,7 @@ impl<T> Tagged for AnyCustomClassImplicit<T> {
201203

202204
/// Attempt to decode a custom class-tagged field with the given
203205
/// helper callback.
204-
fn decode_peeking<'a, F, R: Reader<'a>, E, T>(
206+
fn peek_decode_optional<'a, F, R: Reader<'a>, E, T>(
205207
reader: &mut R,
206208
expected_class: Class,
207209
expected_number: TagNumber,
@@ -234,6 +236,8 @@ fn is_unskippable_tag(tag: Tag, expected_class: Class, expected_number: TagNumbe
234236
Class::Application => tag.number() > expected_number,
235237
Class::ContextSpecific => tag.number() > expected_number,
236238
Class::Private => tag.number() != expected_number,
239+
240+
// probably unreachable
237241
Class::Universal => tag.number() != expected_number,
238242
}
239243
}

der/src/asn1/custom_class.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Context-specific, Application or Private field.
2+
13
use super::any_custom_class::{
24
expected_tag_constructed, AnyCustomClassExplicit, AnyCustomClassImplicit,
35
};
@@ -9,20 +11,32 @@ use crate::{
911
};
1012
use core::cmp::Ordering;
1113

12-
/// Application, Context-specific or Private class field which wraps an owned inner value.
14+
/// Application, Context-specific or Private class field which wraps an owned inner value `T`.
1315
///
1416
/// This type decodes/encodes a field which is specific to a particular context
15-
/// and is identified by a [`TagNumber`].
17+
/// and is identified by a [`TagNumber`] in `TAG` generic parameter.
18+
///
19+
/// - Encodes: always with `TAG` and `CLASS` generic parameter, with inner tag and value.
20+
///
21+
/// - Decodes: only if `TAG` and `CLASS` generic parameter matches data.
22+
///
23+
/// Note that only 2 most significant bits of `CLASS` are used.
1624
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
1725
pub struct CustomClassExplicit<const TAG: u16, T, const CLASS: u8> {
1826
/// Value of the field.
1927
pub value: T,
2028
}
2129

22-
/// Application, Context-specific or Private class field which wraps an owned inner value.
30+
/// Application, Context-specific or Private class field which wraps an owned inner value `T`.
2331
///
2432
/// This type decodes/encodes a field which is specific to a particular context
25-
/// and is identified by a [`TagNumber`].
33+
/// and is identified by a [`TagNumber`] in `TAG` generic parameter.
34+
///
35+
/// - Encodes: always with `TAG` and `CLASS` generic parameter, with inner value only (implicit, without inner tag).
36+
///
37+
/// - Decodes: only if `TAG` and `CLASS` generic parameter matches data.
38+
///
39+
/// Note that only 2 most significant bits of `CLASS` are used.
2640
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
2741
pub struct CustomClassImplicit<const TAG: u16, T, const CLASS: u8> {
2842
/// Value of the field.

der/src/asn1/private.rs

-50
Original file line numberDiff line numberDiff line change
@@ -20,56 +20,6 @@ pub type PrivateExplicitRef<'a, const TAG: u16, T> =
2020
pub type PrivateImplicitRef<'a, const TAG: u16, T> =
2121
CustomClassImplicitRef<'a, TAG, T, CLASS_PRIVATE>;
2222

23-
// /// Private field reference.
24-
// ///
25-
// /// This type encodes a field which is whose meaning is specific to a given
26-
// /// enterprise and is identified by a [`TagNumber`].
27-
// #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
28-
// pub struct PrivateRef<'a, T> {
29-
// /// Private tag number sans the leading `0b11000000` class
30-
// /// identifier bit and `0b100000` constructed flag.
31-
// pub tag_number: TagNumber,
32-
33-
// /// Tag mode: `EXPLICIT` VS `IMPLICIT`.
34-
// pub tag_mode: TagMode,
35-
36-
// /// Value of the field.
37-
// pub value: &'a T,
38-
// }
39-
40-
// impl<'a, T> PrivateRef<'a, T> {
41-
// /// Convert to a [`Private`].
42-
// fn encoder(&self) -> Private<EncodeValueRef<'a, T>> {
43-
// Private {
44-
// tag_number: self.tag_number,
45-
// tag_mode: self.tag_mode,
46-
// value: EncodeValueRef(self.value),
47-
// }
48-
// }
49-
// }
50-
51-
// impl<'a, T> EncodeValue for PrivateRef<'a, T>
52-
// where
53-
// T: EncodeValue + Tagged,
54-
// {
55-
// fn value_len(&self) -> Result<Length, Error> {
56-
// self.encoder().value_len()
57-
// }
58-
59-
// fn encode_value(&self, writer: &mut impl Writer) -> Result<(), Error> {
60-
// self.encoder().encode_value(writer)
61-
// }
62-
// }
63-
64-
// impl<'a, T> Tagged for PrivateRef<'a, T>
65-
// where
66-
// T: Tagged,
67-
// {
68-
// fn tag(&self) -> Tag {
69-
// self.encoder().tag()
70-
// }
71-
// }
72-
7323
#[cfg(test)]
7424
#[allow(clippy::unwrap_used)]
7525
mod tests {

0 commit comments

Comments
 (0)