Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make 'timestamp' a positional argument #34

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cross_language_tests/challenge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
when "generate"
# write the private encryption key to the test directory to retrieve in later tests
key = OpenSSL::PKey::EC.new(test_case["RubyPrivateSigningKey"])
result = Krypto::Challenge.generate(key, test_case["ChallengeId"], test_case["ChallengeData"], test_case["RequestData"], timestamp: Time.now)
result = Krypto::Challenge.generate(key, test_case["ChallengeId"], test_case["ChallengeData"], test_case["RequestData"], Time.now)
File.write(private_encryption_key_path, Base64.strict_encode64(result[1]))

# return the challenge
Expand Down
2 changes: 1 addition & 1 deletion lib/krypto/challenge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

module Krypto
class Challenge
def self.generate(signing_key, challenge_id, challenge_data, request_data, timestamp: Time.now)
def self.generate(signing_key, challenge_id, challenge_data, request_data, timestamp = Time.now)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idiomatically, I'm thinking about this as having 4 required arguments, and then 1 optional timestamp. Potentially, in the future, there may be more optional arguments. Knowing that, do you want to move timestamp to positional?

Copy link
Author

@pelted pelted Aug 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Knowing that I would expect the method to look something like this

def self.generate(signing_key, challenge_id, challenge_data, request_data, **options)
   options = { timestamp: Time.now.utc.to_i }.merge(options)
   ...
end

or

def self.generate(signing_key:, challenge_id:, challenge_data:, request_data:, **options)
   options = { timestamp: Time.now.utc.to_i }.merge(options)
   ...
end

but I don't think this 2nd one is Ruby 1.9 compatible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we need ruby 1.9.

I think timestamp: Time.now gives us a better path to get to **options.

Thinking about it, I'm uncomfortable with optional positional arguments. I'd suggest moving to all named style, or leaving as is.

private_encryption_key = RbNaCl::PrivateKey.generate
public_encryption_key = private_encryption_key.public_key

Expand Down