sbombox-core 0.1.0__tar.gz

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.
Files changed (69) hide show
  1. sbombox_core-0.1.0/.gitignore +40 -0
  2. sbombox_core-0.1.0/PKG-INFO +31 -0
  3. sbombox_core-0.1.0/pyproject.toml +37 -0
  4. sbombox_core-0.1.0/samples/.gitkeep +0 -0
  5. sbombox_core-0.1.0/src/sbombox_core/__init__.py +162 -0
  6. sbombox_core-0.1.0/src/sbombox_core/compliance/__init__.py +711 -0
  7. sbombox_core-0.1.0/src/sbombox_core/compliance/profiles/bsi-tr-03183-2@1.1.yaml +36 -0
  8. sbombox_core-0.1.0/src/sbombox_core/compliance/profiles/bsi-tr-03183-2@2.0.0.yaml +46 -0
  9. sbombox_core-0.1.0/src/sbombox_core/compliance/profiles/bsi-tr-03183-2@2.1.0.yaml +57 -0
  10. sbombox_core-0.1.0/src/sbombox_core/compliance/profiles/cisa-2025.yaml +56 -0
  11. sbombox_core-0.1.0/src/sbombox_core/compliance/profiles/cisa-2026.yaml +106 -0
  12. sbombox_core-0.1.0/src/sbombox_core/compliance/profiles/cra-readiness.yaml +56 -0
  13. sbombox_core-0.1.0/src/sbombox_core/compliance/profiles/fsct-v3.yaml +51 -0
  14. sbombox_core-0.1.0/src/sbombox_core/compliance/profiles/ntia-2021.yaml +42 -0
  15. sbombox_core-0.1.0/src/sbombox_core/compliance/profiles/openchain-telco.yaml +57 -0
  16. sbombox_core-0.1.0/src/sbombox_core/config/__init__.py +138 -0
  17. sbombox_core-0.1.0/src/sbombox_core/diff/__init__.py +156 -0
  18. sbombox_core-0.1.0/src/sbombox_core/enrich/__init__.py +335 -0
  19. sbombox_core-0.1.0/src/sbombox_core/errors.py +45 -0
  20. sbombox_core-0.1.0/src/sbombox_core/fix/__init__.py +191 -0
  21. sbombox_core-0.1.0/src/sbombox_core/generate/__init__.py +605 -0
  22. sbombox_core-0.1.0/src/sbombox_core/generate/image.py +252 -0
  23. sbombox_core-0.1.0/src/sbombox_core/model/__init__.py +99 -0
  24. sbombox_core-0.1.0/src/sbombox_core/model/common.py +234 -0
  25. sbombox_core-0.1.0/src/sbombox_core/model/component.py +195 -0
  26. sbombox_core-0.1.0/src/sbombox_core/model/dependency.py +45 -0
  27. sbombox_core-0.1.0/src/sbombox_core/model/metadata.py +192 -0
  28. sbombox_core-0.1.0/src/sbombox_core/model/results.py +245 -0
  29. sbombox_core-0.1.0/src/sbombox_core/model/sbom.py +231 -0
  30. sbombox_core-0.1.0/src/sbombox_core/model/service.py +139 -0
  31. sbombox_core-0.1.0/src/sbombox_core/model/vex.py +154 -0
  32. sbombox_core-0.1.0/src/sbombox_core/model/vulnerability.py +187 -0
  33. sbombox_core-0.1.0/src/sbombox_core/normalize/__init__.py +110 -0
  34. sbombox_core-0.1.0/src/sbombox_core/parse/__init__.py +234 -0
  35. sbombox_core-0.1.0/src/sbombox_core/parse/cyclonedx.py +319 -0
  36. sbombox_core-0.1.0/src/sbombox_core/parse/sniff.py +374 -0
  37. sbombox_core-0.1.0/src/sbombox_core/parse/spdx.py +1120 -0
  38. sbombox_core-0.1.0/src/sbombox_core/report/__init__.py +229 -0
  39. sbombox_core-0.1.0/src/sbombox_core/score/__init__.py +437 -0
  40. sbombox_core-0.1.0/src/sbombox_core/serialize/__init__.py +249 -0
  41. sbombox_core-0.1.0/src/sbombox_core/share/__init__.py +69 -0
  42. sbombox_core-0.1.0/src/sbombox_core/util/__init__.py +45 -0
  43. sbombox_core-0.1.0/src/sbombox_core/util/hashes.py +128 -0
  44. sbombox_core-0.1.0/src/sbombox_core/util/licenses.py +172 -0
  45. sbombox_core-0.1.0/src/sbombox_core/util/purl.py +108 -0
  46. sbombox_core-0.1.0/src/sbombox_core/validate/__init__.py +138 -0
  47. sbombox_core-0.1.0/src/sbombox_core/validate/schema.py +923 -0
  48. sbombox_core-0.1.0/src/sbombox_core/validate/semantic.py +350 -0
  49. sbombox_core-0.1.0/src/sbombox_core/vex/__init__.py +392 -0
  50. sbombox_core-0.1.0/tests/__init__.py +0 -0
  51. sbombox_core-0.1.0/tests/conftest.py +19 -0
  52. sbombox_core-0.1.0/tests/fixtures.py +423 -0
  53. sbombox_core-0.1.0/tests/test_api.py +254 -0
  54. sbombox_core-0.1.0/tests/test_builtin_generators.py +275 -0
  55. sbombox_core-0.1.0/tests/test_compliance.py +219 -0
  56. sbombox_core-0.1.0/tests/test_diff.py +163 -0
  57. sbombox_core-0.1.0/tests/test_enrich.py +263 -0
  58. sbombox_core-0.1.0/tests/test_fix.py +140 -0
  59. sbombox_core-0.1.0/tests/test_generate.py +209 -0
  60. sbombox_core-0.1.0/tests/test_generator_selection.py +43 -0
  61. sbombox_core-0.1.0/tests/test_image_generation.py +168 -0
  62. sbombox_core-0.1.0/tests/test_model.py +635 -0
  63. sbombox_core-0.1.0/tests/test_normalize.py +125 -0
  64. sbombox_core-0.1.0/tests/test_parse.py +403 -0
  65. sbombox_core-0.1.0/tests/test_score.py +145 -0
  66. sbombox_core-0.1.0/tests/test_serialize.py +94 -0
  67. sbombox_core-0.1.0/tests/test_util.py +314 -0
  68. sbombox_core-0.1.0/tests/test_validate.py +451 -0
  69. sbombox_core-0.1.0/tests/test_vex.py +168 -0
@@ -0,0 +1,40 @@
1
+ # --- Python ---
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ .Python
7
+ build/
8
+ develop-eggs/
9
+ dist/
10
+ downloads/
11
+ eggs/
12
+ .eggs/
13
+ lib/
14
+ lib64/
15
+ parts/
16
+ sdist/
17
+ var/
18
+ wheels/
19
+ *.egg-info/
20
+ .installed.cfg
21
+ *.egg
22
+ MANIFEST
23
+
24
+ # --- Virtual environments ---
25
+ .env
26
+ .env.*
27
+ !.env.example
28
+ .venv
29
+ env/
30
+ venv/
31
+ ENV/
32
+
33
+ # --- Tooling caches ---
34
+ .mypy_cache/
35
+ .ruff_cache/
36
+ .pytest_cache/
37
+ .coverage
38
+ reports/
39
+ release/
40
+ .DS_Store
@@ -0,0 +1,31 @@
1
+ Metadata-Version: 2.5
2
+ Name: sbombox-core
3
+ Version: 0.1.0
4
+ Summary: SBOMBox core library - parse, validate, score, and check compliance of SBOMs
5
+ Project-URL: Homepage, https://sbombox.com
6
+ Project-URL: Documentation, https://sbombox.com/docs/cli
7
+ Project-URL: Source, https://github.com/sbombox-hq/cli
8
+ Project-URL: Issues, https://github.com/sbombox-hq/cli/issues
9
+ Author-email: sia-sbombox <sia@sbombox.com>
10
+ Maintainer-email: sia-sbombox <sia@sbombox.com>
11
+ License-Expression: Apache-2.0
12
+ Requires-Python: >=3.12
13
+ Requires-Dist: httpx>=0.27
14
+ Requires-Dist: jsonschema>=4.20
15
+ Requires-Dist: license-expression>=30.0
16
+ Requires-Dist: lxml>=5.0
17
+ Requires-Dist: packageurl-python>=0.11
18
+ Requires-Dist: pydantic>=2.0
19
+ Requires-Dist: ruamel-yaml>=0.18
20
+ Requires-Dist: univers>=0.21
21
+ Provides-Extra: cyclonedx
22
+ Requires-Dist: cyclonedx-python-lib>=8.0; extra == 'cyclonedx'
23
+ Provides-Extra: dev
24
+ Requires-Dist: mypy>=1.10; extra == 'dev'
25
+ Requires-Dist: pytest-cov>=5.0; extra == 'dev'
26
+ Requires-Dist: pytest>=8.0; extra == 'dev'
27
+ Requires-Dist: ruff>=0.4; extra == 'dev'
28
+ Provides-Extra: sigstore
29
+ Requires-Dist: sigstore>=3.0; extra == 'sigstore'
30
+ Provides-Extra: spdx
31
+ Requires-Dist: spdx-tools>=0.8; extra == 'spdx'
@@ -0,0 +1,37 @@
1
+ [project]
2
+ name = "sbombox-core"
3
+ version = "0.1.0"
4
+ description = "SBOMBox core library - parse, validate, score, and check compliance of SBOMs"
5
+ requires-python = ">=3.12"
6
+ license = "Apache-2.0"
7
+ authors = [{ name = "sia-sbombox", email = "sia@sbombox.com" }]
8
+ maintainers = [{ name = "sia-sbombox", email = "sia@sbombox.com" }]
9
+ dependencies = [
10
+ "pydantic>=2.0",
11
+ "packageurl-python>=0.11",
12
+ "license-expression>=30.0",
13
+ "univers>=0.21",
14
+ "jsonschema>=4.20",
15
+ "ruamel.yaml>=0.18",
16
+ "lxml>=5.0",
17
+ "httpx>=0.27",
18
+ ]
19
+
20
+ [project.optional-dependencies]
21
+ sigstore = ["sigstore>=3.0"]
22
+ cyclonedx = ["cyclonedx-python-lib>=8.0"]
23
+ spdx = ["spdx-tools>=0.8"]
24
+ dev = ["pytest>=8.0", "pytest-cov>=5.0", "ruff>=0.4", "mypy>=1.10"]
25
+
26
+ [project.urls]
27
+ Homepage = "https://sbombox.com"
28
+ Documentation = "https://sbombox.com/docs/cli"
29
+ Source = "https://github.com/sbombox-hq/cli"
30
+ Issues = "https://github.com/sbombox-hq/cli/issues"
31
+
32
+ [build-system]
33
+ requires = ["hatchling"]
34
+ build-backend = "hatchling.build"
35
+
36
+ [tool.hatch.build.targets.wheel]
37
+ packages = ["src/sbombox_core"]
File without changes
@@ -0,0 +1,162 @@
1
+ """SBOMBox Core - parse, validate, score, and check compliance of SBOMs.
2
+
3
+ This package is the shared foundation for both the ``sbombox`` CLI and the API
4
+ server. It deliberately has no framework dependencies - no Django, no Typer, no
5
+ HTTP client in the import path - so it can be embedded anywhere, and every
6
+ operation is offline: a document is never fetched, and no schema is downloaded.
7
+
8
+ The public surface is intentionally small::
9
+
10
+ from sbombox_core import load, validate_sbom
11
+
12
+ sbom = load("bom.json") # path, bytes or text; format auto-detected
13
+ report = validate_sbom(sbom) # semantic findings, never raises
14
+
15
+ Callers that need finer control can drop a level: :func:`parse_sbom` for the
16
+ parser, :func:`validate_document` for both validation layers over a raw
17
+ document, and :mod:`sbombox_core.model` for the data model itself.
18
+ """
19
+
20
+ from __future__ import annotations
21
+
22
+ from pathlib import Path
23
+
24
+ from sbombox_core.compliance import check_compliance
25
+ from sbombox_core.diff import diff
26
+ from sbombox_core.errors import (
27
+ MalformedDocumentError,
28
+ SbomboxError,
29
+ SbomParseError,
30
+ SbomValidationError,
31
+ UnsupportedFormatError,
32
+ )
33
+ from sbombox_core.fix import fix
34
+ from sbombox_core.model import (
35
+ ComplianceResult,
36
+ Component,
37
+ DiffResult,
38
+ FixResult,
39
+ Sbom,
40
+ SbomFormat,
41
+ ScoreResult,
42
+ )
43
+ from sbombox_core.normalize import normalize
44
+ from sbombox_core.parse import parse_sbom, read_sbom_file
45
+ from sbombox_core.score import score
46
+ from sbombox_core.validate import (
47
+ ValidationResult,
48
+ validate_document,
49
+ validate_sbom,
50
+ )
51
+
52
+ #: Kept in step with ``[project].version`` in ``pyproject.toml``. A literal
53
+ #: rather than ``importlib.metadata`` so the value is still correct when the
54
+ #: package is imported straight from a source tree.
55
+ __version__ = "0.1.0"
56
+
57
+ __all__ = [
58
+ "Component",
59
+ "ComplianceResult",
60
+ "DiffResult",
61
+ "FixResult",
62
+ "MalformedDocumentError",
63
+ "PathOrContent",
64
+ "Sbom",
65
+ "SbomFormat",
66
+ "SbomParseError",
67
+ "SbomValidationError",
68
+ "SbomboxError",
69
+ "ScoreResult",
70
+ "UnsupportedFormatError",
71
+ "ValidationResult",
72
+ "__version__",
73
+ "check_compliance",
74
+ "diff",
75
+ "fix",
76
+ "load",
77
+ "normalize",
78
+ "parse_sbom",
79
+ "read_sbom_file",
80
+ "score",
81
+ "validate_document",
82
+ "validate_sbom",
83
+ ]
84
+
85
+ #: What :func:`load` accepts: a filesystem path, or the document itself.
86
+ type PathOrContent = str | bytes | bytearray | Path
87
+
88
+ #: Extensions that identify a file as an SBOM without opening it.
89
+ _SBOM_SUFFIXES = frozenset({".json", ".jsonld", ".xml", ".rdf", ".yaml", ".yml", ".spdx", ".tv", ".bom"})
90
+
91
+ #: Anything longer than this is a document, not a filename.
92
+ _MAX_PATH_LENGTH = 4096
93
+
94
+
95
+ def load(path_or_content: PathOrContent, format: str | SbomFormat | None = None) -> Sbom: # noqa: A002
96
+ """Load an SBOM from a file path, raw bytes, or document text.
97
+
98
+ The specification (CycloneDX or SPDX) and the serialisation (JSON, XML,
99
+ YAML or SPDX tag-value) are both detected from the content, so the same
100
+ call handles every document SBOMBox can read.
101
+
102
+ Args:
103
+ path_or_content: A filesystem path, or the document itself as ``bytes``
104
+ or ``str``. A ``str`` is treated as a path when it looks like one
105
+ - see :func:`_is_path_like` - and as content otherwise.
106
+ format: Optional format hint, ``"cyclonedx"`` or ``"spdx"``. Useful for
107
+ documents delivered without a name whose container is ambiguous.
108
+ A hint that contradicts the content is an error, not a fallback:
109
+ silently parsing SPDX as CycloneDX would produce an empty inventory
110
+ that looks valid.
111
+
112
+ Returns:
113
+ The parsed :class:`~sbombox_core.model.Sbom`.
114
+
115
+ Raises:
116
+ TypeError: if *path_or_content* is none of the accepted types.
117
+ SbomParseError: if the file cannot be read.
118
+ UnsupportedFormatError: if the content is not a recognised SBOM.
119
+ MalformedDocumentError: if it is a recognised serialisation that is
120
+ broken (truncated JSON, ill-formed XML).
121
+ """
122
+ if isinstance(path_or_content, Path):
123
+ return read_sbom_file(path_or_content)
124
+
125
+ if isinstance(path_or_content, (bytes, bytearray)):
126
+ return parse_sbom(bytes(path_or_content), format=format)
127
+
128
+ if isinstance(path_or_content, str):
129
+ text = path_or_content
130
+ if _is_path_like(text):
131
+ return read_sbom_file(text)
132
+ return parse_sbom(text, format=format)
133
+
134
+ raise TypeError(f"load() expects a path, bytes or str, got {type(path_or_content).__name__}")
135
+
136
+
137
+ def _is_path_like(text: str) -> bool:
138
+ """Decide whether a ``str`` argument names a file rather than holds a document.
139
+
140
+ Every serialisation SBOMBox reads starts with markup - ``{`` for JSON, ``<``
141
+ for XML - or spans several lines, and no plausible filename does either.
142
+ What survives that filter is settled by a known SBOM extension, then by the
143
+ shape of the string, then by the filesystem, so ``load("bom.json")`` and
144
+ ``load("out/bom")`` both report a missing file rather than a mysterious
145
+ parse error, while ``load(handle.read())`` parses the text.
146
+ """
147
+ candidate = text.strip()
148
+ if not candidate or len(candidate) > _MAX_PATH_LENGTH:
149
+ return False
150
+ if "\n" in candidate or "\r" in candidate or "\x00" in candidate:
151
+ return False
152
+ if candidate[0] in "{<[":
153
+ return False
154
+
155
+ path = Path(candidate)
156
+ if path.suffix.lower() in _SBOM_SUFFIXES:
157
+ return True
158
+ # A dotted or relative/absolute name is a path even when it has no SBOM
159
+ # extension and does not exist yet - the caller meant a file.
160
+ if len(path.parts) > 1 or candidate[0] in ".~":
161
+ return True
162
+ return path.is_file()