Merge branch 'hsdesc-accessors' into 'main'
netdoc: Use derive amplify::Getters for HsDesc accessors. Closes #909 See merge request tpo/core/arti!1266
This commit is contained in:
commit
1e5004eba7
|
@ -49,6 +49,47 @@ dependencies = [
|
|||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "amplify"
|
||||
version = "4.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f26966af46e0d200e8bf2b7f16230997c1c3f2d141bc27ccc091c012ed527b58"
|
||||
dependencies = [
|
||||
"amplify_derive",
|
||||
"amplify_num",
|
||||
"ascii",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "amplify_derive"
|
||||
version = "3.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c87df0f28e6eb1f2d355f29ba6793fa9ca643967528609608d5cbd70bd68f9d1"
|
||||
dependencies = [
|
||||
"amplify_syn",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "amplify_num"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ddce3bc63e807ea02065e8d8b702695f3d302ae4158baddff8b0ce5c73947251"
|
||||
|
||||
[[package]]
|
||||
name = "amplify_syn"
|
||||
version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7736fb8d473c0d83098b5bac44df6a561e20470375cd8bcae30516dc889fd62a"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "android-tzdata"
|
||||
version = "0.1.1"
|
||||
|
@ -288,6 +329,12 @@ dependencies = [
|
|||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ascii"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d92bec98840b8f03a5ff5413de5293bfcd8bf96467cf5452609f939ec6f5de16"
|
||||
|
||||
[[package]]
|
||||
name = "assert-impl"
|
||||
version = "0.1.3"
|
||||
|
@ -4587,6 +4634,7 @@ dependencies = [
|
|||
name = "tor-netdoc"
|
||||
version = "0.8.0"
|
||||
dependencies = [
|
||||
"amplify",
|
||||
"base64ct",
|
||||
"bitflags 2.3.1",
|
||||
"cipher",
|
||||
|
|
|
@ -78,6 +78,7 @@ dangerous-expose-struct-fields = ["visible", "visibility", "__is_experimental"]
|
|||
__is_experimental = []
|
||||
|
||||
[dependencies]
|
||||
amplify = { version = "4", default-features = false, features = ["derive"] }
|
||||
base64ct = { version = "1.5.1", features = ["alloc"] }
|
||||
bitflags = "2"
|
||||
cipher = { version = "0.4.1", features = ["zeroize"] }
|
||||
|
|
|
@ -130,7 +130,7 @@ pub enum IntroAuthType {
|
|||
|
||||
/// Information in an onion service descriptor about a single
|
||||
/// introduction point.
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, amplify::Getters)]
|
||||
pub struct IntroPointDesc {
|
||||
/// The list of link specifiers needed to extend a circuit to the introduction point.
|
||||
///
|
||||
|
@ -138,6 +138,7 @@ pub struct IntroPointDesc {
|
|||
//
|
||||
// TODO hs: perhaps we should make certain link specifiers mandatory? That
|
||||
// would make it possible for IntroPointDesc to implement CircTarget.
|
||||
#[getter(skip)]
|
||||
link_specifiers: Vec<EncodedLinkSpec>,
|
||||
|
||||
/// The key to be used to extend a circuit _to the introduction point_, using the
|
||||
|
@ -167,7 +168,7 @@ pub struct EncryptedHsDesc {
|
|||
pub type UncheckedEncryptedHsDesc = signed::SignatureGated<timed::TimerangeBound<EncryptedHsDesc>>;
|
||||
|
||||
impl StoredHsDescMeta {
|
||||
// TODO hs: needs accessor functions too. (Let's not use public fields; we
|
||||
// TODO relay: needs accessor functions too. (Let's not use public fields; we
|
||||
// are likely to want to mess with the repr of these types.)
|
||||
|
||||
/// Parse the outermost layer of the descriptor in `input`, and return the
|
||||
|
@ -181,9 +182,6 @@ impl StoredHsDescMeta {
|
|||
}
|
||||
|
||||
impl HsDesc {
|
||||
// TODO hs: needs accessor functions too. (Let's not use public fields; we
|
||||
// are likely to want to mess with the repr of these types.)
|
||||
|
||||
/// Parse the outermost document of the descriptor in `input`, and validate
|
||||
/// that its identity is consistent with `blinded_onion_id`.
|
||||
///
|
||||
|
@ -298,21 +296,11 @@ impl HsDesc {
|
|||
/// One or more introduction points used to contact the onion service.
|
||||
///
|
||||
/// Accessor function.
|
||||
// TODO HS derive this accessor
|
||||
//
|
||||
// For this and others I considered the following crates:
|
||||
// TODO: We'd like to derive this, but amplify::Getters would give us &Vec<>,
|
||||
// not &[].
|
||||
//
|
||||
// * amplify_derive, derive-getters, accessors-rs:
|
||||
// No way to deref the Vec to [], which I think is desirable
|
||||
// (after all, eventually these might become Box<[]>.
|
||||
//
|
||||
// * getset: Always generates methods called `get_` which isn't what we want.
|
||||
// * tia: Same problem. Also strange API.
|
||||
// * field_accessor: Works with Strings.
|
||||
// * accessors: Always uses `get` prefix, underdocumented.
|
||||
// * structural: Seems to be something much more reflection-y.
|
||||
//
|
||||
// derive-adhoc would make short work of this problem.
|
||||
// Perhaps someday we can use derive_adhoc, or add as_ref() support?
|
||||
pub fn intro_points(&self) -> &[IntroPointDesc] {
|
||||
&self.intro_points
|
||||
}
|
||||
|
@ -324,41 +312,12 @@ impl IntroPointDesc {
|
|||
/// These can include public keys and network addresses.
|
||||
///
|
||||
/// Accessor function.
|
||||
// TODO HS derive this accessor (see above)
|
||||
//
|
||||
// TODO: It would be better to derive this too, but this accessor needs to
|
||||
// return a slice; Getters can only give us a &Vec<> in this case.
|
||||
pub fn link_specifiers(&self) -> &[EncodedLinkSpec] {
|
||||
&self.link_specifiers
|
||||
}
|
||||
|
||||
/// The key to be used to extend a circuit _to the introduction point_, using the
|
||||
/// ntor or ntor3 handshakes. (`KP_ntor`)
|
||||
///
|
||||
/// Accessor function.
|
||||
// TODO HS derive this accessor (see above)
|
||||
pub fn ipt_ntor_key(&self) -> &curve25519::PublicKey {
|
||||
&self.ipt_ntor_key
|
||||
}
|
||||
|
||||
/// The key to be used to identify the onion service at this introduction point.
|
||||
/// (`KP_hs_ipt_sid`)
|
||||
///
|
||||
/// Accessor function.
|
||||
// TODO HS derive this accessor (see above)
|
||||
pub fn ipt_sid_key(&self) -> &HsIntroPtSessionIdKey {
|
||||
&self.ipt_sid_key
|
||||
}
|
||||
|
||||
/// `KP_hss_ntor`, the key used to encrypt a handshake _to the onion
|
||||
/// service_ when using this introduction point.
|
||||
///
|
||||
/// The onion service uses a separate key of this type with each
|
||||
/// introduction point as part of its strategy for preventing replay
|
||||
/// attacks.
|
||||
///
|
||||
/// Accessor function.
|
||||
// TODO HS derive this accessor (see above)
|
||||
pub fn svc_ntor_key(&self) -> &HsSvcNtorKey {
|
||||
&self.svc_ntor_key
|
||||
}
|
||||
}
|
||||
|
||||
impl EncryptedHsDesc {
|
||||
|
|
Loading…
Reference in New Issue