exonware-xwsystem 0.0.1.411__py3-none-any.whl → 0.1.0.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- exonware/__init__.py +2 -1
- exonware/conf.py +2 -2
- exonware/xwsystem/__init__.py +115 -43
- exonware/xwsystem/base.py +30 -0
- exonware/xwsystem/caching/__init__.py +39 -13
- exonware/xwsystem/caching/base.py +24 -6
- exonware/xwsystem/caching/bloom_cache.py +2 -2
- exonware/xwsystem/caching/cache_manager.py +2 -1
- exonware/xwsystem/caching/conditional.py +2 -2
- exonware/xwsystem/caching/contracts.py +85 -139
- exonware/xwsystem/caching/decorators.py +6 -19
- exonware/xwsystem/caching/defs.py +2 -1
- exonware/xwsystem/caching/disk_cache.py +2 -1
- exonware/xwsystem/caching/distributed.py +2 -1
- exonware/xwsystem/caching/errors.py +2 -1
- exonware/xwsystem/caching/events.py +110 -27
- exonware/xwsystem/caching/eviction_strategies.py +2 -2
- exonware/xwsystem/caching/external_caching_python.py +701 -0
- exonware/xwsystem/caching/facade.py +253 -0
- exonware/xwsystem/caching/factory.py +300 -0
- exonware/xwsystem/caching/fluent.py +14 -12
- exonware/xwsystem/caching/integrity.py +21 -6
- exonware/xwsystem/caching/lfu_cache.py +2 -1
- exonware/xwsystem/caching/lfu_optimized.py +18 -6
- exonware/xwsystem/caching/lru_cache.py +7 -4
- exonware/xwsystem/caching/memory_bounded.py +2 -2
- exonware/xwsystem/caching/metrics_exporter.py +2 -2
- exonware/xwsystem/caching/observable_cache.py +2 -2
- exonware/xwsystem/caching/pluggable_cache.py +2 -2
- exonware/xwsystem/caching/rate_limiter.py +2 -2
- exonware/xwsystem/caching/read_through.py +2 -2
- exonware/xwsystem/caching/secure_cache.py +81 -28
- exonware/xwsystem/caching/serializable.py +9 -7
- exonware/xwsystem/caching/stats.py +2 -2
- exonware/xwsystem/caching/tagging.py +2 -2
- exonware/xwsystem/caching/ttl_cache.py +4 -3
- exonware/xwsystem/caching/two_tier_cache.py +6 -3
- exonware/xwsystem/caching/utils.py +30 -12
- exonware/xwsystem/caching/validation.py +2 -2
- exonware/xwsystem/caching/warming.py +6 -3
- exonware/xwsystem/caching/write_behind.py +15 -6
- exonware/xwsystem/config/__init__.py +11 -17
- exonware/xwsystem/config/base.py +5 -5
- exonware/xwsystem/config/contracts.py +93 -153
- exonware/xwsystem/config/defaults.py +3 -2
- exonware/xwsystem/config/defs.py +3 -2
- exonware/xwsystem/config/errors.py +2 -5
- exonware/xwsystem/config/logging.py +12 -8
- exonware/xwsystem/config/logging_setup.py +3 -2
- exonware/xwsystem/config/performance.py +73 -391
- exonware/xwsystem/config/performance_modes.py +9 -8
- exonware/xwsystem/config/version_manager.py +1 -0
- exonware/xwsystem/config.py +27 -0
- exonware/xwsystem/console/__init__.py +53 -0
- exonware/xwsystem/console/base.py +133 -0
- exonware/xwsystem/console/cli/__init__.py +61 -0
- exonware/xwsystem/{cli → console/cli}/args.py +27 -24
- exonware/xwsystem/{cli → console/cli}/base.py +18 -87
- exonware/xwsystem/{cli → console/cli}/colors.py +15 -13
- exonware/xwsystem/console/cli/console.py +98 -0
- exonware/xwsystem/{cli → console/cli}/contracts.py +51 -69
- exonware/xwsystem/console/cli/defs.py +87 -0
- exonware/xwsystem/console/cli/encoding.py +69 -0
- exonware/xwsystem/{cli → console/cli}/errors.py +8 -3
- exonware/xwsystem/console/cli/event_logger.py +166 -0
- exonware/xwsystem/{cli → console/cli}/progress.py +25 -21
- exonware/xwsystem/{cli → console/cli}/prompts.py +3 -2
- exonware/xwsystem/{cli → console/cli}/tables.py +27 -24
- exonware/xwsystem/console/contracts.py +113 -0
- exonware/xwsystem/console/defs.py +154 -0
- exonware/xwsystem/console/errors.py +34 -0
- exonware/xwsystem/console/event_logger.py +385 -0
- exonware/xwsystem/console/writer.py +132 -0
- exonware/xwsystem/contracts.py +28 -0
- exonware/xwsystem/data_structures/__init__.py +23 -0
- exonware/xwsystem/data_structures/trie.py +34 -0
- exonware/xwsystem/data_structures/union_find.py +144 -0
- exonware/xwsystem/defs.py +17 -0
- exonware/xwsystem/errors.py +23 -0
- exonware/xwsystem/facade.py +62 -0
- exonware/xwsystem/http_client/__init__.py +22 -1
- exonware/xwsystem/http_client/advanced_client.py +8 -5
- exonware/xwsystem/http_client/base.py +3 -2
- exonware/xwsystem/http_client/client.py +7 -4
- exonware/xwsystem/http_client/contracts.py +42 -56
- exonware/xwsystem/http_client/defs.py +2 -1
- exonware/xwsystem/http_client/errors.py +2 -1
- exonware/xwsystem/http_client/facade.py +156 -0
- exonware/xwsystem/io/__init__.py +22 -3
- exonware/xwsystem/io/archive/__init__.py +8 -2
- exonware/xwsystem/io/archive/archive.py +1 -1
- exonware/xwsystem/io/archive/archive_files.py +4 -7
- exonware/xwsystem/io/archive/archivers.py +120 -10
- exonware/xwsystem/io/archive/base.py +4 -5
- exonware/xwsystem/io/archive/codec_integration.py +1 -2
- exonware/xwsystem/io/archive/compression.py +1 -2
- exonware/xwsystem/io/archive/facade.py +263 -0
- exonware/xwsystem/io/archive/formats/__init__.py +2 -3
- exonware/xwsystem/io/archive/formats/brotli_format.py +20 -7
- exonware/xwsystem/io/archive/formats/lz4_format.py +20 -7
- exonware/xwsystem/io/archive/formats/rar.py +11 -5
- exonware/xwsystem/io/archive/formats/sevenzip.py +12 -6
- exonware/xwsystem/io/archive/formats/squashfs_format.py +1 -2
- exonware/xwsystem/io/archive/formats/tar.py +52 -7
- exonware/xwsystem/io/archive/formats/wim_format.py +11 -5
- exonware/xwsystem/io/archive/formats/zip.py +1 -2
- exonware/xwsystem/io/archive/formats/zpaq_format.py +1 -2
- exonware/xwsystem/io/archive/formats/zstandard.py +20 -7
- exonware/xwsystem/io/base.py +119 -115
- exonware/xwsystem/io/codec/__init__.py +4 -2
- exonware/xwsystem/io/codec/base.py +19 -13
- exonware/xwsystem/io/codec/contracts.py +59 -2
- exonware/xwsystem/io/codec/registry.py +67 -21
- exonware/xwsystem/io/common/__init__.py +1 -1
- exonware/xwsystem/io/common/atomic.py +29 -16
- exonware/xwsystem/io/common/base.py +11 -10
- exonware/xwsystem/io/common/lock.py +6 -5
- exonware/xwsystem/io/common/path_manager.py +2 -1
- exonware/xwsystem/io/common/watcher.py +1 -2
- exonware/xwsystem/io/contracts.py +301 -433
- exonware/xwsystem/io/contracts_1.py +1180 -0
- exonware/xwsystem/io/data_operations.py +279 -14
- exonware/xwsystem/io/defs.py +4 -3
- exonware/xwsystem/io/errors.py +3 -2
- exonware/xwsystem/io/facade.py +87 -61
- exonware/xwsystem/io/file/__init__.py +1 -1
- exonware/xwsystem/io/file/base.py +8 -9
- exonware/xwsystem/io/file/conversion.py +2 -3
- exonware/xwsystem/io/file/file.py +61 -18
- exonware/xwsystem/io/file/paged_source.py +8 -8
- exonware/xwsystem/io/file/paging/__init__.py +1 -2
- exonware/xwsystem/io/file/paging/byte_paging.py +4 -5
- exonware/xwsystem/io/file/paging/line_paging.py +2 -3
- exonware/xwsystem/io/file/paging/record_paging.py +2 -3
- exonware/xwsystem/io/file/paging/registry.py +1 -2
- exonware/xwsystem/io/file/source.py +13 -17
- exonware/xwsystem/io/filesystem/__init__.py +1 -1
- exonware/xwsystem/io/filesystem/base.py +1 -2
- exonware/xwsystem/io/filesystem/local.py +3 -4
- exonware/xwsystem/io/folder/__init__.py +1 -1
- exonware/xwsystem/io/folder/base.py +1 -2
- exonware/xwsystem/io/folder/folder.py +16 -7
- exonware/xwsystem/io/indexing/__init__.py +14 -0
- exonware/xwsystem/io/indexing/facade.py +443 -0
- exonware/xwsystem/io/path_parser.py +98 -0
- exonware/xwsystem/io/serialization/__init__.py +21 -3
- exonware/xwsystem/io/serialization/auto_serializer.py +146 -20
- exonware/xwsystem/io/serialization/base.py +84 -34
- exonware/xwsystem/io/serialization/contracts.py +50 -73
- exonware/xwsystem/io/serialization/defs.py +2 -1
- exonware/xwsystem/io/serialization/errors.py +2 -1
- exonware/xwsystem/io/serialization/flyweight.py +154 -7
- exonware/xwsystem/io/serialization/format_detector.py +15 -14
- exonware/xwsystem/io/serialization/formats/__init__.py +8 -5
- exonware/xwsystem/io/serialization/formats/binary/bson.py +15 -6
- exonware/xwsystem/io/serialization/formats/binary/cbor.py +5 -5
- exonware/xwsystem/io/serialization/formats/binary/marshal.py +5 -5
- exonware/xwsystem/io/serialization/formats/binary/msgpack.py +5 -5
- exonware/xwsystem/io/serialization/formats/binary/pickle.py +5 -5
- exonware/xwsystem/io/serialization/formats/binary/plistlib.py +5 -5
- exonware/xwsystem/io/serialization/formats/database/dbm.py +7 -7
- exonware/xwsystem/io/serialization/formats/database/shelve.py +7 -7
- exonware/xwsystem/io/serialization/formats/database/sqlite3.py +7 -7
- exonware/xwsystem/io/serialization/formats/tabular/__init__.py +27 -0
- exonware/xwsystem/io/serialization/formats/tabular/base.py +89 -0
- exonware/xwsystem/io/serialization/formats/tabular/csv.py +319 -0
- exonware/xwsystem/io/serialization/formats/tabular/df.py +249 -0
- exonware/xwsystem/io/serialization/formats/tabular/excel.py +291 -0
- exonware/xwsystem/io/serialization/formats/tabular/googlesheets.py +374 -0
- exonware/xwsystem/io/serialization/formats/text/__init__.py +1 -1
- exonware/xwsystem/io/serialization/formats/text/append_only_log.py +199 -0
- exonware/xwsystem/io/serialization/formats/text/configparser.py +5 -5
- exonware/xwsystem/io/serialization/formats/text/csv.py +7 -5
- exonware/xwsystem/io/serialization/formats/text/formdata.py +5 -5
- exonware/xwsystem/io/serialization/formats/text/json.py +65 -33
- exonware/xwsystem/io/serialization/formats/text/json5.py +8 -4
- exonware/xwsystem/io/serialization/formats/text/jsonlines.py +113 -25
- exonware/xwsystem/io/serialization/formats/text/multipart.py +5 -5
- exonware/xwsystem/io/serialization/formats/text/toml.py +8 -6
- exonware/xwsystem/io/serialization/formats/text/xml.py +25 -20
- exonware/xwsystem/io/serialization/formats/text/yaml.py +8 -6
- exonware/xwsystem/io/serialization/parsers/__init__.py +16 -0
- exonware/xwsystem/io/serialization/parsers/base.py +60 -0
- exonware/xwsystem/io/serialization/parsers/hybrid_parser.py +62 -0
- exonware/xwsystem/io/serialization/parsers/msgspec_parser.py +48 -0
- exonware/xwsystem/io/serialization/parsers/orjson_direct_parser.py +54 -0
- exonware/xwsystem/io/serialization/parsers/orjson_parser.py +62 -0
- exonware/xwsystem/io/serialization/parsers/pysimdjson_parser.py +55 -0
- exonware/xwsystem/io/serialization/parsers/rapidjson_parser.py +53 -0
- exonware/xwsystem/io/serialization/parsers/registry.py +91 -0
- exonware/xwsystem/io/serialization/parsers/standard.py +44 -0
- exonware/xwsystem/io/serialization/parsers/ujson_parser.py +53 -0
- exonware/xwsystem/io/serialization/registry.py +4 -4
- exonware/xwsystem/io/serialization/serializer.py +168 -79
- exonware/xwsystem/io/serialization/universal_options.py +367 -0
- exonware/xwsystem/io/serialization/utils/__init__.py +1 -2
- exonware/xwsystem/io/serialization/utils/path_ops.py +5 -6
- exonware/xwsystem/io/source_reader.py +223 -0
- exonware/xwsystem/io/stream/__init__.py +1 -1
- exonware/xwsystem/io/stream/async_operations.py +61 -14
- exonware/xwsystem/io/stream/base.py +1 -2
- exonware/xwsystem/io/stream/codec_io.py +6 -7
- exonware/xwsystem/ipc/__init__.py +1 -0
- exonware/xwsystem/ipc/async_fabric.py +4 -4
- exonware/xwsystem/ipc/base.py +6 -5
- exonware/xwsystem/ipc/contracts.py +41 -66
- exonware/xwsystem/ipc/defs.py +2 -1
- exonware/xwsystem/ipc/errors.py +2 -1
- exonware/xwsystem/ipc/message_queue.py +5 -2
- exonware/xwsystem/ipc/pipes.py +70 -34
- exonware/xwsystem/ipc/process_manager.py +7 -5
- exonware/xwsystem/ipc/process_pool.py +6 -5
- exonware/xwsystem/ipc/shared_memory.py +64 -11
- exonware/xwsystem/monitoring/__init__.py +7 -0
- exonware/xwsystem/monitoring/base.py +11 -8
- exonware/xwsystem/monitoring/contracts.py +86 -144
- exonware/xwsystem/monitoring/defs.py +2 -1
- exonware/xwsystem/monitoring/error_recovery.py +16 -3
- exonware/xwsystem/monitoring/errors.py +2 -1
- exonware/xwsystem/monitoring/facade.py +183 -0
- exonware/xwsystem/monitoring/memory_monitor.py +1 -0
- exonware/xwsystem/monitoring/metrics.py +1 -0
- exonware/xwsystem/monitoring/performance_manager_generic.py +7 -7
- exonware/xwsystem/monitoring/performance_monitor.py +1 -0
- exonware/xwsystem/monitoring/performance_validator.py +1 -0
- exonware/xwsystem/monitoring/system_monitor.py +6 -5
- exonware/xwsystem/monitoring/tracing.py +18 -16
- exonware/xwsystem/monitoring/tracker.py +2 -1
- exonware/xwsystem/operations/__init__.py +5 -50
- exonware/xwsystem/operations/base.py +3 -44
- exonware/xwsystem/operations/contracts.py +25 -15
- exonware/xwsystem/operations/defs.py +1 -1
- exonware/xwsystem/operations/diff.py +5 -4
- exonware/xwsystem/operations/errors.py +1 -1
- exonware/xwsystem/operations/merge.py +6 -4
- exonware/xwsystem/operations/patch.py +5 -4
- exonware/xwsystem/patterns/__init__.py +1 -0
- exonware/xwsystem/patterns/base.py +2 -1
- exonware/xwsystem/patterns/context_manager.py +2 -1
- exonware/xwsystem/patterns/contracts.py +215 -256
- exonware/xwsystem/patterns/defs.py +2 -1
- exonware/xwsystem/patterns/dynamic_facade.py +1 -0
- exonware/xwsystem/patterns/errors.py +2 -4
- exonware/xwsystem/patterns/handler_factory.py +2 -3
- exonware/xwsystem/patterns/import_registry.py +1 -0
- exonware/xwsystem/patterns/object_pool.py +1 -0
- exonware/xwsystem/patterns/registry.py +4 -43
- exonware/xwsystem/plugins/__init__.py +2 -1
- exonware/xwsystem/plugins/base.py +6 -5
- exonware/xwsystem/plugins/contracts.py +94 -158
- exonware/xwsystem/plugins/defs.py +2 -1
- exonware/xwsystem/plugins/errors.py +2 -1
- exonware/xwsystem/py.typed +3 -0
- exonware/xwsystem/query/__init__.py +36 -0
- exonware/xwsystem/query/contracts.py +56 -0
- exonware/xwsystem/query/errors.py +22 -0
- exonware/xwsystem/query/registry.py +128 -0
- exonware/xwsystem/runtime/__init__.py +2 -1
- exonware/xwsystem/runtime/base.py +4 -3
- exonware/xwsystem/runtime/contracts.py +39 -60
- exonware/xwsystem/runtime/defs.py +2 -1
- exonware/xwsystem/runtime/env.py +11 -9
- exonware/xwsystem/runtime/errors.py +2 -1
- exonware/xwsystem/runtime/reflection.py +3 -2
- exonware/xwsystem/security/__init__.py +68 -11
- exonware/xwsystem/security/audit.py +167 -0
- exonware/xwsystem/security/base.py +121 -24
- exonware/xwsystem/security/contracts.py +91 -146
- exonware/xwsystem/security/crypto.py +17 -16
- exonware/xwsystem/security/defs.py +2 -1
- exonware/xwsystem/security/errors.py +2 -1
- exonware/xwsystem/security/facade.py +321 -0
- exonware/xwsystem/security/file_security.py +330 -0
- exonware/xwsystem/security/hazmat.py +11 -8
- exonware/xwsystem/security/monitor.py +372 -0
- exonware/xwsystem/security/path_validator.py +140 -18
- exonware/xwsystem/security/policy.py +357 -0
- exonware/xwsystem/security/resource_limits.py +1 -0
- exonware/xwsystem/security/validator.py +455 -0
- exonware/xwsystem/shared/__init__.py +14 -1
- exonware/xwsystem/shared/base.py +285 -2
- exonware/xwsystem/shared/contracts.py +415 -126
- exonware/xwsystem/shared/defs.py +2 -1
- exonware/xwsystem/shared/errors.py +2 -2
- exonware/xwsystem/shared/xwobject.py +316 -0
- exonware/xwsystem/structures/__init__.py +1 -0
- exonware/xwsystem/structures/base.py +3 -2
- exonware/xwsystem/structures/circular_detector.py +15 -14
- exonware/xwsystem/structures/contracts.py +53 -76
- exonware/xwsystem/structures/defs.py +2 -1
- exonware/xwsystem/structures/errors.py +2 -1
- exonware/xwsystem/structures/tree_walker.py +2 -1
- exonware/xwsystem/threading/__init__.py +21 -4
- exonware/xwsystem/threading/async_primitives.py +6 -5
- exonware/xwsystem/threading/base.py +3 -2
- exonware/xwsystem/threading/contracts.py +87 -143
- exonware/xwsystem/threading/defs.py +2 -1
- exonware/xwsystem/threading/errors.py +2 -1
- exonware/xwsystem/threading/facade.py +175 -0
- exonware/xwsystem/threading/locks.py +1 -0
- exonware/xwsystem/threading/safe_factory.py +1 -0
- exonware/xwsystem/utils/__init__.py +40 -0
- exonware/xwsystem/utils/base.py +22 -21
- exonware/xwsystem/utils/contracts.py +50 -73
- exonware/xwsystem/utils/dt/__init__.py +19 -3
- exonware/xwsystem/utils/dt/base.py +5 -4
- exonware/xwsystem/utils/dt/contracts.py +22 -29
- exonware/xwsystem/utils/dt/defs.py +2 -1
- exonware/xwsystem/utils/dt/errors.py +2 -5
- exonware/xwsystem/utils/dt/formatting.py +88 -2
- exonware/xwsystem/utils/dt/humanize.py +10 -9
- exonware/xwsystem/utils/dt/parsing.py +56 -5
- exonware/xwsystem/utils/dt/timezone_utils.py +2 -24
- exonware/xwsystem/utils/errors.py +2 -4
- exonware/xwsystem/utils/paths.py +1 -0
- exonware/xwsystem/utils/string.py +49 -0
- exonware/xwsystem/utils/test_runner.py +139 -480
- exonware/xwsystem/utils/utils_contracts.py +2 -1
- exonware/xwsystem/utils/web.py +110 -0
- exonware/xwsystem/validation/__init__.py +25 -1
- exonware/xwsystem/validation/base.py +6 -5
- exonware/xwsystem/validation/contracts.py +29 -41
- exonware/xwsystem/validation/data_validator.py +1 -0
- exonware/xwsystem/validation/declarative.py +11 -8
- exonware/xwsystem/validation/defs.py +2 -1
- exonware/xwsystem/validation/errors.py +2 -1
- exonware/xwsystem/validation/facade.py +198 -0
- exonware/xwsystem/validation/fluent_validator.py +22 -19
- exonware/xwsystem/validation/schema_discovery.py +210 -0
- exonware/xwsystem/validation/type_safety.py +2 -1
- exonware/xwsystem/version.py +4 -4
- {exonware_xwsystem-0.0.1.411.dist-info → exonware_xwsystem-0.1.0.3.dist-info}/METADATA +71 -4
- exonware_xwsystem-0.1.0.3.dist-info/RECORD +337 -0
- exonware/xwsystem/caching/USAGE_GUIDE.md +0 -779
- exonware/xwsystem/cli/__init__.py +0 -43
- exonware/xwsystem/cli/console.py +0 -113
- exonware/xwsystem/cli/defs.py +0 -134
- exonware/xwsystem/conf.py +0 -44
- exonware/xwsystem/security/auth.py +0 -484
- exonware_xwsystem-0.0.1.411.dist-info/RECORD +0 -274
- {exonware_xwsystem-0.0.1.411.dist-info → exonware_xwsystem-0.1.0.3.dist-info}/WHEEL +0 -0
- {exonware_xwsystem-0.0.1.411.dist-info → exonware_xwsystem-0.1.0.3.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
|
+
#exonware/xwsystem/src/exonware/xwsystem/security/contracts.py
|
|
2
3
|
"""
|
|
3
4
|
Company: eXonware.com
|
|
4
5
|
Author: Eng. Muhammad AlShehri
|
|
5
6
|
Email: connect@exonware.com
|
|
6
|
-
Version: 0.0.
|
|
7
|
+
Version: 0.1.0.3
|
|
7
8
|
Generation Date: September 04, 2025
|
|
8
9
|
|
|
9
10
|
Security protocol interfaces for XWSystem.
|
|
10
11
|
"""
|
|
11
12
|
|
|
12
|
-
from
|
|
13
|
-
from typing import Any, Optional, Union, Iterator, Callable, Protocol
|
|
14
|
-
from typing_extensions import runtime_checkable
|
|
13
|
+
from typing import Any, Optional, Iterator, Callable, Protocol, runtime_checkable
|
|
15
14
|
import hashlib
|
|
16
15
|
|
|
17
16
|
# Import enums from types module
|
|
@@ -29,15 +28,15 @@ from .defs import (
|
|
|
29
28
|
# SECURITY INTERFACES
|
|
30
29
|
# ============================================================================
|
|
31
30
|
|
|
32
|
-
|
|
31
|
+
@runtime_checkable
|
|
32
|
+
class ISecure(Protocol):
|
|
33
33
|
"""
|
|
34
34
|
Interface for secure objects.
|
|
35
35
|
|
|
36
36
|
Enforces consistent security behavior across XWSystem.
|
|
37
37
|
"""
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
def encrypt(self, data: Union[str, bytes], algorithm: EncryptionAlgorithm = EncryptionAlgorithm.AES_256) -> Union[str, bytes]:
|
|
39
|
+
def encrypt(self, data: str | bytes, algorithm: EncryptionAlgorithm = EncryptionAlgorithm.AES_256) -> str | bytes:
|
|
41
40
|
"""
|
|
42
41
|
Encrypt data.
|
|
43
42
|
|
|
@@ -48,10 +47,9 @@ class ISecure(ABC):
|
|
|
48
47
|
Returns:
|
|
49
48
|
Encrypted data
|
|
50
49
|
"""
|
|
51
|
-
|
|
50
|
+
...
|
|
52
51
|
|
|
53
|
-
|
|
54
|
-
def decrypt(self, encrypted_data: Union[str, bytes], algorithm: EncryptionAlgorithm = EncryptionAlgorithm.AES_256) -> Union[str, bytes]:
|
|
52
|
+
def decrypt(self, encrypted_data: str | bytes, algorithm: EncryptionAlgorithm = EncryptionAlgorithm.AES_256) -> str | bytes:
|
|
55
53
|
"""
|
|
56
54
|
Decrypt data.
|
|
57
55
|
|
|
@@ -62,10 +60,9 @@ class ISecure(ABC):
|
|
|
62
60
|
Returns:
|
|
63
61
|
Decrypted data
|
|
64
62
|
"""
|
|
65
|
-
|
|
63
|
+
...
|
|
66
64
|
|
|
67
|
-
|
|
68
|
-
def hash(self, data: Union[str, bytes], algorithm: HashAlgorithm = HashAlgorithm.SHA256) -> str:
|
|
65
|
+
def hash(self, data: str | bytes, algorithm: HashAlgorithm = HashAlgorithm.SHA256) -> str:
|
|
69
66
|
"""
|
|
70
67
|
Hash data.
|
|
71
68
|
|
|
@@ -76,10 +73,9 @@ class ISecure(ABC):
|
|
|
76
73
|
Returns:
|
|
77
74
|
Hash string
|
|
78
75
|
"""
|
|
79
|
-
|
|
76
|
+
...
|
|
80
77
|
|
|
81
|
-
|
|
82
|
-
def verify_hash(self, data: Union[str, bytes], hash_value: str, algorithm: HashAlgorithm = HashAlgorithm.SHA256) -> bool:
|
|
78
|
+
def verify_hash(self, data: str | bytes, hash_value: str, algorithm: HashAlgorithm = HashAlgorithm.SHA256) -> bool:
|
|
83
79
|
"""
|
|
84
80
|
Verify data against hash.
|
|
85
81
|
|
|
@@ -91,9 +87,8 @@ class ISecure(ABC):
|
|
|
91
87
|
Returns:
|
|
92
88
|
True if hash matches
|
|
93
89
|
"""
|
|
94
|
-
|
|
90
|
+
...
|
|
95
91
|
|
|
96
|
-
@abstractmethod
|
|
97
92
|
def generate_key(self, algorithm: EncryptionAlgorithm = EncryptionAlgorithm.AES_256) -> bytes:
|
|
98
93
|
"""
|
|
99
94
|
Generate encryption key.
|
|
@@ -104,9 +99,8 @@ class ISecure(ABC):
|
|
|
104
99
|
Returns:
|
|
105
100
|
Generated key
|
|
106
101
|
"""
|
|
107
|
-
|
|
102
|
+
...
|
|
108
103
|
|
|
109
|
-
@abstractmethod
|
|
110
104
|
def generate_salt(self, length: int = 32) -> bytes:
|
|
111
105
|
"""
|
|
112
106
|
Generate random salt.
|
|
@@ -117,9 +111,8 @@ class ISecure(ABC):
|
|
|
117
111
|
Returns:
|
|
118
112
|
Generated salt
|
|
119
113
|
"""
|
|
120
|
-
|
|
114
|
+
...
|
|
121
115
|
|
|
122
|
-
@abstractmethod
|
|
123
116
|
def secure_random(self, length: int) -> bytes:
|
|
124
117
|
"""
|
|
125
118
|
Generate secure random bytes.
|
|
@@ -130,21 +123,21 @@ class ISecure(ABC):
|
|
|
130
123
|
Returns:
|
|
131
124
|
Random bytes
|
|
132
125
|
"""
|
|
133
|
-
|
|
126
|
+
...
|
|
134
127
|
|
|
135
128
|
|
|
136
129
|
# ============================================================================
|
|
137
130
|
# AUTHENTICATION INTERFACES
|
|
138
131
|
# ============================================================================
|
|
139
132
|
|
|
140
|
-
|
|
133
|
+
@runtime_checkable
|
|
134
|
+
class IAuthenticatable(Protocol):
|
|
141
135
|
"""
|
|
142
136
|
Interface for authentication.
|
|
143
137
|
|
|
144
138
|
Enforces consistent authentication behavior across XWSystem.
|
|
145
139
|
"""
|
|
146
140
|
|
|
147
|
-
@abstractmethod
|
|
148
141
|
def authenticate(self, credentials: dict[str, Any]) -> bool:
|
|
149
142
|
"""
|
|
150
143
|
Authenticate user with credentials.
|
|
@@ -155,9 +148,8 @@ class IAuthenticatable(ABC):
|
|
|
155
148
|
Returns:
|
|
156
149
|
True if authenticated
|
|
157
150
|
"""
|
|
158
|
-
|
|
151
|
+
...
|
|
159
152
|
|
|
160
|
-
@abstractmethod
|
|
161
153
|
def authorize(self, user: str, resource: str, action: str) -> bool:
|
|
162
154
|
"""
|
|
163
155
|
Authorize user for resource action.
|
|
@@ -170,9 +162,8 @@ class IAuthenticatable(ABC):
|
|
|
170
162
|
Returns:
|
|
171
163
|
True if authorized
|
|
172
164
|
"""
|
|
173
|
-
|
|
165
|
+
...
|
|
174
166
|
|
|
175
|
-
@abstractmethod
|
|
176
167
|
def logout(self, user: str) -> bool:
|
|
177
168
|
"""
|
|
178
169
|
Logout user.
|
|
@@ -183,9 +174,8 @@ class IAuthenticatable(ABC):
|
|
|
183
174
|
Returns:
|
|
184
175
|
True if logged out
|
|
185
176
|
"""
|
|
186
|
-
|
|
177
|
+
...
|
|
187
178
|
|
|
188
|
-
@abstractmethod
|
|
189
179
|
def is_authenticated(self, user: str) -> bool:
|
|
190
180
|
"""
|
|
191
181
|
Check if user is authenticated.
|
|
@@ -196,9 +186,8 @@ class IAuthenticatable(ABC):
|
|
|
196
186
|
Returns:
|
|
197
187
|
True if authenticated
|
|
198
188
|
"""
|
|
199
|
-
|
|
189
|
+
...
|
|
200
190
|
|
|
201
|
-
@abstractmethod
|
|
202
191
|
def get_user_permissions(self, user: str) -> list[str]:
|
|
203
192
|
"""
|
|
204
193
|
Get user permissions.
|
|
@@ -209,9 +198,8 @@ class IAuthenticatable(ABC):
|
|
|
209
198
|
Returns:
|
|
210
199
|
List of permissions
|
|
211
200
|
"""
|
|
212
|
-
|
|
201
|
+
...
|
|
213
202
|
|
|
214
|
-
@abstractmethod
|
|
215
203
|
def set_user_permissions(self, user: str, permissions: list[str]) -> None:
|
|
216
204
|
"""
|
|
217
205
|
Set user permissions.
|
|
@@ -220,9 +208,8 @@ class IAuthenticatable(ABC):
|
|
|
220
208
|
user: User identifier
|
|
221
209
|
permissions: List of permissions
|
|
222
210
|
"""
|
|
223
|
-
|
|
211
|
+
...
|
|
224
212
|
|
|
225
|
-
@abstractmethod
|
|
226
213
|
def validate_credentials(self, credentials: dict[str, Any]) -> bool:
|
|
227
214
|
"""
|
|
228
215
|
Validate credential format.
|
|
@@ -233,9 +220,8 @@ class IAuthenticatable(ABC):
|
|
|
233
220
|
Returns:
|
|
234
221
|
True if valid format
|
|
235
222
|
"""
|
|
236
|
-
|
|
223
|
+
...
|
|
237
224
|
|
|
238
|
-
@abstractmethod
|
|
239
225
|
def get_authentication_method(self) -> AuthenticationMethod:
|
|
240
226
|
"""
|
|
241
227
|
Get authentication method.
|
|
@@ -243,21 +229,21 @@ class IAuthenticatable(ABC):
|
|
|
243
229
|
Returns:
|
|
244
230
|
Authentication method
|
|
245
231
|
"""
|
|
246
|
-
|
|
232
|
+
...
|
|
247
233
|
|
|
248
234
|
|
|
249
235
|
# ============================================================================
|
|
250
236
|
# AUDIT INTERFACES
|
|
251
237
|
# ============================================================================
|
|
252
238
|
|
|
253
|
-
|
|
239
|
+
@runtime_checkable
|
|
240
|
+
class IAuditable(Protocol):
|
|
254
241
|
"""
|
|
255
242
|
Interface for audit trails.
|
|
256
243
|
|
|
257
244
|
Enforces consistent audit behavior across XWSystem.
|
|
258
245
|
"""
|
|
259
246
|
|
|
260
|
-
@abstractmethod
|
|
261
247
|
def log_action(self, action: AuditEvent, user: str, resource: str, details: dict[str, Any] = None) -> None:
|
|
262
248
|
"""
|
|
263
249
|
Log audit action.
|
|
@@ -268,9 +254,8 @@ class IAuditable(ABC):
|
|
|
268
254
|
resource: Resource identifier
|
|
269
255
|
details: Additional details
|
|
270
256
|
"""
|
|
271
|
-
|
|
257
|
+
...
|
|
272
258
|
|
|
273
|
-
@abstractmethod
|
|
274
259
|
def get_audit_trail(self, user: Optional[str] = None, resource: Optional[str] = None,
|
|
275
260
|
start_time: Optional[float] = None, end_time: Optional[float] = None) -> list[dict[str, Any]]:
|
|
276
261
|
"""
|
|
@@ -285,9 +270,8 @@ class IAuditable(ABC):
|
|
|
285
270
|
Returns:
|
|
286
271
|
List of audit entries
|
|
287
272
|
"""
|
|
288
|
-
|
|
273
|
+
...
|
|
289
274
|
|
|
290
|
-
@abstractmethod
|
|
291
275
|
def clear_audit_trail(self, older_than: Optional[float] = None) -> int:
|
|
292
276
|
"""
|
|
293
277
|
Clear audit trail.
|
|
@@ -298,9 +282,8 @@ class IAuditable(ABC):
|
|
|
298
282
|
Returns:
|
|
299
283
|
Number of entries cleared
|
|
300
284
|
"""
|
|
301
|
-
|
|
285
|
+
...
|
|
302
286
|
|
|
303
|
-
@abstractmethod
|
|
304
287
|
def export_audit_trail(self, file_path: str, format: str = "json") -> bool:
|
|
305
288
|
"""
|
|
306
289
|
Export audit trail to file.
|
|
@@ -312,9 +295,8 @@ class IAuditable(ABC):
|
|
|
312
295
|
Returns:
|
|
313
296
|
True if exported successfully
|
|
314
297
|
"""
|
|
315
|
-
|
|
298
|
+
...
|
|
316
299
|
|
|
317
|
-
@abstractmethod
|
|
318
300
|
def get_audit_stats(self) -> dict[str, Any]:
|
|
319
301
|
"""
|
|
320
302
|
Get audit statistics.
|
|
@@ -322,9 +304,8 @@ class IAuditable(ABC):
|
|
|
322
304
|
Returns:
|
|
323
305
|
Audit statistics dictionary
|
|
324
306
|
"""
|
|
325
|
-
|
|
307
|
+
...
|
|
326
308
|
|
|
327
|
-
@abstractmethod
|
|
328
309
|
def is_audit_enabled(self) -> bool:
|
|
329
310
|
"""
|
|
330
311
|
Check if auditing is enabled.
|
|
@@ -332,35 +313,33 @@ class IAuditable(ABC):
|
|
|
332
313
|
Returns:
|
|
333
314
|
True if enabled
|
|
334
315
|
"""
|
|
335
|
-
|
|
316
|
+
...
|
|
336
317
|
|
|
337
|
-
@abstractmethod
|
|
338
318
|
def enable_audit(self) -> None:
|
|
339
319
|
"""
|
|
340
320
|
Enable auditing.
|
|
341
321
|
"""
|
|
342
|
-
|
|
322
|
+
...
|
|
343
323
|
|
|
344
|
-
@abstractmethod
|
|
345
324
|
def disable_audit(self) -> None:
|
|
346
325
|
"""
|
|
347
326
|
Disable auditing.
|
|
348
327
|
"""
|
|
349
|
-
|
|
328
|
+
...
|
|
350
329
|
|
|
351
330
|
|
|
352
331
|
# ============================================================================
|
|
353
332
|
# AUTHORIZATION INTERFACES
|
|
354
333
|
# ============================================================================
|
|
355
334
|
|
|
356
|
-
|
|
335
|
+
@runtime_checkable
|
|
336
|
+
class IAuthorization(Protocol):
|
|
357
337
|
"""
|
|
358
338
|
Interface for authorization.
|
|
359
339
|
|
|
360
340
|
Enforces consistent authorization behavior across XWSystem.
|
|
361
341
|
"""
|
|
362
342
|
|
|
363
|
-
@abstractmethod
|
|
364
343
|
def check_permission(self, user: str, resource: str, action: str) -> bool:
|
|
365
344
|
"""
|
|
366
345
|
Check user permission for resource action.
|
|
@@ -373,9 +352,8 @@ class IAuthorization(ABC):
|
|
|
373
352
|
Returns:
|
|
374
353
|
True if permitted
|
|
375
354
|
"""
|
|
376
|
-
|
|
355
|
+
...
|
|
377
356
|
|
|
378
|
-
@abstractmethod
|
|
379
357
|
def grant_permission(self, user: str, resource: str, action: str) -> bool:
|
|
380
358
|
"""
|
|
381
359
|
Grant permission to user.
|
|
@@ -388,9 +366,8 @@ class IAuthorization(ABC):
|
|
|
388
366
|
Returns:
|
|
389
367
|
True if granted
|
|
390
368
|
"""
|
|
391
|
-
|
|
369
|
+
...
|
|
392
370
|
|
|
393
|
-
@abstractmethod
|
|
394
371
|
def revoke_permission(self, user: str, resource: str, action: str) -> bool:
|
|
395
372
|
"""
|
|
396
373
|
Revoke permission from user.
|
|
@@ -403,9 +380,8 @@ class IAuthorization(ABC):
|
|
|
403
380
|
Returns:
|
|
404
381
|
True if revoked
|
|
405
382
|
"""
|
|
406
|
-
|
|
383
|
+
...
|
|
407
384
|
|
|
408
|
-
@abstractmethod
|
|
409
385
|
def get_user_roles(self, user: str) -> list[str]:
|
|
410
386
|
"""
|
|
411
387
|
Get user roles.
|
|
@@ -416,9 +392,8 @@ class IAuthorization(ABC):
|
|
|
416
392
|
Returns:
|
|
417
393
|
List of role names
|
|
418
394
|
"""
|
|
419
|
-
|
|
395
|
+
...
|
|
420
396
|
|
|
421
|
-
@abstractmethod
|
|
422
397
|
def assign_role(self, user: str, role: str) -> bool:
|
|
423
398
|
"""
|
|
424
399
|
Assign role to user.
|
|
@@ -430,9 +405,8 @@ class IAuthorization(ABC):
|
|
|
430
405
|
Returns:
|
|
431
406
|
True if assigned
|
|
432
407
|
"""
|
|
433
|
-
|
|
408
|
+
...
|
|
434
409
|
|
|
435
|
-
@abstractmethod
|
|
436
410
|
def remove_role(self, user: str, role: str) -> bool:
|
|
437
411
|
"""
|
|
438
412
|
Remove role from user.
|
|
@@ -444,9 +418,8 @@ class IAuthorization(ABC):
|
|
|
444
418
|
Returns:
|
|
445
419
|
True if removed
|
|
446
420
|
"""
|
|
447
|
-
|
|
421
|
+
...
|
|
448
422
|
|
|
449
|
-
@abstractmethod
|
|
450
423
|
def get_role_permissions(self, role: str) -> list[str]:
|
|
451
424
|
"""
|
|
452
425
|
Get role permissions.
|
|
@@ -457,9 +430,8 @@ class IAuthorization(ABC):
|
|
|
457
430
|
Returns:
|
|
458
431
|
List of permissions
|
|
459
432
|
"""
|
|
460
|
-
|
|
433
|
+
...
|
|
461
434
|
|
|
462
|
-
@abstractmethod
|
|
463
435
|
def set_role_permissions(self, role: str, permissions: list[str]) -> None:
|
|
464
436
|
"""
|
|
465
437
|
Set role permissions.
|
|
@@ -468,34 +440,33 @@ class IAuthorization(ABC):
|
|
|
468
440
|
role: Role name
|
|
469
441
|
permissions: List of permissions
|
|
470
442
|
"""
|
|
471
|
-
|
|
443
|
+
...
|
|
472
444
|
|
|
473
445
|
|
|
474
446
|
# ============================================================================
|
|
475
447
|
# SECURITY VALIDATION INTERFACES
|
|
476
448
|
# ============================================================================
|
|
477
449
|
|
|
478
|
-
|
|
450
|
+
@runtime_checkable
|
|
451
|
+
class ISecurityValidator(Protocol):
|
|
479
452
|
"""
|
|
480
453
|
Interface for security validation.
|
|
481
454
|
|
|
482
455
|
Enforces consistent security validation across XWSystem.
|
|
483
456
|
"""
|
|
484
457
|
|
|
485
|
-
@abstractmethod
|
|
486
458
|
def validate_password(self, password: str) -> tuple[bool, list[str]]:
|
|
487
459
|
"""
|
|
488
460
|
Validate password strength.
|
|
489
461
|
|
|
490
462
|
Args:
|
|
491
|
-
|
|
463
|
+
...word: Password to validate
|
|
492
464
|
|
|
493
465
|
Returns:
|
|
494
466
|
Tuple of (is_valid, error_messages)
|
|
495
467
|
"""
|
|
496
|
-
|
|
468
|
+
...
|
|
497
469
|
|
|
498
|
-
@abstractmethod
|
|
499
470
|
def validate_input(self, input_data: str, input_type: str) -> tuple[bool, list[str]]:
|
|
500
471
|
"""
|
|
501
472
|
Validate input data.
|
|
@@ -507,9 +478,8 @@ class ISecurityValidator(ABC):
|
|
|
507
478
|
Returns:
|
|
508
479
|
Tuple of (is_valid, error_messages)
|
|
509
480
|
"""
|
|
510
|
-
|
|
481
|
+
...
|
|
511
482
|
|
|
512
|
-
@abstractmethod
|
|
513
483
|
def sanitize_input(self, input_data: str) -> str:
|
|
514
484
|
"""
|
|
515
485
|
Sanitize input data.
|
|
@@ -520,9 +490,8 @@ class ISecurityValidator(ABC):
|
|
|
520
490
|
Returns:
|
|
521
491
|
Sanitized data
|
|
522
492
|
"""
|
|
523
|
-
|
|
493
|
+
...
|
|
524
494
|
|
|
525
|
-
@abstractmethod
|
|
526
495
|
def detect_sql_injection(self, input_data: str) -> bool:
|
|
527
496
|
"""
|
|
528
497
|
Detect SQL injection attempts.
|
|
@@ -533,9 +502,8 @@ class ISecurityValidator(ABC):
|
|
|
533
502
|
Returns:
|
|
534
503
|
True if SQL injection detected
|
|
535
504
|
"""
|
|
536
|
-
|
|
505
|
+
...
|
|
537
506
|
|
|
538
|
-
@abstractmethod
|
|
539
507
|
def detect_xss(self, input_data: str) -> bool:
|
|
540
508
|
"""
|
|
541
509
|
Detect XSS attempts.
|
|
@@ -546,9 +514,8 @@ class ISecurityValidator(ABC):
|
|
|
546
514
|
Returns:
|
|
547
515
|
True if XSS detected
|
|
548
516
|
"""
|
|
549
|
-
|
|
517
|
+
...
|
|
550
518
|
|
|
551
|
-
@abstractmethod
|
|
552
519
|
def validate_certificate(self, certificate: bytes) -> tuple[bool, str]:
|
|
553
520
|
"""
|
|
554
521
|
Validate certificate.
|
|
@@ -559,9 +526,8 @@ class ISecurityValidator(ABC):
|
|
|
559
526
|
Returns:
|
|
560
527
|
Tuple of (is_valid, error_message)
|
|
561
528
|
"""
|
|
562
|
-
|
|
529
|
+
...
|
|
563
530
|
|
|
564
|
-
@abstractmethod
|
|
565
531
|
def check_security_headers(self, headers: dict[str, str]) -> dict[str, bool]:
|
|
566
532
|
"""
|
|
567
533
|
Check security headers.
|
|
@@ -572,21 +538,21 @@ class ISecurityValidator(ABC):
|
|
|
572
538
|
Returns:
|
|
573
539
|
Dictionary of header validation results
|
|
574
540
|
"""
|
|
575
|
-
|
|
541
|
+
...
|
|
576
542
|
|
|
577
543
|
|
|
578
544
|
# ============================================================================
|
|
579
545
|
# SECURITY MONITORING INTERFACES
|
|
580
546
|
# ============================================================================
|
|
581
547
|
|
|
582
|
-
|
|
548
|
+
@runtime_checkable
|
|
549
|
+
class ISecurityMonitor(Protocol):
|
|
583
550
|
"""
|
|
584
551
|
Interface for security monitoring.
|
|
585
552
|
|
|
586
553
|
Enforces consistent security monitoring across XWSystem.
|
|
587
554
|
"""
|
|
588
555
|
|
|
589
|
-
@abstractmethod
|
|
590
556
|
def detect_intrusion(self, event_data: dict[str, Any]) -> bool:
|
|
591
557
|
"""
|
|
592
558
|
Detect intrusion attempts.
|
|
@@ -597,9 +563,8 @@ class ISecurityMonitor(ABC):
|
|
|
597
563
|
Returns:
|
|
598
564
|
True if intrusion detected
|
|
599
565
|
"""
|
|
600
|
-
|
|
566
|
+
...
|
|
601
567
|
|
|
602
|
-
@abstractmethod
|
|
603
568
|
def monitor_failed_logins(self, user: str, max_attempts: int = 5) -> bool:
|
|
604
569
|
"""
|
|
605
570
|
Monitor failed login attempts.
|
|
@@ -611,9 +576,8 @@ class ISecurityMonitor(ABC):
|
|
|
611
576
|
Returns:
|
|
612
577
|
True if threshold exceeded
|
|
613
578
|
"""
|
|
614
|
-
|
|
579
|
+
...
|
|
615
580
|
|
|
616
|
-
@abstractmethod
|
|
617
581
|
def detect_anomaly(self, behavior_data: dict[str, Any]) -> bool:
|
|
618
582
|
"""
|
|
619
583
|
Detect anomalous behavior.
|
|
@@ -624,9 +588,8 @@ class ISecurityMonitor(ABC):
|
|
|
624
588
|
Returns:
|
|
625
589
|
True if anomaly detected
|
|
626
590
|
"""
|
|
627
|
-
|
|
591
|
+
...
|
|
628
592
|
|
|
629
|
-
@abstractmethod
|
|
630
593
|
def get_security_alerts(self) -> list[dict[str, Any]]:
|
|
631
594
|
"""
|
|
632
595
|
Get security alerts.
|
|
@@ -634,16 +597,14 @@ class ISecurityMonitor(ABC):
|
|
|
634
597
|
Returns:
|
|
635
598
|
List of security alerts
|
|
636
599
|
"""
|
|
637
|
-
|
|
600
|
+
...
|
|
638
601
|
|
|
639
|
-
@abstractmethod
|
|
640
602
|
def clear_security_alerts(self) -> None:
|
|
641
603
|
"""
|
|
642
604
|
Clear security alerts.
|
|
643
605
|
"""
|
|
644
|
-
|
|
606
|
+
...
|
|
645
607
|
|
|
646
|
-
@abstractmethod
|
|
647
608
|
def get_threat_level(self) -> SecurityLevel:
|
|
648
609
|
"""
|
|
649
610
|
Get current threat level.
|
|
@@ -651,9 +612,8 @@ class ISecurityMonitor(ABC):
|
|
|
651
612
|
Returns:
|
|
652
613
|
Current threat level
|
|
653
614
|
"""
|
|
654
|
-
|
|
615
|
+
...
|
|
655
616
|
|
|
656
|
-
@abstractmethod
|
|
657
617
|
def set_threat_level(self, level: SecurityLevel) -> None:
|
|
658
618
|
"""
|
|
659
619
|
Set threat level.
|
|
@@ -661,9 +621,8 @@ class ISecurityMonitor(ABC):
|
|
|
661
621
|
Args:
|
|
662
622
|
level: Threat level to set
|
|
663
623
|
"""
|
|
664
|
-
|
|
624
|
+
...
|
|
665
625
|
|
|
666
|
-
@abstractmethod
|
|
667
626
|
def get_security_metrics(self) -> dict[str, Any]:
|
|
668
627
|
"""
|
|
669
628
|
Get security metrics.
|
|
@@ -671,21 +630,21 @@ class ISecurityMonitor(ABC):
|
|
|
671
630
|
Returns:
|
|
672
631
|
Security metrics dictionary
|
|
673
632
|
"""
|
|
674
|
-
|
|
633
|
+
...
|
|
675
634
|
|
|
676
635
|
|
|
677
636
|
# ============================================================================
|
|
678
637
|
# SECURITY POLICY INTERFACES
|
|
679
638
|
# ============================================================================
|
|
680
639
|
|
|
681
|
-
|
|
640
|
+
@runtime_checkable
|
|
641
|
+
class ISecurityPolicy(Protocol):
|
|
682
642
|
"""
|
|
683
643
|
Interface for security policies.
|
|
684
644
|
|
|
685
645
|
Enforces consistent security policy behavior across XWSystem.
|
|
686
646
|
"""
|
|
687
647
|
|
|
688
|
-
@abstractmethod
|
|
689
648
|
def get_policy(self, policy_name: str) -> dict[str, Any]:
|
|
690
649
|
"""
|
|
691
650
|
Get security policy.
|
|
@@ -696,9 +655,8 @@ class ISecurityPolicy(ABC):
|
|
|
696
655
|
Returns:
|
|
697
656
|
Policy dictionary
|
|
698
657
|
"""
|
|
699
|
-
|
|
658
|
+
...
|
|
700
659
|
|
|
701
|
-
@abstractmethod
|
|
702
660
|
def set_policy(self, policy_name: str, policy: dict[str, Any]) -> None:
|
|
703
661
|
"""
|
|
704
662
|
Set security policy.
|
|
@@ -707,9 +665,8 @@ class ISecurityPolicy(ABC):
|
|
|
707
665
|
policy_name: Policy name
|
|
708
666
|
policy: Policy dictionary
|
|
709
667
|
"""
|
|
710
|
-
|
|
668
|
+
...
|
|
711
669
|
|
|
712
|
-
@abstractmethod
|
|
713
670
|
def validate_policy(self, policy: dict[str, Any]) -> tuple[bool, list[str]]:
|
|
714
671
|
"""
|
|
715
672
|
Validate security policy.
|
|
@@ -720,9 +677,8 @@ class ISecurityPolicy(ABC):
|
|
|
720
677
|
Returns:
|
|
721
678
|
Tuple of (is_valid, error_messages)
|
|
722
679
|
"""
|
|
723
|
-
|
|
680
|
+
...
|
|
724
681
|
|
|
725
|
-
@abstractmethod
|
|
726
682
|
def apply_policy(self, policy_name: str, context: dict[str, Any]) -> bool:
|
|
727
683
|
"""
|
|
728
684
|
Apply security policy.
|
|
@@ -734,9 +690,8 @@ class ISecurityPolicy(ABC):
|
|
|
734
690
|
Returns:
|
|
735
691
|
True if policy applied successfully
|
|
736
692
|
"""
|
|
737
|
-
|
|
693
|
+
...
|
|
738
694
|
|
|
739
|
-
@abstractmethod
|
|
740
695
|
def list_policies(self) -> list[str]:
|
|
741
696
|
"""
|
|
742
697
|
List all security policies.
|
|
@@ -744,9 +699,8 @@ class ISecurityPolicy(ABC):
|
|
|
744
699
|
Returns:
|
|
745
700
|
List of policy names
|
|
746
701
|
"""
|
|
747
|
-
|
|
702
|
+
...
|
|
748
703
|
|
|
749
|
-
@abstractmethod
|
|
750
704
|
def remove_policy(self, policy_name: str) -> bool:
|
|
751
705
|
"""
|
|
752
706
|
Remove security policy.
|
|
@@ -757,9 +711,8 @@ class ISecurityPolicy(ABC):
|
|
|
757
711
|
Returns:
|
|
758
712
|
True if removed
|
|
759
713
|
"""
|
|
760
|
-
|
|
714
|
+
...
|
|
761
715
|
|
|
762
|
-
@abstractmethod
|
|
763
716
|
def get_policy_violations(self) -> list[dict[str, Any]]:
|
|
764
717
|
"""
|
|
765
718
|
Get policy violations.
|
|
@@ -767,28 +720,27 @@ class ISecurityPolicy(ABC):
|
|
|
767
720
|
Returns:
|
|
768
721
|
List of policy violations
|
|
769
722
|
"""
|
|
770
|
-
|
|
723
|
+
...
|
|
771
724
|
|
|
772
|
-
@abstractmethod
|
|
773
725
|
def clear_policy_violations(self) -> None:
|
|
774
726
|
"""
|
|
775
727
|
Clear policy violations.
|
|
776
728
|
"""
|
|
777
|
-
|
|
729
|
+
...
|
|
778
730
|
|
|
779
731
|
|
|
780
732
|
# ============================================================================
|
|
781
733
|
# SECURITY TOKEN INTERFACES
|
|
782
734
|
# ============================================================================
|
|
783
735
|
|
|
784
|
-
|
|
736
|
+
@runtime_checkable
|
|
737
|
+
class ISecurityToken(Protocol):
|
|
785
738
|
"""
|
|
786
739
|
Interface for security tokens.
|
|
787
740
|
|
|
788
741
|
Enforces consistent security token behavior across XWSystem.
|
|
789
742
|
"""
|
|
790
743
|
|
|
791
|
-
@abstractmethod
|
|
792
744
|
def generate_token(self, payload: dict[str, Any], expires_in: int = 3600) -> str:
|
|
793
745
|
"""
|
|
794
746
|
Generate security token.
|
|
@@ -800,9 +752,8 @@ class ISecurityToken(ABC):
|
|
|
800
752
|
Returns:
|
|
801
753
|
Generated token
|
|
802
754
|
"""
|
|
803
|
-
|
|
755
|
+
...
|
|
804
756
|
|
|
805
|
-
@abstractmethod
|
|
806
757
|
def validate_token(self, token: str) -> tuple[bool, dict[str, Any]]:
|
|
807
758
|
"""
|
|
808
759
|
Validate security token.
|
|
@@ -813,9 +764,8 @@ class ISecurityToken(ABC):
|
|
|
813
764
|
Returns:
|
|
814
765
|
Tuple of (is_valid, payload)
|
|
815
766
|
"""
|
|
816
|
-
|
|
767
|
+
...
|
|
817
768
|
|
|
818
|
-
@abstractmethod
|
|
819
769
|
def refresh_token(self, token: str, expires_in: int = 3600) -> str:
|
|
820
770
|
"""
|
|
821
771
|
Refresh security token.
|
|
@@ -827,9 +777,8 @@ class ISecurityToken(ABC):
|
|
|
827
777
|
Returns:
|
|
828
778
|
Refreshed token
|
|
829
779
|
"""
|
|
830
|
-
|
|
780
|
+
...
|
|
831
781
|
|
|
832
|
-
@abstractmethod
|
|
833
782
|
def revoke_token(self, token: str) -> bool:
|
|
834
783
|
"""
|
|
835
784
|
Revoke security token.
|
|
@@ -840,9 +789,8 @@ class ISecurityToken(ABC):
|
|
|
840
789
|
Returns:
|
|
841
790
|
True if revoked
|
|
842
791
|
"""
|
|
843
|
-
|
|
792
|
+
...
|
|
844
793
|
|
|
845
|
-
@abstractmethod
|
|
846
794
|
def is_token_expired(self, token: str) -> bool:
|
|
847
795
|
"""
|
|
848
796
|
Check if token is expired.
|
|
@@ -853,9 +801,8 @@ class ISecurityToken(ABC):
|
|
|
853
801
|
Returns:
|
|
854
802
|
True if expired
|
|
855
803
|
"""
|
|
856
|
-
|
|
804
|
+
...
|
|
857
805
|
|
|
858
|
-
@abstractmethod
|
|
859
806
|
def get_token_info(self, token: str) -> dict[str, Any]:
|
|
860
807
|
"""
|
|
861
808
|
Get token information.
|
|
@@ -866,9 +813,8 @@ class ISecurityToken(ABC):
|
|
|
866
813
|
Returns:
|
|
867
814
|
Token information dictionary
|
|
868
815
|
"""
|
|
869
|
-
|
|
816
|
+
...
|
|
870
817
|
|
|
871
|
-
@abstractmethod
|
|
872
818
|
def list_active_tokens(self, user: Optional[str] = None) -> list[str]:
|
|
873
819
|
"""
|
|
874
820
|
List active tokens.
|
|
@@ -879,9 +825,8 @@ class ISecurityToken(ABC):
|
|
|
879
825
|
Returns:
|
|
880
826
|
List of active tokens
|
|
881
827
|
"""
|
|
882
|
-
|
|
828
|
+
...
|
|
883
829
|
|
|
884
|
-
@abstractmethod
|
|
885
830
|
def cleanup_expired_tokens(self) -> int:
|
|
886
831
|
"""
|
|
887
832
|
Cleanup expired tokens.
|
|
@@ -889,7 +834,7 @@ class ISecurityToken(ABC):
|
|
|
889
834
|
Returns:
|
|
890
835
|
Number of tokens cleaned up
|
|
891
836
|
"""
|
|
892
|
-
|
|
837
|
+
...
|
|
893
838
|
|
|
894
839
|
|
|
895
840
|
# ============================================================================
|
|
@@ -897,22 +842,22 @@ class ISecurityToken(ABC):
|
|
|
897
842
|
# ============================================================================
|
|
898
843
|
|
|
899
844
|
@runtime_checkable
|
|
900
|
-
class
|
|
845
|
+
class IHashable(Protocol):
|
|
901
846
|
"""Protocol for objects that can be hashed securely."""
|
|
902
847
|
|
|
903
|
-
def hash(self, data:
|
|
848
|
+
def hash(self, data: str | bytes, **kwargs: Any) -> str:
|
|
904
849
|
"""Generate hash of data."""
|
|
905
850
|
...
|
|
906
851
|
|
|
907
852
|
|
|
908
853
|
@runtime_checkable
|
|
909
|
-
class
|
|
854
|
+
class IEncryptable(Protocol):
|
|
910
855
|
"""Protocol for objects that support encryption/decryption."""
|
|
911
856
|
|
|
912
|
-
def encrypt(self, data:
|
|
857
|
+
def encrypt(self, data: str | bytes, **kwargs: Any) -> bytes:
|
|
913
858
|
"""Encrypt data."""
|
|
914
859
|
...
|
|
915
860
|
|
|
916
|
-
def decrypt(self, data: bytes, **kwargs: Any) ->
|
|
861
|
+
def decrypt(self, data: bytes, **kwargs: Any) -> str | bytes:
|
|
917
862
|
"""Decrypt data."""
|
|
918
863
|
...
|