class CQR::OTP::Builder
Constants
- VALID_DIGITS
- VALID_PERIOD
- VALID_TYPES
Attributes
counter[RW]
digits[RW]
issuer[RW]
label[RW]
period[RW]
secret[RW]
type[RW]
Public Instance Methods
to_qr()
click to toggle source
# File lib/cqr/otp/builder.rb, line 12 def to_qr QRFormatter.new(url) end
to_s()
click to toggle source
# File lib/cqr/otp/builder.rb, line 16 def to_s url end
Private Instance Methods
build_counter()
click to toggle source
# File lib/cqr/otp/builder.rb, line 46 def build_counter raise CQRException.new("counter with non-hotp") if counter && type != "hotp" counter ? "&counter=#{counter}" : "" end
build_digits()
click to toggle source
# File lib/cqr/otp/builder.rb, line 27 def build_digits raise CQRException.new("wrong number of digits") unless VALID_DIGITS.member?(digits) digits ? "&digits=#{digits}" : "" end
build_issuer()
click to toggle source
# File lib/cqr/otp/builder.rb, line 42 def build_issuer issuer ? "&issuer=#{issuer}" : "" end
build_period()
click to toggle source
# File lib/cqr/otp/builder.rb, line 32 def build_period raise CQRException.new("wrong period") unless VALID_PERIOD.member?(period) abort "period wit hotp" if period && type == "hotp" period ? "&period=#{period}" : "" end
build_type()
click to toggle source
# File lib/cqr/otp/builder.rb, line 22 def build_type raise CQRException.new("unknown type") unless VALID_TYPES.member?(type) type end
url()
click to toggle source
# File lib/cqr/otp/builder.rb, line 51 def url "otpauth://#{build_type}/#{label}?secret=#{secret}#{build_digits}" + "#{build_period}#{build_counter}#{build_issuer}" end