class

CWE::Catalog

Inherits Reference < Object

The in-memory CWE catalog.

The default instance (CWE::Catalog.default) is built once from the JSON blob embedded at compile time and cached for the life of the process. All CWE.find, CWE.search, etc. helpers route through this default catalog.

Constructing your own Catalog (e.g. from a different JSON file or a filtered subset) is supported but rarely necessary — the embedded blob is sourced from the MITRE CWE Research view (view 1000), which is the comprehensive set.

Constants

EMBEDDED_JSON = {{ read_file("/tmp/tmp.ebBKin/src/src/cwe/data/weaknesses.json") }}

Embedded source data. Loaded at compile time so the resulting binary is self-contained — no I/O is required to look up any CWE entry.

Constructors

default

The catalog backed by the embedded MITRE data. Built on first access; subsequent calls return the cached instance. Thread-safe — concurrent first calls won't race on the lazy parse.

Source
from_json(input : String | IO) : Catalog

Build a Catalog from a JSON document with the schema produced by data/build_data.cr. Useful for testing and for callers that ship their own subset.

Source
new(catalog_version : String, generated_at : String, weaknesses : Array(Weakness), categories : Array(Category) = [] of Category, views : Array(View) = [] of View, external_references : Array(ExternalReference) = [] of ExternalReference)
Source

Instance methods

[](id : Int) : Weakness

Catalog[X] syntax — same as find!.

Source
[](id : String) : Weakness
Source
[]?(id : Int) : Weakness | Nil

Catalog[X]? syntax — same as find.

Source
[]?(id : String) : Weakness | Nil
Source
all

All weaknesses, sorted by numeric id.

Returns a fresh array on each call — the catalog's own storage is never handed out, so a caller is free to sort/reject/clear the result without corrupting the catalog. Use each to iterate without the copy.

Source
all_categories

All categories, sorted by numeric id. Fresh array on each call, as all.

Source
all_views

All views, sorted by numeric id. Fresh array on each call, as all.

Source
ancestors_of(id : Int, view_id : Int | Nil = nil, max_depth : Int = 32) : Array(Weakness)

All ancestors (transitive closure of ChildOf), nearest first. max_depth guards against pathological catalogs; the real CWE has chains of length 3-4. view_id filters edges to a single CWE view.

Source
ancestors_of(id : String, view_id : Int | Nil = nil, max_depth : Int = 32) : Array(Weakness)
Source
catalog_version

The MITRE catalog version string, e.g. "4.20", or "unknown" if the build script was not given a sibling XML to read it from.

Source
category(id : Int) : Category | Nil
Source
category(id : String) : Category | Nil
Source
category!(id : Int) : Category
Source
category!(id : String) : Category
Source
category_count

Number of categories in the catalog (0 if the build was CSV-only).

Source
children_of(id : Int, view_id : Int | Nil = nil) : Array(Weakness)

Direct children of id. Resolved via the pre-built children index in O(children); when view_id is given, only children whose ChildOf edge belongs to that view are returned. The returned array is a copy of the index bucket, so mutating it does not disturb the catalog.

Source
children_of(id : String, view_id : Int | Nil = nil) : Array(Weakness)
Source
descendants_of(id : Int, view_id : Int | Nil = nil, max_depth : Int = 32) : Array(Weakness)

All descendants (transitive closure of children), nearest first.

Source
descendants_of(id : String, view_id : Int | Nil = nil, max_depth : Int = 32) : Array(Weakness)
Source
each

Iterate over all entries in numeric-id order.

Source
entry(id : Int) : Weakness | Category | View | Nil

Look up any entry by id — returns a Weakness, Category, or View (in that order of preference). Useful when you don't know up front which kind of CWE entity a given id refers to.

Source
entry(id : String) : Weakness | Category | View | Nil
Source
external_reference(id : String) : ExternalReference | Nil

Resolve a Reference_ID such as "REF-2" to its full citation. Returns nil if the id is not in the registry. The REF- prefix is optional and case-insensitive, so "REF-2", "ref-2" and "2" are equivalent.

Source
external_reference!(id : String) : ExternalReference
Source
external_reference_count

Number of catalog-level external references.

Source
external_references

All catalog-level external references (citations), in Reference_ID order (REF-1, REF-2, … REF-10, …).

Source
find(id : Int) : Weakness | Nil

Find by integer id. Returns nil if not found.

Source
find(id : String) : Weakness | Nil

Find by "CWE-79" / "cwe-79" / "79". Returns nil if the string does not parse as a CWE id or the id is not in the catalog.

Source
find!(id : Int) : Weakness

Bang variants — raise NotFoundError on miss.

Source
find!(id : String) : Weakness
Source
generated_at

ISO-8601 UTC timestamp at which the embedded blob was generated.

Source
includes?(id : Int) : Bool
Source
includes?(id : String) : Bool
Source
members_of(id : Int) : Array(Weakness)

Member weaknesses (resolved) of a category or view. Members that reference Categories or Views (rare nesting) are skipped — use Category#members / View#members for the raw edge list.

Source
members_of(id : String) : Array(Weakness)
Source
parents_of(id : Int, view_id : Int | Nil = nil) : Array(Weakness)

Direct parents of id per the catalog's ChildOf edges. When view_id is given, only edges declared in that CWE view are returned (CWE catalog records the same parent twice when it appears in multiple views — view 1000 vs 1003 most commonly).

Source
parents_of(id : String, view_id : Int | Nil = nil) : Array(Weakness)

String-id forms of the traversal API, so callers holding a "CWE-79" can walk the hierarchy without converting first — the same way find, category, view and entry already accept either form. An id that does not parse is a miss, not an error.

Source
pillar_of(id : Int) : Weakness | Nil

The pillar (top-level entry) reached by walking ChildOf edges from id. Returns the entry itself if it is already a Pillar. Returns nil if id is not in the catalog. If the ancestor chain contains a Pillar, that is returned; otherwise the most distant ancestor is returned (some chains topple out at a Class rather than a Pillar).

Source
pillar_of(id : String) : Weakness | Nil
Source
search(query : String) : Array(Weakness)

Case-insensitive substring search over name + description + extended description + alternate terms. Returns matches in id order.

Source
search_by_name(query : String) : Array(Weakness)

Like search but returns only entries with at least one hit in the name field. Useful when callers want strong matches only.

Source
size

Number of entries in the catalog.

Source
view(id : Int) : View | Nil
Source
view(id : String) : View | Nil
Source
view!(id : Int) : View
Source
view!(id : String) : View
Source
view_count
Source
with_abstraction(level : Abstraction) : Array(Weakness)
Source
with_status(status : Status) : Array(Weakness)
Source