From dc66a78e3712f1840de05507548f607c916b1c78 Mon Sep 17 00:00:00 2001 From: Brian Underwood Date: Fri, 22 May 2020 10:59:26 +0200 Subject: [PATCH] Don't double-encode in urlsafe_base64 I tried using this function and the results were longer than they should have been. This was because it was encoding to standard base64 and then re-encoding *that* to URL-safe base64. This change fixes that --- lib/secure_random.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/secure_random.ex b/lib/secure_random.ex index 62d4864..f7963ec 100644 --- a/lib/secure_random.ex +++ b/lib/secure_random.ex @@ -70,7 +70,7 @@ defmodule SecureRandom do """ def urlsafe_base64(n \\ @default_length) do - base64(n) + random_bytes(n) |> Base.url_encode64(case: :lower, padding: true) end