Skip to main content

ruso_runtime/
contract.rs

1//! Shared types embedded in Ruso bytecode (constant pools and probe specs).
2//!
3//! `ruso-script` parses source into an AST that uses these types for matchers,
4//! bodies, and metadata so compiled output matches what `ruso-runtime` executes.
5
6#[derive(Debug, Clone, PartialEq)]
7pub enum Severity {
8    Low,
9    Medium,
10    High,
11    Critical,
12    Info,
13}
14
15impl Severity {
16    pub fn as_str(&self) -> &'static str {
17        match self {
18            Self::Low => "low",
19            Self::Medium => "medium",
20            Self::High => "high",
21            Self::Critical => "critical",
22            Self::Info => "info",
23        }
24    }
25}
26
27#[derive(Debug, Clone, PartialEq)]
28pub enum HttpMethod {
29    Get,
30    Post,
31    Put,
32    Patch,
33    Delete,
34    Head,
35    Options,
36}
37
38#[derive(Debug, Clone, PartialEq)]
39pub struct ObjectBody {
40    pub pairs: Vec<(String, BodyValue)>,
41}
42
43#[derive(Debug, Clone, PartialEq)]
44pub enum BodyValue {
45    String(String),
46    Interpolation(String),
47    Object(ObjectBody),
48    Bytes(String),
49    Part(InlinePart),
50}
51
52#[derive(Debug, Clone, PartialEq)]
53pub struct InlinePart {
54    pub filename: Option<String>,
55    pub body: InlinePartBody,
56}
57
58#[derive(Debug, Clone, PartialEq)]
59pub enum InlinePartBody {
60    Text(String),
61    Bytes(String),
62}
63
64#[derive(Debug, Clone, PartialEq)]
65pub struct QualifiedField {
66    pub target: String,
67    pub kind: FieldKind,
68}
69
70#[derive(Debug, Clone, PartialEq)]
71pub enum FieldKind {
72    Status,
73    Body,
74    Header(String),
75    ResponseTime,
76    ResponseSize,
77    /// Resolver answers (`dns` without `port` / `payload`).
78    Answer,
79    /// Raw probe bytes (tcp / udp / wire dns). Alias: `banner` in scripts.
80    Response,
81    Banner,
82}
83
84#[derive(Debug, Clone, PartialEq)]
85pub struct QualifiedMatch {
86    pub field: QualifiedField,
87    pub predicate: MatchPredicate,
88}
89
90#[derive(Debug, Clone, PartialEq)]
91pub enum MatchPredicate {
92    Compare { op: CmpOp, value: CmpValue },
93    Contains(String),
94    NotContains(String),
95    Regex(String),
96}
97
98#[derive(Debug, Clone, PartialEq)]
99pub enum ExtractSource {
100    Body {
101        target: String,
102        regex: Option<String>,
103    },
104    Header {
105        target: String,
106        name: String,
107    },
108}
109
110#[derive(Debug, Clone, PartialEq)]
111pub enum EvidenceKind {
112    /// HTTP probe response body (truncated).
113    BodyRef(String),
114    /// Probe response text: HTTP body, DNS answers, or socket data (truncated).
115    ResponseRef(String),
116    Regex {
117        target: String,
118        pattern: String,
119    },
120}
121
122#[derive(Debug, Clone, Copy, PartialEq)]
123pub enum CmpOp {
124    Eq,
125    Ne,
126    Lt,
127    Gt,
128    Le,
129    Ge,
130}
131
132#[derive(Debug, Clone, PartialEq)]
133pub enum CmpValue {
134    Number(u64),
135    String(String),
136    Duration(String),
137}