Exemplo n.º 1
0
def test_TestSHA256Hex():
    h = skycoin.cipher_SHA256()
    _, b = skycoin.SKY_cipher_RandByte(32)
    skycoin.SKY_cipher_SHA256_Set(h, b)
    _, s = skycoin.SKY_cipher_SHA256_Hex(h)
    h2 = skycoin.cipher_SHA256()
    err = skycoin.SKY_cipher_SHA256FromHex(s, h2)
    assert err == skycoin.SKY_OK
    assert h == h2
    _, s2 = skycoin.SKY_cipher_SHA256_Hex(h2)
    assert s2 == s
Exemplo n.º 2
0
def test_TestSHA256KnownValue():
    vals = []
    values = struct_test()
    values.inputs = b"skycoin"
    values.outputs = b"5a42c0643bdb465d90bf673b99c14f5fa02db71513249d904573d2b8b63d353d"
    vals.append(values)
    values.inputs = b"hello world"
    values.outputs = b"b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9"
    vals.append(values)
    values.inputs = b"hello world asd awd awd awdapodawpokawpod "
    values.outputs = b"99d71f95cafe05ea2dddebc35b6083bd5af0e44850c9dc5139b4476c99950be4"

    for v in vals:
        b = v.inputs
        h = skycoin.cipher_SHA256()
        err = skycoin.SKY_cipher_SumSHA256(b, h)
        assert err == skycoin.SKY_OK
        _, h = skycoin.SKY_cipher_SHA256_Hex(h)
        assert h == v.outputs
Exemplo n.º 3
0
def test_TestSHA256FromHex():
    # Invalid hex hash
    h = skycoin.cipher_SHA256()
    err = skycoin.SKY_cipher_SHA256FromHex(b"cawcad", h)
    assert err == skycoin.SKY_ERROR

    # Truncated hex hash
    _, b = skycoin.SKY_cipher_RandByte(128)
    h = skycoin.cipher_SHA256()
    skycoin.SKY_cipher_SumSHA256(b, h)
    h_bytes = h.toStr()
    h1 = skycoin.cipher_SHA256()
    err = skycoin.SKY_cipher_SHA256FromHex(h_bytes[:int(len(h_bytes) / 2)], h1)
    assert err == skycoin.SKY_ERROR

    # Valid hex hash
    h2 = skycoin.cipher_SHA256()
    err, b = skycoin.SKY_cipher_SHA256_Hex(h)
    err = skycoin.SKY_cipher_SHA256FromHex(b, h2)
    assert h == h2
    assert err == skycoin.SKY_OK