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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
%%% Copyright (c) 2016, NORDUnet A/S.
%%% See LICENSE for licensing information.
-module(plop_compat).
-export([unpack_spki/1, timestamp/0, monotonic_time/1, start_timer/4, unique_integer/1, time_offset/1]).
-include_lib("public_key/include/public_key.hrl").
unpack_spki(SPKI) ->
unpack_spki(erlang:system_info(otp_release), SPKI).
timestamp() ->
timestamp(erlang:system_info(otp_release)).
monotonic_time(Unit) ->
monotonic_time(erlang:system_info(otp_release), Unit).
start_timer(Time, Dest, Msg, Options) ->
start_timer(erlang:system_info(otp_release), Time, Dest, Msg, Options).
unique_integer(Modifiers) ->
unique_integer(erlang:system_info(otp_release), Modifiers).
time_offset(Unit) ->
time_offset(erlang:system_info(otp_release), Unit).
unpack_spki("R16" ++ _, SPKI) ->
#'SubjectPublicKeyInfo'{subjectPublicKey = {_, Octets},
algorithm = Algorithm} = SPKI,
{Octets, Algorithm};
unpack_spki("17", SPKI) ->
#'SubjectPublicKeyInfo'{subjectPublicKey = {_, Octets},
algorithm = Algorithm} = SPKI,
{Octets, Algorithm};
unpack_spki("18", SPKI) ->
#'SubjectPublicKeyInfo'{subjectPublicKey = Octets,
algorithm = Algorithm} = SPKI,
{Octets, Algorithm};
unpack_spki("19", SPKI) ->
#'SubjectPublicKeyInfo'{subjectPublicKey = Octets,
algorithm = Algorithm} = SPKI,
{Octets, Algorithm}.
%% <=R17: now/0, >=R18 timestamp/0
timestamp("R16" ++ _) ->
erlang:now();
timestamp("17") ->
erlang:now();
timestamp("18") ->
erlang:timestamp();
timestamp("19") ->
erlang:timestamp().
monotonic_time("R16" ++ _, millisecond) ->
{MeS, S, MiS} = timestamp(),
(MeS * 1000000 + S) * 1000 + MiS div 1000;
monotonic_time("17", millisecond) ->
{MeS, S, MiS} = timestamp(),
(MeS * 1000000 + S) * 1000 + MiS div 1000;
monotonic_time("18", Unit) ->
erlang:monotonic_time(Unit);
monotonic_time("19", Unit) ->
erlang:monotonic_time(Unit).
unique_integer("R16", _Modifiers) ->
{MeS, S, MiS} = erlang:now(),
(MeS * 1000000 + S) * 1000000 + MiS;
unique_integer("17", _Modifiers) ->
{MeS, S, MiS} = erlang:now(),
(MeS * 1000000 + S) * 1000000 + MiS;
unique_integer("18", Modifiers) ->
erlang:unique_integer(Modifiers);
unique_integer("19", Modifiers) ->
erlang:unique_integer(Modifiers).
time_offset("R16", _Unit) ->
0;
time_offset("17", _Unit) ->
0;
time_offset("18", Unit) ->
erlang:time_offset(Unit);
time_offset("19", Unit) ->
erlang:time_offset(Unit).
start_timer("R16" ++ _, Time, Dest, Msg, [{abs, true}]) ->
erlang:start_timer(max(0, Time - monotonic_time(millisecond)), Dest, Msg);
start_timer("17", Time, Dest, Msg, [{abs, true}]) ->
erlang:start_timer(max(0, Time - monotonic_time(millisecond)), Dest, Msg);
start_timer("18", Time, Dest, Msg, Options) ->
erlang:start_timer(Time, Dest, Msg, Options);
start_timer("19", Time, Dest, Msg, Options) ->
erlang:start_timer(Time, Dest, Msg, Options).
|