summaryrefslogtreecommitdiff
path: root/src/catlfish_compat.erl
blob: 183eb44048444bac3e14c7426b8c3566d6d463df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
-module(catlfish_compat).
-export([unpack_issuer/1, unpack_signature/1, poison_val/1]).
-include_lib("public_key/include/public_key.hrl").

unpack_issuer(Issuer) ->
    unpack_issuer(erlang:system_info(otp_release), Issuer).
unpack_signature(Signature) ->
    unpack_signature(erlang:system_info(otp_release), Signature).
poison_val(Value) ->
    poison_val(erlang:system_info(otp_release), Value).

%% @doc Dig out alg, params and key from issuer.
unpack_issuer("17", Issuer) ->
    #'SubjectPublicKeyInfo'{
       algorithm = #'AlgorithmIdentifier'{algorithm = Alg, parameters = Params},
       subjectPublicKey = {0, Key}} = Issuer,
    {Alg, Params, Key};
unpack_issuer("18", Issuer) ->
    #'SubjectPublicKeyInfo'{
       algorithm = #'AlgorithmIdentifier'{algorithm = Alg, parameters = Params},
       subjectPublicKey = Key} = Issuer,
    {Alg, Params, Key}.

%% @doc Unpack a #'Certificate'.signature, return the signature.
unpack_signature("17", Signature) ->
    {_, Sig} = Signature,
    Sig;
unpack_signature("18", Signature) ->
    Signature.

%% Use a list for R17 and a binary for newer versions.
poison_val("17", Val) ->
    Val;
poison_val("18", Val) ->
    list_to_binary(Val).