Exemplo n.º 1
0
def test_huge_split():
    max_ = gfshare._MAX_SHARECOUNT

    assert gfshare.split(max_, max_, b"secret")

    with pytest.raises(ValueError) as exc:
        gfshare.split(max_ + 1, max_ + 1, b"secret")
    assert str(exc.value) == "sharecount must be < {}".format(max_)
Exemplo n.º 2
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
Exemplo n.º 3
0
def test_smoketest():
    secret = b"secret"
    result = gfshare.split(10, 10, secret)

    assert len(result) == 10
    assert isinstance(result, dict)

    for k, v in result.items():
        assert isinstance(k, int)
        assert isinstance(v, bytes)
        assert len(v) == len(secret)
Exemplo n.º 4
0
    def splitSecret(bits=250, k=3, n=5):
        """
    Generate a new secret and split into shares
    """
        if k > n:
            raise ValueError(f"Quorum K cannot be larger than total number "
                             "of shares N. Instead found K={k} and N={n}")

        secret = Crypto.randomBytes(bits=bits, noNullBytes=True)
        print("secret=", secret)
        print(len(secret))
        return gfshare.split(k, n, secret)
Exemplo n.º 5
0
def test_allow_str():
    gfshare.split(10, 10, "str")
Exemplo n.º 6
0
def test_validate_sharecount_threshold():
    with pytest.raises(ValueError) as exc:
        gfshare.split(3, 2, b"secret")
    assert str(exc.value) == "sharecount must be >= threshold"
Exemplo n.º 7
0
def test_validate_sharecount():
    with pytest.raises(ValueError) as exc:
        gfshare.split(1, 1, b"secret")
    assert str(exc.value) == "sharecount must be >= 2"
Exemplo n.º 8
0
def test_validate_threshold():
    with pytest.raises(ValueError) as exc:
        gfshare.split(0, 10, b"secret")
    assert str(exc.value) == "threshold must be >= 1"
Exemplo n.º 9
0
def test_random_results():
    assert gfshare.split(10, 10, b"secret") != \
        gfshare.split(10, 10, b"secret")
Exemplo n.º 10
0
def test_roundtrip():
    assert gfshare.combine(gfshare.split(10, 10, b"secret")) == b"secret"
Exemplo n.º 11
0
def test_breaks():
    shares = gfshare.split(10, 10, b"secret")
    shares.popitem()
    assert gfshare.combine(shares) != b"secret"
Exemplo n.º 12
0
def test_validate_type():
    with pytest.raises(TypeError) as exc:
        gfshare.split(10, 10, "str")
    assert str(exc.value) == "a bytes-like object is required, not 'str'"
Exemplo n.º 13
0
 def encode(self, data):
     shares = gfshare.split(self.n_blocks, self.threshold, data)
     encoded = map(lambda (x, y): str(x) + "<-->" + y, shares)
     return encoded
Exemplo n.º 14
0
def test_embedded_null_byte():
    assert gfshare.combine(gfshare.split(10, 10, b"sec\x00ret")) == b"sec\x00ret"