Construct a signed key from a [`PeerEntry`].
(entry: &PeerEntry, node_key: &NodeKey)
| 127 | } |
| 128 | /// Construct a signed key from a [`PeerEntry`]. |
| 129 | pub fn from_entry(entry: &PeerEntry, node_key: &NodeKey) -> anyhow::Result<Self> { |
| 130 | if entry.id() != node_key.id() { |
| 131 | bail!("peer key must be signed by its own ID") |
| 132 | } |
| 133 | Ok(Self(format!( |
| 134 | // 11 digits of a timestamp gets us 1000+ years of padding for a consistent sort order. |
| 135 | "{:0>11}.{}", |
| 136 | entry.expiration, |
| 137 | entry.to_jws(node_key)? |
| 138 | ))) |
| 139 | } |
| 140 | /// Decode and verify key as a [`PeerEntry`]. |
| 141 | pub fn to_entry(&self) -> anyhow::Result<PeerEntry> { |
| 142 | let (expiration, jws) = self.split_expiration()?; |