tor-bytes: Use InternalError.
This crate's Error type is too low-level to have an ErrorKind, but it does make sense to use InternalError for the internal errors here.
This commit is contained in:
parent
8748a8b126
commit
7670a26d9c
|
@ -2885,6 +2885,7 @@ dependencies = [
|
|||
"hex-literal",
|
||||
"signature",
|
||||
"thiserror",
|
||||
"tor-error",
|
||||
"tor-llcrypto",
|
||||
]
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ repository = "https://gitlab.torproject.org/tpo/core/arti.git/"
|
|||
|
||||
[dependencies]
|
||||
tor-llcrypto = { path = "../tor-llcrypto", version = "0.0.3"}
|
||||
tor-error = { path="../tor-error", version = "0.0.1" }
|
||||
|
||||
arrayref = "0.3"
|
||||
bytes = "1"
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
use thiserror::Error;
|
||||
|
||||
/// Error type for decoding Tor objects from bytes.
|
||||
#[derive(Error, Debug, PartialEq, Eq, Clone)]
|
||||
#[derive(Error, Debug, Clone)]
|
||||
#[non_exhaustive]
|
||||
pub enum Error {
|
||||
/// Tried to read something, but we didn't find enough bytes.
|
||||
|
@ -25,5 +25,18 @@ pub enum Error {
|
|||
/// We use this one in lieu of calling assert() and expect() and
|
||||
/// unwrap() from within parsing code.
|
||||
#[error("internal programming error")]
|
||||
Internal,
|
||||
Internal(#[from] tor_error::InternalError),
|
||||
}
|
||||
|
||||
impl PartialEq for Error {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
use Error::*;
|
||||
match (self, other) {
|
||||
(Truncated, Truncated) => true,
|
||||
(ExtraneousBytes, ExtraneousBytes) => true,
|
||||
(BadMessage(a), BadMessage(b)) => a == b,
|
||||
// notably, this means that an internal error is equal to nothing, not even itself.
|
||||
(_, _) => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -240,7 +240,8 @@ mod rsa_impls {
|
|||
impl Readable for RsaIdentity {
|
||||
fn take_from(b: &mut Reader<'_>) -> Result<Self> {
|
||||
let m = b.take(RSA_ID_LEN)?;
|
||||
Ok(RsaIdentity::from_bytes(m).expect("take gave wrong length"))
|
||||
RsaIdentity::from_bytes(m)
|
||||
.ok_or_else(|| tor_error::internal!("wrong number of bytes from take").into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue