Add a generator of a SafeString.

This commit is contained in:
2023-07-07 16:58:00 +03:00
parent 2e3f3d3901
commit be508ec88a
2 changed files with 17 additions and 0 deletions
@@ -0,0 +1,15 @@
defmodule LinkShortener.Generators.SafeString do
@moduledoc """
This module provides a generator.
"""
@doc """
Generate a random string with the length.
The string can be used as part of a url.
"""
def generate(length) do
:crypto.strong_rand_bytes(length)
|> Base.url_encode64()
|> binary_part(0, length)
end
end