@@ -28,18 +28,16 @@ impl<T> ContextSpecific<T> {
2828 /// Attempt to decode an `EXPLICIT` ASN.1 `CONTEXT-SPECIFIC` field with the
2929 /// provided [`TagNumber`].
3030 ///
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:
3434 ///
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.
4135 /// - Returns `Ok(None)` if anything other than a [`ContextSpecific`] field
4236 /// 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.
4341 pub fn decode_explicit < ' a , R : Reader < ' a > > (
4442 reader : & mut R ,
4543 tag_number : TagNumber ,
@@ -59,6 +57,10 @@ impl<T> ContextSpecific<T> {
5957 /// This method otherwise behaves the same as `decode_explicit`,
6058 /// but should be used in cases where the particular fields are `IMPLICIT`
6159 /// 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.
6264 pub fn decode_implicit < ' a , R : Reader < ' a > > (
6365 reader : & mut R ,
6466 tag_number : TagNumber ,
@@ -111,12 +113,12 @@ where
111113 // Decode EXPLICIT header
112114 let header = Header :: decode ( reader) ?;
113115
116+ // encoding shall be constructed
117+ if !header. tag . is_constructed ( ) {
118+ return Err ( header. tag . non_canonical_error ( ) . into ( ) ) ;
119+ }
114120 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 {
120122 tag_number : number,
121123 tag_mode : TagMode :: default ( ) ,
122124 value : reader. read_nested ( header. length , |reader| {
0 commit comments