1 use crate::settings::Settings;
2 use openssl::{pkey::PKey, rsa::Rsa};
3 use std::io::{Error, ErrorKind};
7 pub private_key: String,
8 pub public_key: String,
11 /// Generate the asymmetric keypair for ActivityPub HTTP signatures.
12 pub fn generate_actor_keypair() -> Result<Keypair, Error> {
13 let rsa = Rsa::generate(2048)?;
14 let pkey = PKey::from_rsa(rsa)?;
15 let public_key = pkey.public_key_to_pem()?;
16 let private_key = pkey.private_key_to_pem_pkcs8()?;
17 let key_to_string = |key| match String::from_utf8(key) {
19 Err(e) => Err(Error::new(
21 format!("Failed converting key to string: {}", e),
25 private_key: key_to_string(private_key)?,
26 public_key: key_to_string(public_key)?,
30 pub enum EndpointType {
38 /// Generates the ActivityPub ID for a given object type and ID.
39 pub fn make_apub_endpoint(endpoint_type: EndpointType, name: &str) -> Url {
40 let point = match endpoint_type {
41 EndpointType::Community => "c",
42 EndpointType::User => "u",
43 EndpointType::Post => "post",
44 EndpointType::Comment => "comment",
45 EndpointType::PrivateMessage => "private_message",
50 Settings::get().get_protocol_and_hostname(),