Add verify functions for NRs
This commit is contained in:
parent
98fe935d7a
commit
50ce57765d
|
@ -42,7 +42,7 @@ impl NegativeReport {
|
||||||
|
|
||||||
pub fn from_bridgeline(bridge_id: [u8; 20], bridgeline: BridgeLine, country: String) -> Self {
|
pub fn from_bridgeline(bridge_id: [u8; 20], bridgeline: BridgeLine, country: String) -> Self {
|
||||||
let bridge_pok =
|
let bridge_pok =
|
||||||
ProofOfBridgeKnowledge::HashOfBridgeLine(HashOfBridgeLine::new(bridgeline));
|
ProofOfBridgeKnowledge::HashOfBridgeLine(HashOfBridgeLine::new(&bridgeline));
|
||||||
NegativeReport::new(bridge_id, bridge_pok, country)
|
NegativeReport::new(bridge_id, bridge_pok, country)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,6 +80,28 @@ impl NegativeReport {
|
||||||
Err(_) => Err(NegativeReportError::FailedToDeserialize),
|
Err(_) => Err(NegativeReportError::FailedToDeserialize),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Verify report if proof of bridge knowledge is bridge line hash
|
||||||
|
pub fn verify_with_hash_of_bridge_line(self, bl: &BridgeLine) -> bool {
|
||||||
|
match self.bridge_pok {
|
||||||
|
ProofOfBridgeKnowledge::HashOfBridgeLine(pok) => {
|
||||||
|
let hash = HashOfBridgeLine::new(bl);
|
||||||
|
hash == pok
|
||||||
|
},
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Verify report if proof of bridge knowledge is bucket hash
|
||||||
|
pub fn verify_with_hash_of_bucket(self, bucket: &Scalar) -> bool {
|
||||||
|
match self.bridge_pok {
|
||||||
|
ProofOfBridgeKnowledge::HashOfBucket(pok) => {
|
||||||
|
let hash = HashOfBucket::new(bucket);
|
||||||
|
hash == pok
|
||||||
|
},
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// (De)serializable negative report object which must be consumed by the
|
/// (De)serializable negative report object which must be consumed by the
|
||||||
|
@ -125,7 +147,7 @@ pub struct HashOfBridgeLine {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HashOfBridgeLine {
|
impl HashOfBridgeLine {
|
||||||
pub fn new(bl: BridgeLine) -> Self {
|
pub fn new(bl: &BridgeLine) -> Self {
|
||||||
let mut hasher = Sha3_256::new();
|
let mut hasher = Sha3_256::new();
|
||||||
hasher.update(bincode::serialize(&bl).unwrap());
|
hasher.update(bincode::serialize(&bl).unwrap());
|
||||||
let hash: [u8; 32] = hasher.finalize().into();
|
let hash: [u8; 32] = hasher.finalize().into();
|
||||||
|
@ -140,7 +162,7 @@ pub struct HashOfBucket {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HashOfBucket {
|
impl HashOfBucket {
|
||||||
pub fn new(bucket: Scalar) -> Self {
|
pub fn new(bucket: &Scalar) -> Self {
|
||||||
let mut hasher = Sha3_256::new();
|
let mut hasher = Sha3_256::new();
|
||||||
hasher.update(bucket.to_bytes());
|
hasher.update(bucket.to_bytes());
|
||||||
let hash: [u8; 32] = hasher.finalize().into();
|
let hash: [u8; 32] = hasher.finalize().into();
|
||||||
|
|
Loading…
Reference in New Issue