class AwsSRP::Hex

Hexadecimal number represntation.

Constants

ARITHMETIC_OPERATORS
DOUBLE_ZERO_PADDING_PATTERN
HEX_STRING_PATTERN

Attributes

str[R]

Public Class Methods

new(val) click to toggle source
# File lib/aws_srp/hex.rb, line 17
def initialize(val)
  @str, @int = if val.is_a?(Integer)
    [val.to_s(16), val]
  else
    validate_str!(val.to_s)
  end

  @str = @str.downcase
end
str(str) click to toggle source

Return a hex string (e.g. x9F)

# File lib/aws_srp/hex.rb, line 11
def self.str(str)
  [str].pack('H*')
end

Public Instance Methods

concat(other) click to toggle source
# File lib/aws_srp/hex.rb, line 49
def concat(other)
  to_s + other.to_s
end
int() click to toggle source
# File lib/aws_srp/hex.rb, line 27
def int
  @int ||= str.hex
end
Also aliased as: to_i
mod_exp(b, m) click to toggle source
# File lib/aws_srp/hex.rb, line 65
def mod_exp(b, m)
  self.class.new(_mod_exp(to_i, b.to_i, m.to_i))
end
padding() click to toggle source
# File lib/aws_srp/hex.rb, line 32
def padding
  if str.length.odd?
    '0'
  elsif str =~ DOUBLE_ZERO_PADDING_PATTERN
    '00'
  end
end
to_hs() click to toggle source

to hex string (e.g. x9F)

# File lib/aws_srp/hex.rb, line 45
def to_hs
  self.class.str(to_s)
end
to_i()
Alias for: int
to_s() click to toggle source
# File lib/aws_srp/hex.rb, line 40
def to_s
  "#{padding}#{str}"
end
zero?() click to toggle source
# File lib/aws_srp/hex.rb, line 61
def zero?
  to_i.zero?
end

Private Instance Methods

validate_str!(val) click to toggle source
# File lib/aws_srp/hex.rb, line 71
def validate_str!(val)
  return val if val =~ HEX_STRING_PATTERN

  raise ArgumentError, "'#{val}' must be a hex string"
end