summaryrefslogtreecommitdiffstats
path: root/third_party/rust/rust_cascade/test_data/make-sample-data.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /third_party/rust/rust_cascade/test_data/make-sample-data.py
parentInitial commit. (diff)
downloadfirefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz
firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/rust_cascade/test_data/make-sample-data.py')
-rw-r--r--third_party/rust/rust_cascade/test_data/make-sample-data.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/third_party/rust/rust_cascade/test_data/make-sample-data.py b/third_party/rust/rust_cascade/test_data/make-sample-data.py
new file mode 100644
index 0000000000..bbb73ec4e6
--- /dev/null
+++ b/third_party/rust/rust_cascade/test_data/make-sample-data.py
@@ -0,0 +1,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"))