|
22 | 22 | """ |
23 | 23 | Provides a DecisionPointGroup object for use in SSVC. |
24 | 24 | """ |
| 25 | +import secrets |
25 | 26 | from collections.abc import MutableMapping |
26 | 27 | from itertools import product |
27 | 28 |
|
@@ -86,6 +87,37 @@ def add(self, decision_point: DecisionPoint) -> None: |
86 | 87 | # set the decision point in the dictionary |
87 | 88 | self.decision_points[decision_point.id] = decision_point |
88 | 89 |
|
| 90 | + def obfuscate(self) -> tuple["DecisionPointGroup", dict[str, str]]: |
| 91 | + """ |
| 92 | + Returns a new DecisionPointGroup object, with the keys of the decision points dict obfuscated. |
| 93 | +
|
| 94 | + Returns: |
| 95 | + tuple: A tuple containing the new DecisionPointGroup and a dictionary mapping old keys to new obfuscated keys. |
| 96 | + """ |
| 97 | + token_len = 4 |
| 98 | + new_dict = {} |
| 99 | + translator = {} |
| 100 | + for old_key in self.decision_points.keys(): |
| 101 | + while True: |
| 102 | + new_key = secrets.token_hex(token_len) |
| 103 | + # make the new key match NNNN-NNNN... |
| 104 | + new_key = "-".join( |
| 105 | + new_key[i : i + token_len] |
| 106 | + for i in range(0, len(new_key), token_len) |
| 107 | + ) |
| 108 | + # uppercase the new key |
| 109 | + new_key = new_key.upper() |
| 110 | + if new_key not in translator: |
| 111 | + break |
| 112 | + # got a unique new_key |
| 113 | + translator[old_key] = new_key |
| 114 | + new_dict[new_key] = self.decision_points[old_key] |
| 115 | + |
| 116 | + new_group = self.copy(deep=True) |
| 117 | + new_group.decision_points = new_dict |
| 118 | + |
| 119 | + return (new_group, translator) |
| 120 | + |
89 | 121 | def combination_strings(self) -> list[tuple[str, ...]]: |
90 | 122 | """ |
91 | 123 | Generate all combinations of decision point values as strings. |
|
0 commit comments