Skip to content

Commit

Permalink
Adds the ability to configure the secret key size generated. Fixes #1847
Browse files Browse the repository at this point in the history
  • Loading branch information
jwoertink committed Mar 24, 2024
1 parent 3de0f33 commit c9ce741
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
14 changes: 11 additions & 3 deletions spec/tasks/gen/secret_key_base_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@ require "../../spec_helper"

describe Gen::SecretKey do
it "outputs a new secret key base" do
io = IO::Memory.new
task = Gen::SecretKey.new
task.output = IO::Memory.new
task.print_help_or_call(args: [] of String)

Gen::SecretKey.new.call(io)
(task.output.to_s.size >= 32).should be_true
end

it "outputs a larger size when configured" do
task = Gen::SecretKey.new
task.output = IO::Memory.new
task.print_help_or_call(args: ["-n 64"])

(io.to_s.size >= 32).should be_true
(task.output.to_s.size >= 64).should be_true
end
end
6 changes: 4 additions & 2 deletions tasks/gen/secret_key.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ require "lucky_task"
class Gen::SecretKey < LuckyTask::Task
summary "Generate a new secret key"

def call(io : IO = STDOUT)
io.puts Random::Secure.base64(32)
int32 :number, "n random bytes used to encode into base64.", shortcut: "-n", default: 32

def call
output.puts Random::Secure.base64(number)
end
end

0 comments on commit c9ce741

Please sign in to comment.