@@ -68,7 +68,7 @@ main = do
68
68
69
69
exitSuccess
70
70
71
- data Category = CodeExecution | CryptoFailure | PrivilegeEscalation | DOS | FileDisclosure | FormatInjection | MemoryCorruption | MemoryExposure
71
+ newtype CWE = CWE { unCWE :: Integer }
72
72
deriving (Show )
73
73
74
74
data Architecture = AArch64 | Alpha | Arm | HPPA | HPPA1_1 | I386 | IA64 | M68K | MIPS | MIPSEB | MIPSEL | NIOS2 | PowerPC | PowerPC64 | PowerPC64LE | RISCV32 | RISCV64 | RS6000 | S390 | S390X | SH4 | SPARC | SPARC64 | VAX | X86_64
@@ -89,7 +89,7 @@ data Advisory = Advisory
89
89
advisoryPackage :: Text ,
90
90
advisoryDate :: Date ,
91
91
advisoryUrl :: Text ,
92
- advisoryCategories :: [Category ],
92
+ advisoryCWEs :: [CWE ],
93
93
advisoryKeywords :: [Keyword ],
94
94
advisoryAliases :: [Text ],
95
95
advisoryCVSS :: Maybe Text ,
@@ -112,7 +112,7 @@ renderAdvisory adv =
112
112
row " Package" advisoryPackage,
113
113
row " Date" (date . advisoryDate),
114
114
row " URL" advisoryUrl,
115
- row " Categories " (T. intercalate " , " . map (T. pack . show ) . advisoryCategories ),
115
+ row " CWEs " (T. intercalate " , " . map (T. pack . show . unCWE ) . advisoryCWEs ),
116
116
row " Keywords" (T. intercalate " , " . map (T. pack . show ) . advisoryKeywords),
117
117
row " Aliases" (T. intercalate " , " . advisoryAliases),
118
118
row " CVSS" (fromMaybe " " . advisoryCVSS),
@@ -139,7 +139,7 @@ parseAdvisory table = runTableParser $ do
139
139
package <- mandatory advisory " package" isString
140
140
date <- mandatory advisory " date" isDate <&> uncurry3 Date . toGregorian
141
141
url <- mandatory advisory " url" isString
142
- cats <- fromMaybe [] <$> optional advisory " categories " (isArrayOf (isString >=> category ))
142
+ cats <- fromMaybe [] <$> optional advisory " cwe " (isArrayOf (fmap CWE . isInt ))
143
143
kwds <- fromMaybe [] <$> optional advisory " keywords" (isArrayOf (fmap Keyword . isString))
144
144
aliases <- fromMaybe [] <$> optional advisory " aliases" (isArrayOf isString)
145
145
cvss <- optional advisory " cvss" isString
@@ -162,7 +162,7 @@ parseAdvisory table = runTableParser $ do
162
162
advisoryPackage = package,
163
163
advisoryDate = date,
164
164
advisoryUrl = url,
165
- advisoryCategories = cats,
165
+ advisoryCWEs = cats,
166
166
advisoryKeywords = kwds,
167
167
advisoryAliases = aliases,
168
168
advisoryCVSS = cvss,
@@ -176,17 +176,6 @@ parseAdvisory table = runTableParser $ do
176
176
uncurry3 :: (a -> b -> c -> d ) -> (a , b , c ) -> d
177
177
uncurry3 f (x, y, z) = f x y z
178
178
179
- category :: Text -> TableParser Category
180
- category " code-execution" = pure CodeExecution
181
- category " crypto-failure" = pure CryptoFailure
182
- category " denial-of-service" = pure DOS
183
- category " file-disclosure" = pure FileDisclosure
184
- category " format-injection" = pure FormatInjection
185
- category " memory-corruption" = pure MemoryCorruption
186
- category " memory-exposure" = pure MemoryExposure
187
- category " privilege-escalation" = pure PrivilegeEscalation
188
- category other = throwError $ InvalidCategory other
189
-
190
179
operatingSystem :: Text -> TableParser OS
191
180
operatingSystem " darwin" = pure MacOS
192
181
operatingSystem " freebsd" = pure FreeBSD
@@ -236,7 +225,6 @@ data TableParseErr
236
225
= UnexpectedKeys (NonEmpty Text )
237
226
| MissingKey Text
238
227
| InvalidFormat Text Text
239
- | InvalidCategory Text
240
228
| InvalidOS Text
241
229
| InvalidArchitecture Text
242
230
| UnderlyingParserError Text
@@ -263,6 +251,10 @@ mandatory tbl k act = onKey tbl k (throwError $ MissingKey k) act
263
251
onKey :: TOML. Table -> Text -> TableParser a -> (TOML. Value -> TableParser a ) -> TableParser a
264
252
onKey tbl k absent present = maybe absent present $ Map. lookup k tbl
265
253
254
+ isInt :: TOML. Value -> TableParser Integer
255
+ isInt (TOML. Integer i) = pure i
256
+ isInt other = throwError $ InvalidFormat " Integer" (describeValue other)
257
+
266
258
isString :: TOML. Value -> TableParser Text
267
259
isString (TOML. String txt) = pure txt
268
260
isString other = throwError $ InvalidFormat " String" (describeValue other)
0 commit comments