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

Remove OpenStruct from CLI/Arguments parser #137

Open
Earlopain opened this issue Apr 2, 2024 · 0 comments
Open

Remove OpenStruct from CLI/Arguments parser #137

Earlopain opened this issue Apr 2, 2024 · 0 comments

Comments

@Earlopain
Copy link

Earlopain commented Apr 2, 2024

Ruby 3.4 will warn on usage of ostruct, 3.5 will raise. Also see https://bugs.ruby-lang.org/issues/20309, ruby/ruby#10428

Something like this should be a good substitute, however since there seem to be no tests for CLI behaviour I'm not confident enough to PR myself:

# arguments.rb

Options = Struct.new(
  :time,
  :counter,
  :mode,
  :digest,
  :secret,
)

def default_options
  Options.new time: true, counter: 0, mode: :time
end

def to_h
  { time: options!.time, counter: options!.counter, digest: options!.digest, secret: options!.secret! }
end

# cli.rb

if options.mode == :time
  ROTP::TOTP.new(options.secret, options.to_h).now
elsif options.mode == :hmac
  ROTP::HOTP.new(options.secret, options.to_h).at options.counter
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant