File: fle2_generate_tests.py

package info (click to toggle)
libmongocrypt 1.17.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,572 kB
  • sloc: ansic: 70,067; python: 4,547; cpp: 615; sh: 460; makefile: 44; awk: 8
file content (25 lines) | stat: -rw-r--r-- 698 bytes parent folder | download | duplicates (2)
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
# fle2_generate_tests.py is used to generate the test file: ./test/data/roundtrip/fle2-generated.json
import json
import os
import fle2_crypto

# Generate test cases of various and plaintext (M) lengths.
M_lens = [1, 16, 64, 100]
out = []
for M_len in M_lens:
    M = os.urandom(M_len)
    IV = os.urandom(16)
    Ke = os.urandom(32)
    C = fle2_crypto.fle2_encrypt(M=M, Ke=Ke, IV=IV)

    out.append({
      'name': "generated test. M length={}".format (M_len),
      'origin': "etc/fle2_generate_tests.py",
      'algo': 'AES-256-CTR/NONE',
      'iv': IV.hex(),
      'key': Ke.hex(),
      'plaintext': M.hex(),
      'ciphertext': C.hex()
   })

print(json.JSONEncoder(indent=3).encode(out))