File tree Expand file tree Collapse file tree 4 files changed +12
-8
lines changed Expand file tree Collapse file tree 4 files changed +12
-8
lines changed Original file line number Diff line number Diff line change 1
1
tested-with : GHC== 9.2.5
2
2
3
- packages : *.cabal
3
+ packages : *.cabal ../cwe/cwe.cabal
4
4
5
5
package hsec-tools
Original file line number Diff line number Diff line change @@ -50,8 +50,9 @@ library
50
50
aeson >= 2.0.1.0 && < 3 ,
51
51
pandoc-types >= 1.22 && < 2 ,
52
52
parsec >= 3 && < 4 ,
53
- commonmark-pandoc >= 0.2 && < 0.3
54
- , safe >= 0.3
53
+ commonmark-pandoc >= 0.2 && < 0.3 ,
54
+ safe >= 0.3 ,
55
+ cwe >= 0.1 && < 2 ,
55
56
hs-source-dirs : src
56
57
default-language : Haskell2010
57
58
ghc-options : -Wall
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ module Security.Advisories.Definition
12
12
)
13
13
where
14
14
15
+ import CWE (CWEID )
15
16
import Data.Text (Text )
16
17
import Data.Time (ZonedTime )
17
18
import Distribution.Types.VersionRange (VersionRange )
@@ -25,7 +26,7 @@ data Advisory = Advisory
25
26
{ advisoryId :: HsecId
26
27
, advisoryModified :: ZonedTime
27
28
, advisoryPublished :: ZonedTime
28
- , advisoryCWEs :: [CWE ]
29
+ , advisoryCWEs :: [CWEID ]
29
30
, advisoryKeywords :: [Keyword ]
30
31
, advisoryAliases :: [Text ]
31
32
, advisoryRelated :: [Text ]
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ module Security.Advisories.Parse
17
17
)
18
18
where
19
19
20
+ import qualified CWE
20
21
import Control.Monad ((>=>) )
21
22
import Data.Bifunctor (first )
22
23
import Data.Foldable (toList )
@@ -172,7 +173,7 @@ parseAdvisoryTable oob policy table doc summary details html = runTableParser $
172
173
173
174
cats <-
174
175
fromMaybe []
175
- <$> optional advisory " cwe" (isArrayOf (fmap CWE . isInt ))
176
+ <$> optional advisory " cwe" (isArrayOf (isCWE ))
176
177
kwds <-
177
178
fromMaybe []
178
179
<$> optional advisory " keywords" (isArrayOf (fmap Keyword . isString))
@@ -417,9 +418,10 @@ onKey ::
417
418
onKey tbl k absent present =
418
419
maybe absent present $ Map. lookup k tbl
419
420
420
- isInt :: TOML. Value -> TableParser Integer
421
- isInt (TOML. Integer i) = pure i
422
- isInt other = throwError $ InvalidFormat " Integer" (describeValue other) " 42"
421
+ isCWE :: TOML. Value -> TableParser CWE. CWEID
422
+ isCWE (TOML. Integer i) | Just cwe <- CWE. mkCWEID i, Map. member cwe CWE. cweNames = pure cwe
423
+ isCWE (TOML. String txt) | Just cwe <- Map. lookup txt CWE. cweIds = pure cwe
424
+ isCWE other = throwError $ InvalidFormat " Integer" (describeValue other) " 42"
423
425
424
426
isString :: TOML. Value -> TableParser T. Text
425
427
isString (TOML. String txt) = pure txt
You can’t perform that action at this time.
0 commit comments