Skip to content

Commit 5f911c5

Browse files
authored
Adds the ability to configure the secret key size generated. Fixes #1847 (#1856)
1 parent 74c1ede commit 5f911c5

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

spec/tasks/gen/secret_key_base_spec.cr

+11-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,18 @@ require "../../spec_helper"
22

33
describe Gen::SecretKey do
44
it "outputs a new secret key base" do
5-
io = IO::Memory.new
5+
task = Gen::SecretKey.new
6+
task.output = IO::Memory.new
7+
task.print_help_or_call(args: [] of String)
68

7-
Gen::SecretKey.new.call(io)
9+
(task.output.to_s.size >= 32).should be_true
10+
end
11+
12+
it "outputs a larger size when configured" do
13+
task = Gen::SecretKey.new
14+
task.output = IO::Memory.new
15+
task.print_help_or_call(args: ["-n 64"])
816

9-
(io.to_s.size >= 32).should be_true
17+
(task.output.to_s.size >= 64).should be_true
1018
end
1119
end

tasks/gen/secret_key.cr

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ require "lucky_task"
33
class Gen::SecretKey < LuckyTask::Task
44
summary "Generate a new secret key"
55

6-
def call(io : IO = STDOUT)
7-
io.puts Random::Secure.base64(32)
6+
int32 :number, "n random bytes used to encode into base64.", shortcut: "-n", default: 32
7+
8+
def call
9+
output.puts Random::Secure.base64(number)
810
end
911
end

0 commit comments

Comments
 (0)