2023-03-06 01:17:34 +00:00
|
|
|
//! Struct which is used to federate actor key for HTTP signatures
|
|
|
|
|
2023-03-01 23:19:10 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use url::Url;
|
|
|
|
|
2023-03-02 14:18:06 +00:00
|
|
|
/// Public key of actors which is used for HTTP signatures.
|
|
|
|
///
|
|
|
|
/// This needs to be federated in the `public_key` field of all actors.
|
2023-03-01 23:19:10 +00:00
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct PublicKey {
|
2023-03-02 14:18:06 +00:00
|
|
|
/// Id of this private key.
|
|
|
|
pub id: String,
|
|
|
|
/// ID of the actor that this public key belongs to
|
|
|
|
pub owner: Url,
|
|
|
|
/// The actual public key in PEM format
|
2023-03-01 23:19:10 +00:00
|
|
|
pub public_key_pem: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PublicKey {
|
2023-03-02 14:18:06 +00:00
|
|
|
/// Create a new [PublicKey] struct for the `owner` with `public_key_pem`.
|
|
|
|
///
|
|
|
|
/// It uses an standard key id of `{actor_id}#main-key`
|
2023-03-16 01:11:48 +00:00
|
|
|
pub(crate) fn new(owner: Url, public_key_pem: String) -> Self {
|
2023-03-01 23:19:10 +00:00
|
|
|
let id = main_key_id(&owner);
|
|
|
|
PublicKey {
|
|
|
|
id,
|
|
|
|
owner,
|
|
|
|
public_key_pem,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn main_key_id(owner: &Url) -> String {
|
|
|
|
format!("{}#main-key", &owner)
|
|
|
|
}
|