File: print-marking.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 (36 lines) | stat: -rw-r--r-- 1,074 bytes parent folder | download | duplicates (4)
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
instructions = """
Print the contents of a marking from mongocryptd.

Usage:
python print-marking.py <base64 representation of marking>

Example:
python ./etc/print-marking.py ADgAAAAQYQABAAAABWtpABAAAAAEYWFhYWFhYWFhYWFhYWFhYQJ2AAwAAAA0NTctNTUtNTQ2MgAA
"""

import sys
import base64
import bson
from bson import BSON
from bson import json_util
from bson.codec_options import CodecOptions

if len(sys.argv) != 2:
    print(instructions)
    sys.exit(1)

marking = base64.b64decode(sys.argv[1])
codec_options = CodecOptions(uuid_representation=bson.binary.STANDARD)
json_options = json_util.JSONOptions(json_mode=json_util.JSONMode.CANONICAL, uuid_representation=bson.binary.STANDARD)

if marking[0] != 0:
    print("Invalid first byte: {}".format(marking[0]))

marking_bson = BSON(marking[1:]).decode(codec_options=codec_options)
print(json_util.dumps(marking_bson, indent=4, json_options=json_options))

if "a" in marking_bson:
    if marking_bson["a"] == 1:
        print ("Algorithm is deterministic")
    elif marking_bson["a"] == 2:
        print ("Algorithm is random")