Disallow empty country code in negative reports
This commit is contained in:
parent
28233ec8a5
commit
cc86baa4b5
|
@ -12,6 +12,7 @@ pub enum NegativeReportError {
|
||||||
DateInFuture,
|
DateInFuture,
|
||||||
FailedToDeserialize, // couldn't deserialize to SerializableNegativeReport
|
FailedToDeserialize, // couldn't deserialize to SerializableNegativeReport
|
||||||
InvalidCountryCode,
|
InvalidCountryCode,
|
||||||
|
MissingCountryCode,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A report that the user was unable to connect to the bridge
|
/// A report that the user was unable to connect to the bridge
|
||||||
|
@ -20,7 +21,7 @@ pub struct NegativeReport {
|
||||||
pub fingerprint: [u8; 20],
|
pub fingerprint: [u8; 20],
|
||||||
/// some way to prove knowledge of bridge
|
/// some way to prove knowledge of bridge
|
||||||
bridge_pok: ProofOfBridgeKnowledge,
|
bridge_pok: ProofOfBridgeKnowledge,
|
||||||
/// user's country code, may be an empty string
|
/// user's country code
|
||||||
pub country: String,
|
pub country: String,
|
||||||
/// today's Julian date
|
/// today's Julian date
|
||||||
pub date: u32,
|
pub date: u32,
|
||||||
|
@ -116,7 +117,10 @@ pub struct SerializableNegativeReport {
|
||||||
|
|
||||||
impl SerializableNegativeReport {
|
impl SerializableNegativeReport {
|
||||||
pub fn to_report(self) -> Result<NegativeReport, NegativeReportError> {
|
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);
|
return Err(NegativeReportError::InvalidCountryCode);
|
||||||
}
|
}
|
||||||
if self.date > get_date().into() {
|
if self.date > get_date().into() {
|
||||||
|
|
Loading…
Reference in New Issue