diff --git a/lib/plug/crypto.ex b/lib/plug/crypto.ex index fa8770b..65e9d14 100644 --- a/lib/plug/crypto.ex +++ b/lib/plug/crypto.ex @@ -168,7 +168,7 @@ defmodule Plug.Crypto do * `:key_digest` - option passed to `Plug.Crypto.KeyGenerator` when generating the encryption and signing keys. Defaults to `:sha256` * `:signed_at` - set the timestamp of the token in seconds. - Defaults to `System.system_time(:millisecond)` + Defaults to `System.os_time(:millisecond)` * `:max_age` - the default maximum age of the token. Defaults to `86400` seconds (1 day) and it may be overridden on `verify/4`. @@ -196,7 +196,7 @@ defmodule Plug.Crypto do * `:key_digest` - option passed to `Plug.Crypto.KeyGenerator` when generating the encryption and signing keys. Defaults to `:sha256` * `:signed_at` - set the timestamp of the token in seconds. - Defaults to `System.system_time(:millisecond)` + Defaults to `System.os_time(:millisecond)` * `:max_age` - the default maximum age of the token. Defaults to `86400` seconds (1 day) and it may be overridden on `decrypt/4`. @@ -347,5 +347,5 @@ defmodule Plug.Crypto do defp expired?(_signed, max_age_secs) when max_age_secs <= 0, do: true defp expired?(signed, max_age_secs), do: signed + trunc(max_age_secs * 1000) < now_ms() - defp now_ms, do: System.system_time(:millisecond) + defp now_ms, do: System.os_time(:millisecond) end diff --git a/test/plug/crypto_test.exs b/test/plug/crypto_test.exs index 9f6a738..95d2bf5 100644 --- a/test/plug/crypto_test.exs +++ b/test/plug/crypto_test.exs @@ -192,7 +192,7 @@ defmodule Plug.CryptoTest do test "supports signed_at in seconds" do seconds_in_day = 24 * 60 * 60 - day_ago_seconds = System.system_time(:second) - seconds_in_day + day_ago_seconds = System.os_time(:second) - seconds_in_day token = encrypt(@key, "secret", 1, signed_at: day_ago_seconds) assert decrypt(@key, "secret", token, max_age: seconds_in_day + 1) == {:ok, 1}