Sha256: 91789604474df8823f9c245d6ed850151a263c5c5083bf5962eb19b165863672

Contents?: true

Size: 1.1 KB

Versions: 10

Compression:

Stored size: 1.1 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/test_helper')

class UtilTest < Test::Unit::TestCase

  include SRP::Util

  # comparing to the hash created with python srp lib to make sure
  # we use the same constants and hash the same way.
  def test_sha256_of_prime
    n = BIG_PRIME_N
    nhex = '%x' % [n]
    assert_equal "494b6a801b379f37c9ee25d5db7cd70ffcfe53d01b7c9e4470eaca46bda24b39",
      sha256_hex(nhex)
  end

  def test_hashing
    x = sha256_str("testuser:password")
    assert_equal 'a5376a27a385bcd791d76cbd6484e1bde130129210e4647a4583e49f45de107f',
      x
  end

  def test_packing_hex_to_byte_string
    shex = "7686acb8"
    assert_equal [118, 134, 172, 184].pack('C*'), [shex].pack('H*')
  end

  def test_multiplier
    # >>> "%x" % pysrp.H(sha, N, g)
    assert_equal 'bf66c44a428916cad64aa7c679f3fd897ad4c375e9bbb4cbf2f5de241d618ef0',
      "%x" % multiplier
  end

  def test_hn_xor_hg
    # >>> binascii.hexlify (pysrp.HNxorg(hashlib.sha256, N, g))
    assert_equal '928ade491bc87bba9eb578701d44d30ed9080e60e542ba0d3b9c20ded9f592bf',
      hn_xor_hg.bytes.map{|b| "%02x" % b.ord}.join
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ruby-srp-0.2.1 test/util_test.rb
ruby-srp-0.2.0 test/util_test.rb
ruby-srp-0.1.7 test/util_test.rb
ruby-srp-0.1.6 test/util_test.rb
ruby-srp-0.1.5 test/util_test.rb
ruby-srp-0.1.4 test/util_test.rb
ruby-srp-0.1.3 test/util_test.rb
ruby-srp-0.1.2 test/util_test.rb
ruby-srp-0.1.1 test/util_test.rb
ruby-srp-0.1.0 test/util_test.rb