mirror of
https://seed.radicle.dev/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5.git
synced 2026-11-21 10:30:41 +08:00
node: Implement signature verification
Signed-off-by: Alexis Sellier <self@cloudhead.io>
This commit is contained in:
@@ -58,6 +58,14 @@ pub struct NodeAnnouncement {
|
||||
addresses: Vec<Address>,
|
||||
}
|
||||
|
||||
impl NodeAnnouncement {
|
||||
/// Verify a signature on this message.
|
||||
pub fn verify(&self, signature: &crypto::Signature) -> bool {
|
||||
let msg = serde_json::to_vec(self).unwrap();
|
||||
self.id.verify(signature, &msg).is_ok()
|
||||
}
|
||||
}
|
||||
|
||||
/// Message payload.
|
||||
/// These are the messages peers send to each other.
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
@@ -110,6 +118,16 @@ impl Message {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn node<S: crypto::Signer>(announcement: NodeAnnouncement, signer: S) -> Self {
|
||||
let msg = serde_json::to_vec(&announcement).unwrap();
|
||||
let signature = signer.sign(&msg);
|
||||
|
||||
Self::Node {
|
||||
signature,
|
||||
announcement,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn inventory<S, T, G>(ctx: &mut Context<S, T, G>) -> Result<Self, storage::Error>
|
||||
where
|
||||
T: storage::ReadStorage,
|
||||
|
||||
Reference in New Issue
Block a user