/// A length descriptor in the packet didn't describe the later data correctly
/// (currently only generated in node_announcement)
BadLengthDescriptor,
+ /// Error from std::io
+ Io(::std::io::Error),
+ /// Invalid value found when decoding
+ InvalidValue,
}
pub trait MsgDecodable: Sized {
fn decode(v: &[u8]) -> Result<Self, DecodeError>;
DecodeError::ShortRead => "Packet extended beyond the provided bytes",
DecodeError::ExtraAddressesPerType => "More than one address of a single type",
DecodeError::BadLengthDescriptor => "A length descriptor in the packet didn't describe the later data correctly",
+ DecodeError::Io(ref e) => e.description(),
+ DecodeError::InvalidValue => "Invalid value in the bytes",
}
}
}
}
}
+impl From<::std::io::Error> for DecodeError {
+ fn from(e: ::std::io::Error) -> Self {
+ if e.kind() == ::std::io::ErrorKind::UnexpectedEof {
+ DecodeError::ShortRead
+ } else {
+ DecodeError::Io(e)
+ }
+ }
+}
+
macro_rules! secp_pubkey {
( $ctx: expr, $slice: expr ) => {
match PublicKey::from_slice($ctx, $slice) {