@@ -28,18 +28,16 @@ impl<T> ContextSpecific<T> {
28
28
/// Attempt to decode an `EXPLICIT` ASN.1 `CONTEXT-SPECIFIC` field with the
29
29
/// provided [`TagNumber`].
30
30
///
31
- /// This method has the following behavior which is designed to simplify
32
- /// handling of extension fields, which are denoted in an ASN.1 schema
33
- /// using the `...` ellipsis extension marker:
31
+ /// This method has the following behavior which decodes tag numbers one by one
32
+ /// in extension fields, which are denoted in an ASN.1 schema using
33
+ /// the `...` ellipsis extension marker:
34
34
///
35
- /// - Skips over [`ContextSpecific`] fields with a tag number lower than
36
- /// the current one, consuming and ignoring them.
37
- /// - Returns `Ok(None)` if a [`ContextSpecific`] field with a higher tag
38
- /// number is encountered. These fields are not consumed in this case,
39
- /// allowing a field with a lower tag number to be omitted, then the
40
- /// higher numbered field consumed as a follow-up.
41
35
/// - Returns `Ok(None)` if anything other than a [`ContextSpecific`] field
42
36
/// is encountered.
37
+ /// - Returns `Ok(None)` if a [`ContextSpecific`] field with a different tag
38
+ /// number is encountered. These fields are not consumed in this case.
39
+ /// - Returns `Err(ErrorKind::Noncanonical)` if constructed bit is primitive.
40
+ /// - Returns `Ok(Some(..))` if tag number matches.
43
41
pub fn decode_explicit < ' a , R : Reader < ' a > > (
44
42
reader : & mut R ,
45
43
tag_number : TagNumber ,
@@ -59,6 +57,10 @@ impl<T> ContextSpecific<T> {
59
57
/// This method otherwise behaves the same as `decode_explicit`,
60
58
/// but should be used in cases where the particular fields are `IMPLICIT`
61
59
/// as opposed to `EXPLICIT`.
60
+ ///
61
+ /// Differences from `EXPLICIT`:
62
+ /// - Returns `Err(ErrorKind::Noncanonical)` if constructed bit
63
+ /// does not match constructed bit of the base encoding.
62
64
pub fn decode_implicit < ' a , R : Reader < ' a > > (
63
65
reader : & mut R ,
64
66
tag_number : TagNumber ,
@@ -111,12 +113,12 @@ where
111
113
// Decode EXPLICIT header
112
114
let header = Header :: decode ( reader) ?;
113
115
116
+ // encoding shall be constructed
117
+ if !header. tag . is_constructed ( ) {
118
+ return Err ( header. tag . non_canonical_error ( ) . into ( ) ) ;
119
+ }
114
120
match header. tag {
115
- Tag :: ContextSpecific {
116
- number,
117
- // encoding shall be constructed
118
- constructed : true ,
119
- } => Ok ( Self {
121
+ Tag :: ContextSpecific { number, .. } => Ok ( Self {
120
122
tag_number : number,
121
123
tag_mode : TagMode :: default ( ) ,
122
124
value : reader. read_nested ( header. length , |reader| {
0 commit comments