Macro puffin::input_action

source ยท
macro_rules! input_action {
    (@internal [$($label:expr, $precomp:expr);+] $recipe:expr) => { ... };
    (@internal [$($precomps:tt)+] $other_name:literal = $other_precomp:expr => $($tail:tt)+) => { ... };
    (@internal [$($precomps:tt)+] $other_name:literal = $other_precomp:expr, $($tail:tt)+) => { ... };
    (@internal [$($precomps:tt)+] $other_precomp:expr => $($tail:tt)+) => { ... };
    (@internal [$($precomps:tt)+] $other_precomp:expr, $($tail:tt)+) => { ... };
    ($precomp_name:literal = $precomp:expr => $($tail:tt)+) => { ... };
    ($precomp_name:literal = $precomp:expr , $($tail:tt)+) => { ... };
    ($precomp:expr => $($tail:tt)+) => { ... };
    ($precomp:expr, $($tail:tt)+) => { ... };
    ($recipe:expr) => { ... };
}
Expand description

This macro defines the precomputation syntax to add precomputations to an input action step

Example of precomputation with TLS

โ“˜
input_action! {
    // Here we are precomputing a decryption of TLS extension and using it in the following term
    "decrypted_extensions" = term!{fn_decrypt_handshake_flight(
        ((server, 0)/MessageFlight),
        (@server_hello_transcript),
        (fn_get_server_key_share(((server, 0)[Some(TlsQueryMatcher::Handshake(Some(HandshakeType::ServerHello)))]))),
        fn_no_psk,
        fn_named_group_secp384r1,
        fn_true,
        fn_seq_0  // sequence 0
    )}
    =>
    // This term will be sent to the PUT by the input action
    term!{fn_append_transcript(
        (@server_hello_transcript),
        (
            // We can query our precomputation
            (!"decrypted_extensions", 0)[
                Some(TlsQueryMatcher::Handshake(Some(HandshakeType::EncryptedExtensions)))
            ] / Message
        )
    )}
};

The following syntaxes are accepted :

โ“˜

input_action!{term!{fn_msg()}};
input_action!{term!{fn_precomputation()} => term!{fn_msg()}};
input_action!{"this_is_a_label" = term!{fn_precomputation()} => term!{fn_msg()}};
input_action!{
    "this_is_a_label" = term!{fn_precomputation_1()} =>
        term!{fn_precomputation_2()} =>
            term!{fn_msg()}
};
// the latter is equivalent to
input_action!{
    "this_is_a_label" = term!{fn_precomputation_1()}, term!{fn_precomputation_2()} =>
        term!{fn_msg()}
};

All the previous examples respectively produce

โ“˜

InputAction {
    recipe: term!{fn_msg()},
    precomputations: vec![],
};
InputAction {
    recipe: term!{fn_msg()},
    precomputations: vec![Precomputation{label: "".into(), recipe: term!{fn_precomputation()}}],
};
InputAction {
    recipe: term!{fn_msg()},
    precomputations: vec![Precomputation{label: "this_is_a_label".into(), recipe:
term!{fn_precomputation()}}], };
InputAction {
    recipe: term!{fn_msg()},
    precomputations: vec![
        Precomputation{label: "this_is_a_label".into(), recipe: term!{fn_precomputation_1()}},
        Precomputation{label: "".into(), recipe: term!{fn_precomputation_2()}}
    ],
};