Skip to content

Commit cc8cb32

Browse files
committed
Use System.os_time, closes #41
1 parent b867348 commit cc8cb32

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

lib/plug/crypto.ex

+3-3
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ defmodule Plug.Crypto do
168168
* `:key_digest` - option passed to `Plug.Crypto.KeyGenerator`
169169
when generating the encryption and signing keys. Defaults to `:sha256`
170170
* `:signed_at` - set the timestamp of the token in seconds.
171-
Defaults to `System.system_time(:millisecond)`
171+
Defaults to `System.os_time(:millisecond)`
172172
* `:max_age` - the default maximum age of the token. Defaults to
173173
`86400` seconds (1 day) and it may be overridden on `verify/4`.
174174
@@ -196,7 +196,7 @@ defmodule Plug.Crypto do
196196
* `:key_digest` - option passed to `Plug.Crypto.KeyGenerator`
197197
when generating the encryption and signing keys. Defaults to `:sha256`
198198
* `:signed_at` - set the timestamp of the token in seconds.
199-
Defaults to `System.system_time(:millisecond)`
199+
Defaults to `System.os_time(:millisecond)`
200200
* `:max_age` - the default maximum age of the token. Defaults to
201201
`86400` seconds (1 day) and it may be overridden on `decrypt/4`.
202202
@@ -347,5 +347,5 @@ defmodule Plug.Crypto do
347347
defp expired?(_signed, max_age_secs) when max_age_secs <= 0, do: true
348348
defp expired?(signed, max_age_secs), do: signed + trunc(max_age_secs * 1000) < now_ms()
349349

350-
defp now_ms, do: System.system_time(:millisecond)
350+
defp now_ms, do: System.os_time(:millisecond)
351351
end

test/plug/crypto_test.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ defmodule Plug.CryptoTest do
192192

193193
test "supports signed_at in seconds" do
194194
seconds_in_day = 24 * 60 * 60
195-
day_ago_seconds = System.system_time(:second) - seconds_in_day
195+
day_ago_seconds = System.os_time(:second) - seconds_in_day
196196
token = encrypt(@key, "secret", 1, signed_at: day_ago_seconds)
197197
assert decrypt(@key, "secret", token, max_age: seconds_in_day + 1) == {:ok, 1}
198198

0 commit comments

Comments
 (0)