Disallow empty country code in negative reports

This commit is contained in:
Vecna 2024-02-21 15:34:29 -05:00
parent 28233ec8a5
commit cc86baa4b5
1 changed files with 6 additions and 2 deletions

View File

@ -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<NegativeReport, NegativeReportError> {
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() {