1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
import filtercascade
import hashlib
from pathlib import Path
def predictable_serial_gen(end):
counter = 0
while counter < end:
counter += 1
m = hashlib.sha256()
m.update(counter.to_bytes(4, byteorder="big"))
yield m.hexdigest()
def store(fc, path):
if path.exists():
path.unlink()
with open(path, "wb") as f:
fc.tofile(f)
large_set = set(predictable_serial_gen(100_000))
v2_sha256_with_salt = filtercascade.FilterCascade(
[], defaultHashAlg=filtercascade.fileformats.HashAlgorithm.SHA256, salt=b"nacl"
)
v2_sha256_with_salt.initialize(
include=[b"this", b"that"], exclude=large_set | set([b"other"])
)
store(v2_sha256_with_salt, Path("test_v2_sha256_salt_mlbf"))
v2_sha256 = filtercascade.FilterCascade(
[], defaultHashAlg=filtercascade.fileformats.HashAlgorithm.SHA256
)
v2_sha256.initialize(include=[b"this", b"that"], exclude=large_set | set([b"other"]))
store(v2_sha256, Path("test_v2_sha256_mlbf"))
v2_murmur = filtercascade.FilterCascade(
[], defaultHashAlg=filtercascade.fileformats.HashAlgorithm.MURMUR3
)
v2_murmur.initialize(include=[b"this", b"that"], exclude=large_set | set([b"other"]))
store(v2_murmur, Path("test_v2_murmur_mlbf"))
v2_murmur_inverted = filtercascade.FilterCascade(
[], defaultHashAlg=filtercascade.fileformats.HashAlgorithm.MURMUR3
)
v2_murmur_inverted.initialize(
include=large_set | set([b"this", b"that"]), exclude=[b"other"]
)
store(v2_murmur_inverted, Path("test_v2_murmur_inverted_mlbf"))
v2_sha256_inverted = filtercascade.FilterCascade(
[], defaultHashAlg=filtercascade.fileformats.HashAlgorithm.SHA256
)
v2_sha256_inverted.initialize(
include=large_set | set([b"this", b"that"]), exclude=[b"other"]
)
store(v2_sha256_inverted, Path("test_v2_sha256_inverted_mlbf"))
|