cve (empty) → 0.1.0.0
raw patch · 5 files changed
+116/−0 lines, 5 filesdep +aesondep +basedep +textsetup-changed
Dependencies added: aeson, base, text
Files
- ChangeLog.md +5/−0
- Data/Cve.hs +54/−0
- LICENSE +30/−0
- Setup.hs +2/−0
- cve.cabal +25/−0
+ ChangeLog.md view
@@ -0,0 +1,5 @@+# Revision history for cve++## 0.1.0.0 -- YYYY-mm-dd++* First version. Released on an unsuspecting world.
+ Data/Cve.hs view
@@ -0,0 +1,54 @@+{-# LANGUAGE OverloadedStrings #-}++module Data.Cve+ ( Cve(..)+ , encode+ , decode+ ) where++import Data.Text (Text)+import qualified Data.Text as T+import qualified Data.Text.Read as TR+import qualified Data.Aeson as AE++data Cve = Cve+ { cveYear :: {-# UNPACK #-} !Word+ , cveSequence :: {-# UNPACK #-} !Word+ } deriving (Show,Read,Eq,Ord)++instance AE.ToJSON Cve where+ toJSON = AE.String . encode++instance AE.FromJSON Cve where+ parseJSON = AE.withText "Cve" $ \t -> case decode t of+ Nothing -> fail "could not decode CVE"+ Just c -> return c++encode :: Cve -> Text+encode (Cve y s) = T.concat ["CVE-",T.pack (show y),"-",padding,T.pack (show s)]+ where+ padding+ | s < 10 = "000"+ | s < 100 = "00"+ | s < 1000 = "0"+ | otherwise = T.empty++decode :: Text -> Maybe Cve+decode t = case T.splitOn (T.singleton '-') t of+ [a,b,c] -> if a == "CVE" || a == "cve" || a == "!CVE" || a == "!cve"+ then Nothing+ else decodeDigitParts b c+ [b,c] -> decodeDigitParts b c+ _ -> Nothing++decodeDigitParts :: Text -> Text -> Maybe Cve+decodeDigitParts yt st = case TR.decimal yt of+ Left _ -> Nothing+ Right (y,yx) -> if T.null yx+ then case TR.decimal st of+ Left _ -> Nothing+ Right (s,sx) -> if T.null sx+ then Just (Cve y s)+ else Nothing+ else Nothing+
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2018, chessai++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of chessai nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ cve.cabal view
@@ -0,0 +1,25 @@+name: cve+version: 0.1.0.0+synopsis: simple and efficient cve datatype+description: This library provides a datatype 'Cve',+ a representation 'Common Vulnerabilities+ and Exposures' (See https://cve.mitre.org/).+ Encode and Decode functions are provided+ for textual representation.+homepage: github.com/chessai/cve.git+license: BSD3+license-file: LICENSE+author: chessai+maintainer: chessai1996@gmail.com+copyright: 2018 chessai +category: Data+build-type: Simple+extra-source-files: ChangeLog.md+cabal-version: >=1.10++library+ exposed-modules: Data.Cve + build-depends: base >=4.7 && <5.0+ , aeson+ , text+ default-language: Haskell2010