mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-03 09:41:19 +00:00
1a4e35eb50
Address review comments Store Activitypub urls in database (fixes #808) Co-authored-by: Felix Ableitner <me@nutomic.com> Reviewed-on: https://yerbamate.ml/LemmyNet/lemmy/pulls/162 Co-Authored-By: nutomic <nutomic@noreply.yerbamate.ml> Co-Committed-By: nutomic <nutomic@noreply.yerbamate.ml>
26 lines
761 B
Rust
26 lines
761 B
Rust
use openssl::{pkey::PKey, rsa::Rsa};
|
|
use std::io::{Error, ErrorKind};
|
|
|
|
pub struct Keypair {
|
|
pub private_key: String,
|
|
pub public_key: String,
|
|
}
|
|
|
|
/// Generate the asymmetric keypair for ActivityPub HTTP signatures.
|
|
pub fn generate_actor_keypair() -> Result<Keypair, Error> {
|
|
let rsa = Rsa::generate(2048)?;
|
|
let pkey = PKey::from_rsa(rsa)?;
|
|
let public_key = pkey.public_key_to_pem()?;
|
|
let private_key = pkey.private_key_to_pem_pkcs8()?;
|
|
let key_to_string = |key| match String::from_utf8(key) {
|
|
Ok(s) => Ok(s),
|
|
Err(e) => Err(Error::new(
|
|
ErrorKind::Other,
|
|
format!("Failed converting key to string: {}", e),
|
|
)),
|
|
};
|
|
Ok(Keypair {
|
|
private_key: key_to_string(private_key)?,
|
|
public_key: key_to_string(public_key)?,
|
|
})
|
|
}
|