Debian Codegraph @

ansible_collections/community/crypto/plugins/module_utils/_crypto/_objects.py

raw
1 # Copyright (c) 2019, Felix Fontein <[email protected]>
2 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
3 # SPDX-License-Identifier: GPL-3.0-or-later
4
5 # Note that this module util is **PRIVATE** to the collection. It can have breaking changes at any time.
6 # Do not use this from other collections or standalone plugins/modules!
7
8 from __future__ import annotations
9
10 from ansible_collections.community.crypto.plugins.module_utils._crypto._objects_data import (
11 OID_MAP,
12 )
13
14 OID_LOOKUP: dict[str, str] = {}
15 NORMALIZE_NAMES: dict[str, str] = {}
16 NORMALIZE_NAMES_SHORT: dict[str, str] = {}
17
18 for dotted, names in OID_MAP.items():
19 for name in names:
20 if name in NORMALIZE_NAMES and OID_LOOKUP[name] != dotted:
21 raise AssertionError( # pragma: no cover
22 f'Name collision during setup: "{name}" for OIDs {dotted} and {OID_LOOKUP[name]}'
23 )
24 NORMALIZE_NAMES[name] = names[0]
25 NORMALIZE_NAMES_SHORT[name] = names[-1]
26 OID_LOOKUP[name] = dotted
27 for alias, original in [("userID", "userId")]:
28 if alias in NORMALIZE_NAMES:
29 raise AssertionError( # pragma: no cover
30 f'Name collision during adding aliases: "{alias}" (alias for "{original}") is already mapped to OID {OID_LOOKUP[alias]}'
31 )
32 NORMALIZE_NAMES[alias] = original
33 NORMALIZE_NAMES_SHORT[alias] = NORMALIZE_NAMES_SHORT[original]
34 OID_LOOKUP[alias] = OID_LOOKUP[original]
35
36
37 __all__ = ("NORMALIZE_NAMES", "NORMALIZE_NAMES_SHORT", "OID_LOOKUP")