# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Keys do
end
def keys_from_pem(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
- public_key = {:RSAPublicKey, modulus, exponent}
- {:ok, private_key, public_key}
+ with [private_key_code] <- :public_key.pem_decode(pem),
+ private_key <- :public_key.pem_entry_decode(private_key_code),
+ {:RSAPrivateKey, _, modulus, exponent, _, _, _, _, _, _, _} <- private_key do
+ {:ok, private_key, {:RSAPublicKey, modulus, exponent}}
+ else
+ error -> {:error, error}
+ end
end
end