コード例 #1
0
ファイル: test_rmd5.py プロジェクト: sota/pypy-old
def test_more():
    "Test cases without known digest result."

    cases = (
        "123",
        "1234",
        "12345",
        "123456",
        "1234567",
        "12345678",
        "123456789 123456789 123456789 ",
        "123456789 123456789 ",
        "123456789 123456789 1",
        "123456789 123456789 12",
        "123456789 123456789 123",
        "123456789 123456789 1234",
        "123456789 123456789 123456789 1",
        "123456789 123456789 123456789 12",
        "123456789 123456789 123456789 123",
        "123456789 123456789 123456789 1234",
        "123456789 123456789 123456789 12345",
        "123456789 123456789 123456789 123456",
        "123456789 123456789 123456789 1234567",
        "123456789 123456789 123456789 12345678",
    )

    for input in cases:
        d = rmd5.RMD5(input)
        assert d.hexdigest() == md5.md5(input).hexdigest()
        assert d.digest() == md5.md5(input).digest()
コード例 #2
0
ファイル: test_rmd5.py プロジェクト: sota/pypy-old
def test_updating_many_times():
    "Test with an increasingly growing message."

    d1 = rmd5.RMD5()
    d2 = md5.md5()
    for i in range(300):
        d1.update(chr(i & 0xFF))
        d2.update(chr(i & 0xFF))
        assert d1.digest() == d2.digest()
コード例 #3
0
ファイル: test_rmd5.py プロジェクト: sota/pypy-old
def test_random():
    import random, md5
    for i in range(20):
        input = ''.join([
            chr(random.randrange(256)) for i in range(random.randrange(1000))
        ])
        m1 = rmd5.RMD5()
        m1.update(input)
        m2 = md5.new()
        m2.update(input)
        assert m2.hexdigest() == m1.hexdigest()
コード例 #4
0
ファイル: rmd5.py プロジェクト: mssun/rpython-by-example
def rmd5_example():
    print "digest_size:", rmd5.digest_size

    d1 = rmd5.RMD5()  # or rmd5.new()
    d1.update("123")

    # Terminate and return digest in HEX form.
    print d1.hexdigest()

    # Terminate the message-digest computation and return digest.
    print d1.digest()

    d2 = rmd5.RMD5("123")  # or rmd5.new("123")

    #  Return a copy ('clone') of the md5 object. This can be used to
    #  efficiently compute the digests of strings that shared a common initial
    #  substring.
    d3 = d2.copy()

    print d3.hexdigest()
    print d3.digest()
コード例 #5
0
ファイル: test_rmd5.py プロジェクト: sota/pypy-old
def test_long():
    "Test cases with long messages (can take a while)."

    cases = (
        2**10 * 'a',
        2**10 * 'abcd',
        ##2**20*'a',  ## 1 MB, takes about 160 sec. on a 233 Mhz Pentium.
    )

    for input in cases:
        d = rmd5.RMD5(input)
        assert d.hexdigest() == md5.md5(input).hexdigest()
        assert d.digest() == md5.md5(input).digest()
コード例 #6
0
ファイル: test_rmd5.py プロジェクト: sota/pypy-old
def test_copy():
    "Test updating cloned objects."

    cases = (
        "123",
        "1234",
        "12345",
        "123456",
        "1234567",
        "12345678",
        "123456789 123456789 123456789 ",
        "123456789 123456789 ",
        "123456789 123456789 1",
        "123456789 123456789 12",
        "123456789 123456789 123",
        "123456789 123456789 1234",
        "123456789 123456789 123456789 1",
        "123456789 123456789 123456789 12",
        "123456789 123456789 123456789 123",
        "123456789 123456789 123456789 1234",
        "123456789 123456789 123456789 12345",
        "123456789 123456789 123456789 123456",
        "123456789 123456789 123456789 1234567",
        "123456789 123456789 123456789 12345678",
    )

    # Load both with same prefix.
    prefix1 = 2**10 * 'a'

    m1 = md5.md5()
    m1.update(prefix1)

    m2 = rmd5.RMD5()
    m2.update(prefix1)

    # Update and compare...
    for message in cases:
        m1c = m1.copy()
        m1c.update(message)
        d1 = m1c.hexdigest()

        m2c = m2.copy()
        m2c.update(message)
        d2 = m2c.hexdigest()

        assert d1 == d2
コード例 #7
0
ファイル: test_rmd5.py プロジェクト: sota/pypy-old
def test_cases():
    """
    Feed example strings into a md5 object and check the digest and
    hexdigest.
    """
    cases = (
        ("", "d41d8cd98f00b204e9800998ecf8427e"),
        ("a", "0cc175b9c0f1b6a831c399e269772661"),
        ("abc", "900150983cd24fb0d6963f7d28e17f72"),
        ("message digest", "f96b697d7cb7938d525a2f31aaf161d0"),
        ("abcdefghijklmnopqrstuvwxyz", "c3fcd3d76192e4007dfb496cca67e13b"),
        ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
         "d174ab98d277d9f5a5611c2c9f419d9f"),
        ("1234567890" * 8, "57edf4a22be3c955ac49da2e2107b67a"),
    )
    for input, expected in cases:
        d = rmd5.RMD5()
        d.update(input)
        assert d.hexdigest() == expected
        assert d.digest() == expected.decode('hex')
コード例 #8
0
 def create_id(self):
     d = rmd5.RMD5(str(time.time()))
     self.session_id = d.hexdigest()