Make tests great again !
(Also use only one field for public/private key pem) Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -253,7 +253,7 @@ defmodule Eventos.Service.ActivityPub do
|
||||
preferred_username: data["preferredUsername"],
|
||||
follower_address: data["followers"],
|
||||
summary: data["summary"],
|
||||
public_key: data["publicKey"]["publicKeyPem"],
|
||||
keys: data["publicKey"]["publicKeyPem"],
|
||||
inbox_url: data["inbox"],
|
||||
outbox_url: data["outbox"],
|
||||
following_url: data["following"],
|
||||
|
||||
@@ -304,4 +304,31 @@ defmodule Eventos.Service.ActivityPub.Utils do
|
||||
}
|
||||
|> Map.merge(additional)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Converts PEM encoded keys to a public key representation
|
||||
"""
|
||||
def pem_to_public_key(pem) do
|
||||
[private_key_code] = :public_key.pem_decode(pem)
|
||||
private_key = :public_key.pem_entry_decode(private_key_code)
|
||||
{:RSAPrivateKey, _, modulus, exponent, _, _, _, _, _, _, _} = private_key
|
||||
{:RSAPublicKey, modulus, exponent}
|
||||
end
|
||||
|
||||
@doc """
|
||||
Converts PEM encoded keys to a private key representation
|
||||
"""
|
||||
def pem_to_private_key(pem) do
|
||||
[private_key_code] = :public_key.pem_decode(pem)
|
||||
:public_key.pem_entry_decode(private_key_code)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Converts PEM encoded keys to a PEM public key representation
|
||||
"""
|
||||
def pem_to_public_key_pem(pem) do
|
||||
public_key = pem_to_public_key(pem)
|
||||
public_key = :public_key.pem_entry_encode(:RSAPublicKey, public_key)
|
||||
:public_key.pem_encode([public_key])
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user