asn1_cereal/err.rs
1//! Encoding and Decoding errors that this crate can produce.
2
3use std::io;
4
5#[derive(Debug)]
6/// Errors that can occur while decoding an ASN.1 element.
7pub enum DecodeError {
8 /// Generic IO Error.
9 IO(io::Error),
10 /// Child element(s) decoded to greater length than the parent's tag.
11 GreaterLen,
12 /// Child element(s) decoded to smaller length than the parent's tag.
13 SmallerLen,
14 /// Primitive value encoded with an indefinite length.
15 PrimIndef,
16 /// Decoded tag does not match the expected tag for this type.
17 TagTypeMismatch,
18 /// An explicit tag appeared where an Implicit tag was expected.
19 ExplicitTag,
20 /// Indefinite length encoding appeared when definite length encoding was
21 /// expected.
22 IndefiniteLen,
23 /// Indefinite length encoding was started, but no terminator was found
24 /// at the end.
25 IndefiniteLenEnd,
26 /// Custom decoding error.
27 Custom(&'static str),
28}
29
30impl From<io::Error> for DecodeError {
31 fn from(err: io::Error) -> Self {
32 DecodeError::IO(err)
33 }
34}
35
36#[derive(Debug)]
37/// Errors that can occur while encoding an ASN.1 element.
38pub enum EncodeError {
39 /// Generic IO Error.
40 IO(io::Error),
41}
42
43impl From<io::Error> for EncodeError {
44 fn from(err: io::Error) -> Self {
45 EncodeError::IO(err)
46 }
47}