hsclient keys: Provide :none() and Default and .is_empty()

This commit is contained in:
Ian Jackson 2023-02-27 16:35:16 +00:00
parent 896ea10b7f
commit e3e66793c4
1 changed files with 22 additions and 1 deletions

View File

@ -25,7 +25,7 @@ use tor_hscrypto::pk::{HsClientDescEncSecretKey, HsClientIntroAuthSecretKey};
/// Conversely, `Clone`s of a `ClientSecretKeys` *can* share circuits.
//
// TODO HS some way to read these from files or something!
#[derive(Clone)]
#[derive(Clone, Default)]
pub struct HsClientSecretKeys {
/// The actual keys
///
@ -63,6 +63,27 @@ impl Hash for HsClientSecretKeys {
}
}
impl HsClientSecretKeys {
/// Create a new `HsClientSecretKeys`, for making unauthenticated connections
///
/// Creates a `HsClientSecretKeys` which has no actual keys,
/// so will make connections to hidden services
/// without any Tor-protocol-level client authentication.
pub fn none() -> Self {
Self::default()
}
/// Tests whether this `HsClientSecretKeys` actually contains any keys
pub fn is_empty(&self) -> bool {
// TODO derive this. For now, we deconstruct it to prove we check all the fields.
let ClientSecretKeyValues {
ks_hsc_desc_enc,
ks_hsc_intro_auth,
} = &*self.keys;
ks_hsc_desc_enc.is_none() && ks_hsc_intro_auth.is_none()
}
}
/// Client secret key values
///
/// Skip the whole builder pattern derivation, etc. - the types are just the same