Commit 558ae067 authored by Ian Jackson's avatar Ian Jackson 💬
Browse files

Merge branch 'self_digests_error_if_0' into 'main'

tor-dirclient: Require that self.digests is nonempty

See merge request !553
parents d707f621 04579c03
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -79,6 +79,10 @@ pub enum RequestError {
    /// believes in, we would reject as untimely.)
    #[error("Too much clock skew with directory cache")]
    TooMuchClockSkew,

    /// The requested SHA256 digest of microdescriptors is empty.
    #[error("The requested SHA256 digest of microdescriptors is empty")]
    MdSha256Empty,
}

impl From<TimeoutError> for RequestError {
@@ -155,6 +159,7 @@ impl HasKind for RequestError {
            E::HttpError(_) => EK::Internal,
            E::ContentEncoding(_) => EK::TorProtocolViolation,
            E::TooMuchClockSkew => EK::TorDirectoryError,
            E::MdSha256Empty => EK::Internal,
        }
    }
}
+6 −2
Original line number Diff line number Diff line
@@ -310,7 +310,9 @@ impl MicrodescRequest {

impl Requestable for MicrodescRequest {
    fn make_request(&self) -> Result<http::Request<()>> {
        // TODO: require that self.digests is nonempty.
        if self.digests.is_empty() {
            return Err(RequestError::MdSha256Empty);
        }
        let mut digests = self.digests.clone();
        digests.sort_unstable();

@@ -393,7 +395,9 @@ impl Requestable for RouterDescRequest {
            uri.push_str("all");
        } else {
            uri.push_str("d/");
            // TODO: require that self.digests is nonempty.
            if self.digests.is_empty() {
                return Err(RequestError::MdSha256Empty);
            }
            let mut digests = self.digests.clone();
            digests.sort_unstable();
            let ids: Vec<String> = digests.iter().map(hex::encode).collect();