From cc86baa4b59f0cbbb0895c3da2d77d6ad4ffa9e3 Mon Sep 17 00:00:00 2001 From: Vecna Date: Wed, 21 Feb 2024 15:34:29 -0500 Subject: [PATCH] Disallow empty country code in negative reports --- src/negative_report.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/negative_report.rs b/src/negative_report.rs index 5e62d60..a9eac38 100644 --- a/src/negative_report.rs +++ b/src/negative_report.rs @@ -12,6 +12,7 @@ pub enum NegativeReportError { DateInFuture, FailedToDeserialize, // couldn't deserialize to SerializableNegativeReport InvalidCountryCode, + MissingCountryCode, } /// A report that the user was unable to connect to the bridge @@ -20,7 +21,7 @@ pub struct NegativeReport { pub fingerprint: [u8; 20], /// some way to prove knowledge of bridge bridge_pok: ProofOfBridgeKnowledge, - /// user's country code, may be an empty string + /// user's country code pub country: String, /// today's Julian date pub date: u32, @@ -116,7 +117,10 @@ pub struct SerializableNegativeReport { impl SerializableNegativeReport { pub fn to_report(self) -> Result { - if self.country != "" && !COUNTRY_CODES.contains(self.country.as_str()) { + if self.country == "" { + return Err(NegativeReportError::MissingCountryCode); + } + if !COUNTRY_CODES.contains(self.country.as_str()) { return Err(NegativeReportError::InvalidCountryCode); } if self.date > get_date().into() {