Commit 3d1f272a authored by Ian Jackson's avatar Ian Jackson
Browse files

tor-netdoc: Promote DirectorySignatureHashAlgo from poc as nasty macro

We want DirectorySignatureHashAlgo for prod's directory Signature
type.

However, for complex cfg gate and macro scoping reasons, we can't just
move the definition out of poc.  Hence this rather unpleasant
intermediate state.  This will go away, and become normal again, when
we can abolish poc's signatures and have poc use a prod signature
type.

Review with
  git show --color=always --color-moved-ws=allow-indentation-change --color-moved
parent 24b773c0
Loading
Loading
Loading
Loading
+2 −12
Original line number Diff line number Diff line
@@ -134,18 +134,8 @@ define_derive_deftly! {
    }
}

/// `directory-signature` hash algorithm argument
#[derive(Clone, Copy, Debug, Eq, PartialEq, strum::EnumString, Deftly)]
define_directory_signature_hash_algo! {
    #[derive_deftly(DirectorySignatureHashesAccu)]
#[non_exhaustive]
#[strum(serialize_all = "snake_case")]
pub enum DirectorySignatureHashAlgo {
    /// SHA-1
    #[deftly(hash_len = "20")]
    Sha1,
    /// SHA-256
    #[deftly(hash_len = "32")]
    Sha256,
}

/// Unsupported `vote-status` value
+29 −0
Original line number Diff line number Diff line
@@ -91,3 +91,32 @@ fn test_as_mut_compiles() {

    let _: &mut S<()> = S { t: () }.as_mut();
}

/// Define `DirectorySignatureHashAlgo`, for `directory-signature` items
///
/// This macro exists to avoid clone-and-hack between poc and prod code.
///
/// It is difficult for either of those modules to use the other's definition,
/// because they have different stability, different cfg gating,
/// and want to derive deftly differently.
///
/// tl;dr: defining this type in doc/netstatus.rs would mean
/// the poc derived structs would end up in the prod module;
/// defining it in poc puts it behind the `incomplete` feature gate.
//
// TODO DIRAUTH after poc abolished, turn back into a normal struct DirectorySignatureHashAlgo
macro_rules! define_directory_signature_hash_algo { { $( $attrs:tt )* } => {
    /// `directory-signature` hash algorithm argument
    #[derive(Clone, Copy, Debug, Eq, PartialEq, strum::EnumString, Deftly)]
    $($attrs)*
    #[non_exhaustive]
    #[strum(serialize_all = "snake_case")]
    pub enum DirectorySignatureHashAlgo {
        /// SHA-1
        #[deftly(hash_len = "20")]
        Sha1,
        /// SHA-256
        #[deftly(hash_len = "32")]
        Sha256,
    }
} }