Перейти к содержанию

English fallback

This translation is missing; the canonical English reference follows.

fuzzy1337.intelligence_cvss2_base

Experimental pure CVSS 2 base calculation accepts only original immutable CveCvss2Statements, retaining the source inspection once with a separate ordered frozen calculation per assessment. Each value has its assessment position, algorithm cvss2-base-2.10 and integer score in tenths; the public constructor accepts no calculated fields. DisplayScore() renders exactly one decimal digit.

Exact integer arithmetic implements FIRST equation 2.10 with final rounding only, an explicit zero-impact branch, and no intermediate rounding or impact clamping. Source vectors, asserted scores, context and snapshot bytes remain unchanged. Optional metrics do not create temporal/environmental results. No source correction, severity conversion, target matching, network execution or publisher authentication follows.

docs/INTELLIGENCE_CVSS2_BASE.md and ADR 0107 define the bounded calculation contract, finite-domain rounding evidence and separate source/derived output.

fuzzy1337.intelligence_cvss2_base

Derive immutable CVSS 2 base scores separately from unchanged source assertions.

BaseCalculation dataclass

Keep one internally derived value linked only by its source assessment position.

Source code in fuzzy1337/intelligence_cvss2_base.py
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
@dataclass(frozen=True, slots=True)
class BaseCalculation:
    """Keep one internally derived value linked only by its source assessment position."""

    assessment_index: int
    base_score_tenths: int
    algorithm: str = field(init=False, default="cvss2-base-2.10")

    def DisplayScore(self) -> str:
        """Render exact integer tenths without floating-point or Decimal conversion.

        Returns:
            Score with exactly one decimal digit, including 0.0 and 10.0.
        """

        return f"{self.base_score_tenths // 10}.{self.base_score_tenths % 10}"

    def ToDict(self) -> dict[str, object]:
        """Return a detached derived value without repeating source assertions.

        Returns:
            Assessment position, algorithm identifier and integer score in tenths.
        """

        return {"assessment_index": self.assessment_index, "algorithm": self.algorithm,
                "base_score_tenths": self.base_score_tenths}

DisplayScore() -> str

Render exact integer tenths without floating-point or Decimal conversion.

Returns:

Type Description
str

Score with exactly one decimal digit, including 0.0 and 10.0.

Source code in fuzzy1337/intelligence_cvss2_base.py
70
71
72
73
74
75
76
77
def DisplayScore(self) -> str:
    """Render exact integer tenths without floating-point or Decimal conversion.

    Returns:
        Score with exactly one decimal digit, including 0.0 and 10.0.
    """

    return f"{self.base_score_tenths // 10}.{self.base_score_tenths % 10}"

ToDict() -> dict[str, object]

Return a detached derived value without repeating source assertions.

Returns:

Type Description
dict[str, object]

Assessment position, algorithm identifier and integer score in tenths.

Source code in fuzzy1337/intelligence_cvss2_base.py
79
80
81
82
83
84
85
86
87
def ToDict(self) -> dict[str, object]:
    """Return a detached derived value without repeating source assertions.

    Returns:
        Assessment position, algorithm identifier and integer score in tenths.
    """

    return {"assessment_index": self.assessment_index, "algorithm": self.algorithm,
            "base_score_tenths": self.base_score_tenths}

CveCvss2BaseCalculations dataclass

Compute Experimental base-only values while retaining original typed statements once.

Parameters:

Name Type Description Default
statements CveCvss2Statements

Original immutable source inspection; no raw input or score coercion occurs.

required

Raises:

Type Description
ValueError

Input is not a typed CveCvss2Statements value.

Calculation is pure. Source scores, snapshot bytes, provider/scenario contexts and their positions remain unchanged. No applicability, severity or source-correction verdict follows. Computed fields are not constructor arguments. Direct source construction retains the original inspection API's limit: it cannot independently prove derivation from raw bytes.

Source code in fuzzy1337/intelligence_cvss2_base.py
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
@dataclass(frozen=True, slots=True)
class CveCvss2BaseCalculations:
    """Compute Experimental base-only values while retaining original typed statements once.

    Args:
        statements: Original immutable source inspection; no raw input or score coercion occurs.

    Raises:
        ValueError: Input is not a typed CveCvss2Statements value.

    Calculation is pure. Source scores, snapshot bytes, provider/scenario contexts and their
    positions remain unchanged. No applicability, severity or source-correction verdict follows.
    Computed fields are not constructor arguments. Direct source construction retains the
    original inspection API's limit: it cannot independently prove derivation from raw bytes.
    """

    statements: CveCvss2Statements
    calculations: tuple[BaseCalculation, ...] = field(init=False)

    def __post_init__(self) -> None:
        """Require typed statements and derive one immutable value per assessment in order."""

        if not isinstance(self.statements, CveCvss2Statements):
            raise ValueError("CVSS 2 base calculation requires typed source statements")

        calculations = tuple(
            BaseCalculation(index, BaseScoreTenths(assessment))
            for index, assessment in enumerate(self.statements.assessments)
        )
        object.__setattr__(self, "calculations", calculations)

    def ToDict(self) -> dict[str, object]:
        """Return detached source inspection once and a separate ordered calculation array.

        Returns:
            Unchanged statements and computed-only base values; no persisted decoder is defined.
        """

        return {"statements": self.statements.ToDict(),
                "calculations": [calculation.ToDict() for calculation in self.calculations]}

__post_init__() -> None

Require typed statements and derive one immutable value per assessment in order.

Source code in fuzzy1337/intelligence_cvss2_base.py
109
110
111
112
113
114
115
116
117
118
119
def __post_init__(self) -> None:
    """Require typed statements and derive one immutable value per assessment in order."""

    if not isinstance(self.statements, CveCvss2Statements):
        raise ValueError("CVSS 2 base calculation requires typed source statements")

    calculations = tuple(
        BaseCalculation(index, BaseScoreTenths(assessment))
        for index, assessment in enumerate(self.statements.assessments)
    )
    object.__setattr__(self, "calculations", calculations)

ToDict() -> dict[str, object]

Return detached source inspection once and a separate ordered calculation array.

Returns:

Type Description
dict[str, object]

Unchanged statements and computed-only base values; no persisted decoder is defined.

Source code in fuzzy1337/intelligence_cvss2_base.py
121
122
123
124
125
126
127
128
129
def ToDict(self) -> dict[str, object]:
    """Return detached source inspection once and a separate ordered calculation array.

    Returns:
        Unchanged statements and computed-only base values; no persisted decoder is defined.
    """

    return {"statements": self.statements.ToDict(),
            "calculations": [calculation.ToDict() for calculation in self.calculations]}

BaseScoreTenths(assessment: CveCvss2Assessment) -> int

Evaluate FIRST equation 2.10 exactly, rounding only the final number of tenths.

Parameters:

Name Type Description Default
assessment CveCvss2Assessment

Already validated immutable source metric containing all six base tokens.

required

Returns:

Type Description
int

Integer tenths in 0..100, independent of optional metrics and asserted scores.

Source code in fuzzy1337/intelligence_cvss2_base.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
def BaseScoreTenths(assessment: CveCvss2Assessment) -> int:
    """Evaluate FIRST equation 2.10 exactly, rounding only the final number of tenths.

    Args:
        assessment: Already validated immutable source metric containing all six base tokens.

    Returns:
        Integer tenths in 0..100, independent of optional metrics and asserted scores.
    """

    cvss = cast(Mapping[str, object], assessment.metric["cvssV2_0"])
    vector = cast(str, cvss["vectorString"])
    tokens = dict(component.split(":") for component in vector.split("/"))
    remaining_impact = (
        (_WEIGHT_SCALE - _IMPACT[tokens["C"]])
        * (_WEIGHT_SCALE - _IMPACT[tokens["I"]])
        * (_WEIGHT_SCALE - _IMPACT[tokens["A"]])
    )
    impact_numerator = 1041 * (_PRODUCT_DENOMINATOR - remaining_impact)

    if impact_numerator == 0:
        return 0

    exploitability_numerator = 20 * _AV[tokens["AV"]] * _AC[tokens["AC"]] * _AU[tokens["Au"]]
    # Impact has denominator 100*1000^3; exploitability has denominator 1000^3.
    # Multiplication by ten for tenths cancels the base expression's factor 1/10.
    base_tenths_numerator = (
        6 * impact_numerator + 4 * 100 * exploitability_numerator - 15 * _IMPACT_DENOMINATOR
    ) * 1176
    base_tenths_denominator = _IMPACT_DENOMINATOR * 1000
    quotient, remainder = divmod(base_tenths_numerator, base_tenths_denominator)

    # The complete valid six-token domain has no exact final half-tenth ties.
    return quotient + int(2 * remainder > base_tenths_denominator)