netdoc: Use Itertools::exactly_once in hsdesc parsing

This commit is contained in:
Nick Mathewson 2023-02-06 16:26:28 -05:00
parent 3d53a30c94
commit 68d2ccf5fe
2 changed files with 8 additions and 4 deletions

View File

@ -61,6 +61,7 @@ digest = "0.10.0"
educe = "0.4.6"
hex = "0.4"
humantime = "2"
itertools = "0.10.1"
once_cell = "1"
phf = { version = "0.11.1", features = ["macros"] }
rand = { version = "0.8", optional = true }

View File

@ -6,6 +6,7 @@ use crate::parse::{keyword::Keyword, parser::SectionRules};
use crate::types::misc::{UnvalidatedEdCert, B64};
use crate::{ParseErrorKind as EK, Result};
use itertools::Itertools as _;
use once_cell::sync::Lazy;
use smallvec::SmallVec;
use tor_hscrypto::pk::{IntroPtAuthKey, IntroPtEncKey};
@ -181,8 +182,9 @@ impl HsDescInner {
let tok = body
.slice(ONION_KEY)
.iter()
.find(|item| item.arg(0) == Some("ntor"))
.ok_or_else(|| EK::MissingToken.with_msg("No ntor onion key found."))?;
.filter(|item| item.arg(0) == Some("ntor"))
.exactly_one()
.map_err(|_| EK::MissingToken.with_msg("No unique ntor onion key found."))?;
tok.parse_arg::<B64>(1)?.into_array()?.into()
};
@ -236,8 +238,9 @@ impl HsDescInner {
let tok = body
.slice(ENC_KEY)
.iter()
.find(|item| item.arg(0) == Some("ntor"))
.ok_or_else(|| EK::MissingToken.with_msg("No ntor onion key found."))?;
.filter(|item| item.arg(0) == Some("ntor"))
.exactly_one()
.map_err(|_| EK::MissingToken.with_msg("No unique ntor onion key found."))?;
let key = curve25519::PublicKey::from(tok.parse_arg::<B64>(1)?.into_array()?);
key.into()
};