Beispiel #1
0
    def test5(self):
        "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)
        m1c = m1.copy()

        m2 = pymd5.new()
        m2.update(prefix1)
        m2c = m2.copy()

        # Update and compare...
        for i in xrange(len(cases)):
            message = cases[i][0]

            m1c.update(message)
            d1 = m1c.hexdigest()

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

            assert d1 == d2
Beispiel #2
0
    def test5(self):
        "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)
        m1c = m1.copy()

        m2 = pymd5.new()
        m2.update(prefix1)
        m2c = m2.copy()

        # Update and compare...
        for i in xrange(len(cases)):
            message = cases[i][0]

            m1c.update(message)
            d1 = m1c.hexdigest()

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

            assert d1 == d2
Beispiel #3
0
def compareImp(message):
    """Compare two MD5 implementations, C vs. pure Python module.

    For equal digests this returns None, otherwise it returns
    a tuple of both digests.
    """

    # Use Python's standard library MD5 compiled C module.
    m1 = md5.md5()
    m1.update(message)
    d1 = m1.digest()
    d1h = m1.hexdigest()

    # Use MD5 module in pure Python.
    m2 = pymd5.new()
    m2.update(message)
    d2 = m2.digest()
    d2h = m2.hexdigest()

    # Return None if equal or the different digests if not equal.
    if d1 == d2 and d1h == d2h:
        return
    else:
        return d1, d2
Beispiel #4
0
def compareImp(message):
    """Compare two MD5 implementations, C vs. pure Python module.

    For equal digests this returns None, otherwise it returns
    a tuple of both digests.
    """

    # Use Python's standard library MD5 compiled C module.    
    m1 = md5.md5()
    m1.update(message)
    d1 = m1.digest()
    d1h = m1.hexdigest()
    
    # Use MD5 module in pure Python.
    m2 = pymd5.new()
    m2.update(message)
    d2 = m2.digest()
    d2h = m2.hexdigest()

    # Return None if equal or the different digests if not equal.
    if d1 == d2 and d1h == d2h:
        return
    else:
        return d1, d2
Beispiel #5
0
def test_attributes():
    assert pymd5.digest_size == 16
    assert pymd5.new().digest_size == 16
    assert pymd5.new().digestsize == 16
    assert pymd5.new().block_size == 64
Beispiel #6
0
def test_attributes():
    assert pymd5.digest_size == 16
    assert pymd5.new().digest_size == 16
    assert pymd5.new().digestsize == 16
    assert pymd5.new().block_size == 64