コード例 #1
0
def test_exceed_buffer():
    secret = b"X" * ((gfshare._BUFFER_SIZE * 2) + 1)

    split = gfshare.split(10, 10, secret)
    for x in split.values():
        assert len(x) == len(secret)

    assert gfshare.combine(split) == secret
コード例 #2
0
def test_smoketest():
    result = gfshare.combine({
        113: b'\xe5\xcd\xb7i>"',
        59: b'\x00\x06\xde\x1ej\x83',
        4: b'\x9f\x08~\x10|\xec',
        181: b'N\xd7\xba\xb8\xbe\xa3',
        7: b'\xa8\\\x06\xee0\xae',
        153: b'PW\xdb\x1e\xc3V',
        228: b'\x86/{\x89C!',
        159: b'\x9cV\xc7\x05\xba\xf0',
        53: b'\xdf@\x17\xd6m>',
        175: b'\x9d\xc3q\x13(\xae',
    })

    assert result == b"secret"
コード例 #3
0
 def recoverSecret(shares):
     """
 Receovers a secret from a dict {coeff: share}
 """
     return gfshare.combine(shares)
コード例 #4
0
def test_validate_value_sizes():
    with pytest.raises(TypeError) as exc:
        gfshare.combine({1: b'foo', 2: b'barbaz'})
    assert str(exc.value) == "shares values not all bytes of the same length"
コード例 #5
0
def test_validate_values():
    with pytest.raises(TypeError) as exc:
        gfshare.combine({1: 'foo', 2: b'bar'})

    assert str(exc.value) == \
        "shares values not comprised entirely of byte objects"
コード例 #6
0
def test_validate_keys():
    with pytest.raises(TypeError) as exc:
        gfshare.combine({0: b'foo', 1: b'bar'})

    assert str(exc.value) == \
        "shares dict keys not comprised entirely of positive numbers"
コード例 #7
0
def test_validate_single():
    with pytest.raises(ValueError) as exc:
        gfshare.combine({0: b'foo'})
    assert str(exc.value) == "size of shares must be > 1"
コード例 #8
0
def test_validate_empty():
    with pytest.raises(ValueError) as exc:
        gfshare.combine({})
    assert str(exc.value) == "size of shares must be > 1"
コード例 #9
0
def test_roundtrip():
    assert gfshare.combine(gfshare.split(10, 10, b"secret")) == b"secret"
コード例 #10
0
def test_breaks():
    shares = gfshare.split(10, 10, b"secret")
    shares.popitem()
    assert gfshare.combine(shares) != b"secret"
コード例 #11
0
 def decode(self, data):
     rec_data = map(lambda x: (int(x.split('<-->')[0]), x.split('<-->')[1]),
                    data)
     return gfshare.combine(rec_data)
コード例 #12
0
def test_embedded_null_byte():
    assert gfshare.combine(gfshare.split(10, 10, b"sec\x00ret")) == b"sec\x00ret"