@@ -37,6 +37,9 @@ impl<'a> AnyRef<'a> {
3737 } ;
3838
3939 /// Create a new [`AnyRef`] from the provided [`Tag`] and DER bytes.
40+ ///
41+ /// # Errors
42+ /// Returns [`Error`] with [`ErrorKind::Length`] if `bytes` is too long.
4043 pub const fn new ( tag : Tag , bytes : & ' a [ u8 ] ) -> Result < Self , Error > {
4144 match BytesRef :: new ( bytes) {
4245 Ok ( value) => Ok ( Self { tag, value } ) ,
@@ -50,16 +53,21 @@ impl<'a> AnyRef<'a> {
5053 }
5154
5255 /// Get the raw value for this [`AnyRef`] type as a byte slice.
56+ #[ must_use]
5357 pub fn value ( self ) -> & ' a [ u8 ] {
5458 self . value . as_slice ( )
5559 }
5660
5761 /// Returns [`Tag`] and [`Length`] of self.
62+ #[ must_use]
5863 pub fn header ( & self ) -> Header {
5964 Header :: new ( self . tag , self . value . len ( ) )
6065 }
6166
6267 /// Attempt to decode this [`AnyRef`] type into the inner value.
68+ ///
69+ /// # Errors
70+ /// Returns `T::Error` if a decoding error occurred.
6371 pub fn decode_as < T > ( self ) -> Result < T , <T as DecodeValue < ' a > >:: Error >
6472 where
6573 T : Choice < ' a > + DecodeValue < ' a > ,
@@ -68,6 +76,9 @@ impl<'a> AnyRef<'a> {
6876 }
6977
7078 /// Attempt to decode this [`AnyRef`] type into the inner value.
79+ ///
80+ /// # Errors
81+ /// Returns `T::Error` if a decoding error occurred.
7182 pub fn decode_as_encoding < T > (
7283 self ,
7384 encoding : EncodingRules ,
@@ -86,12 +97,16 @@ impl<'a> AnyRef<'a> {
8697 }
8798
8899 /// Is this value an ASN.1 `NULL` value?
100+ #[ must_use]
89101 pub fn is_null ( self ) -> bool {
90102 self == Self :: NULL
91103 }
92104
93105 /// Attempt to decode this value an ASN.1 `SEQUENCE`, creating a new
94106 /// nested reader and calling the provided argument with it.
107+ ///
108+ /// # Errors
109+ /// Returns `E` in the event an error is returned from `F` or if a decoding error occurs.
95110 pub fn sequence < F , T , E > ( self , f : F ) -> Result < T , E >
96111 where
97112 F : FnOnce ( & mut SliceReader < ' a > ) -> Result < T , E > ,
@@ -192,22 +207,30 @@ mod allocating {
192207
193208 impl Any {
194209 /// Create a new [`Any`] from the provided [`Tag`] and DER bytes.
210+ ///
211+ /// # Errors
212+ /// If `bytes` is too long.
195213 pub fn new ( tag : Tag , bytes : impl Into < Box < [ u8 ] > > ) -> Result < Self , Error > {
196214 let value = BytesOwned :: new ( bytes) ?;
197215 Ok ( Self { tag, value } )
198216 }
199217
200218 /// Allow access to value
219+ #[ must_use]
201220 pub fn value ( & self ) -> & [ u8 ] {
202221 self . value . as_slice ( )
203222 }
204223
205224 /// Returns [`Tag`] and [`Length`] of self.
225+ #[ must_use]
206226 pub fn header ( & self ) -> Header {
207227 Header :: new ( self . tag , self . value . len ( ) )
208228 }
209229
210230 /// Attempt to decode this [`Any`] type into the inner value.
231+ ///
232+ /// # Errors
233+ /// Returns `T::Error` if a decoding error occurred.
211234 pub fn decode_as < ' a , T > ( & ' a self ) -> Result < T , <T as DecodeValue < ' a > >:: Error >
212235 where
213236 T : Choice < ' a > + DecodeValue < ' a > ,
@@ -216,6 +239,9 @@ mod allocating {
216239 }
217240
218241 /// Attempt to decode this [`Any`] type into the inner value with the given encoding rules.
242+ ///
243+ /// # Errors
244+ /// Returns `T::Error` if a decoding error occurred.
219245 pub fn decode_as_encoding < ' a , T > (
220246 & ' a self ,
221247 encoding : EncodingRules ,
@@ -227,6 +253,9 @@ mod allocating {
227253 }
228254
229255 /// Encode the provided type as an [`Any`] value.
256+ ///
257+ /// # Errors
258+ /// If an encoding error occurred.
230259 pub fn encode_from < T > ( msg : & T ) -> Result < Self , Error >
231260 where
232261 T : Tagged + EncodeValue ,
@@ -239,6 +268,9 @@ mod allocating {
239268
240269 /// Attempt to decode this value an ASN.1 `SEQUENCE`, creating a new
241270 /// nested reader and calling the provided argument with it.
271+ ///
272+ /// # Errors
273+ /// If a decoding error occurred.
242274 pub fn sequence < ' a , F , T , E > ( & ' a self , f : F ) -> Result < T , E >
243275 where
244276 F : FnOnce ( & mut SliceReader < ' a > ) -> Result < T , E > ,
@@ -248,6 +280,7 @@ mod allocating {
248280 }
249281
250282 /// [`Any`] representation of the ASN.1 `NULL` type.
283+ #[ must_use]
251284 pub fn null ( ) -> Self {
252285 Self {
253286 tag : Tag :: Null ,
@@ -256,6 +289,7 @@ mod allocating {
256289 }
257290
258291 /// Create a new [`AnyRef`] from the provided [`Any`] owned tag and bytes.
292+ #[ must_use]
259293 pub fn to_ref ( & self ) -> AnyRef < ' _ > {
260294 AnyRef {
261295 tag : self . tag ,
@@ -350,6 +384,7 @@ mod allocating {
350384
351385 impl Any {
352386 /// Is this value an ASN.1 `NULL` value?
387+ #[ must_use]
353388 pub fn is_null ( & self ) -> bool {
354389 self . owned_to_ref ( ) == AnyRef :: NULL
355390 }
0 commit comments