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 11tested-with : GHC== 9.2.5
22
3- packages : *.cabal
3+ packages : *.cabal ../cwe/cwe.cabal
44
55package hsec-tools
Original file line number Diff line number Diff line change @@ -50,8 +50,9 @@ library
5050 aeson >= 2.0.1.0 && < 3 ,
5151 pandoc-types >= 1.22 && < 2 ,
5252 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 ,
5556 hs-source-dirs : src
5657 default-language : Haskell2010
5758 ghc-options : -Wall
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ module Security.Advisories.Definition
1212 )
1313 where
1414
15+ import CWE (CWEID )
1516import Data.Text (Text )
1617import Data.Time (ZonedTime )
1718import Distribution.Types.VersionRange (VersionRange )
@@ -25,7 +26,7 @@ data Advisory = Advisory
2526 { advisoryId :: HsecId
2627 , advisoryModified :: ZonedTime
2728 , advisoryPublished :: ZonedTime
28- , advisoryCWEs :: [CWE ]
29+ , advisoryCWEs :: [CWEID ]
2930 , advisoryKeywords :: [Keyword ]
3031 , advisoryAliases :: [Text ]
3132 , advisoryRelated :: [Text ]
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ module Security.Advisories.Parse
1717 )
1818 where
1919
20+ import qualified CWE
2021import Control.Monad ((>=>) )
2122import Data.Bifunctor (first )
2223import Data.Foldable (toList )
@@ -172,7 +173,7 @@ parseAdvisoryTable oob policy table doc summary details html = runTableParser $
172173
173174 cats <-
174175 fromMaybe []
175- <$> optional advisory " cwe" (isArrayOf (fmap CWE . isInt ))
176+ <$> optional advisory " cwe" (isArrayOf (isCWE ))
176177 kwds <-
177178 fromMaybe []
178179 <$> optional advisory " keywords" (isArrayOf (fmap Keyword . isString))
@@ -417,9 +418,10 @@ onKey ::
417418onKey tbl k absent present =
418419 maybe absent present $ Map. lookup k tbl
419420
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"
423425
424426isString :: TOML. Value -> TableParser T. Text
425427isString (TOML. String txt) = pure txt
You can’t perform that action at this time.
0 commit comments