reach_attestant/
macros.rs

1// SPDX-FileCopyrightText: 2025 eaon <eaon@posteo.net>
2// SPDX-License-Identifier: EUPL-1.2
3
4#[macro_export]
5#[doc(hidden)]
6macro_rules! _shared_keys_random_from_rng {
7    ($signing_keys:tt, $priv_type:tt, $pub_type:tt, $csprng:tt$(,)?) => {{
8        let unsigned_private_keys = $priv_type::random_from_rng($csprng);
9        let unsigned_public_keys = $pub_type::from(&unsigned_private_keys);
10
11        (
12            $signing_keys.sign(unsigned_private_keys, $csprng),
13            $signing_keys.sign(unsigned_public_keys, $csprng),
14        )
15    }};
16}
17
18#[doc(inline)]
19pub use _shared_keys_random_from_rng as shared_keys_random_from_rng;
20
21macro_rules! sign_and_store_shared_keys {
22    (
23        ($priv_keys:tt, $priv_name:tt, $priv_ext:tt),
24        ($pub_keys:tt, $pub_name:tt, $pub_ext:tt),
25        $profile_name:tt,
26    ) => {{
27        let private_keys_path = crate::storage::file_path($profile_name, None, $priv_ext, true)
28            .may_bail_with(
29                concat!("Couldn't determine path for shared ", $priv_name, " keys."),
30                true,
31            );
32        let public_keys_path = crate::storage::file_path($profile_name, None, $pub_ext, true)
33            .may_bail_with(
34                concat!("Couldn't determine path for shared ", $pub_name, " keys."),
35                true,
36            );
37
38        $priv_keys.store(&private_keys_path).may_bail_with(
39            concat!("Couldn't store shared ", $priv_name, " keys."),
40            true,
41        );
42        $pub_keys
43            .store(&public_keys_path)
44            .may_bail_with(concat!("Couldn't store shared ", $pub_name, " keys."), true);
45    }};
46}
47
48pub(crate) use sign_and_store_shared_keys;