diff options
author | Paul Duncan <pabs@pablotron.org> | 2022-01-31 11:09:58 -0500 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2022-01-31 11:09:58 -0500 |
commit | b3dc36421f133ea6983574891720e974cf7974dd (patch) | |
tree | c6375903fa820bd0ac64ce40827c2c8302d38737 /main.go | |
download | cvez-b3dc36421f133ea6983574891720e974cf7974dd.tar.bz2 cvez-b3dc36421f133ea6983574891720e974cf7974dd.zip |
initial commit
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 88 |
1 files changed, 88 insertions, 0 deletions
@@ -0,0 +1,88 @@ +package main + +import ( + "bytes" + "encoding/json" + "fmt" + "log" + "nvd/internal/cvss" + "nvd/internal/feed" + "os" +) + +const testMeta = `lastModifiedDate:2022-01-29T03:01:16-05:00 +size:73202582 +zipSize:3753799 +gzSize:3753663 +sha256:B86258D5D9861507A1894A7B92011764803D7267787B1487539E240EA2405440 +` + +// Test meta parser +func testMetaParser() { + // create buffer + buf := bytes.NewBufferString(testMeta) + + // decode meta, check for error + meta, err := feed.NewMeta(buf) + if err != nil { + log.Fatal(err) + } + + // create json encoder + e := json.NewEncoder(os.Stdout) + if err := e.Encode(meta); err != nil { + log.Fatal(err) + } +} + +// Test feed parser +func testFeedParser() { + var f feed.Feed + + // decode cve feed + d := json.NewDecoder(os.Stdin) + if err := d.Decode(&f); err != nil { + log.Fatal(err) + } + + // create json encoder + e := json.NewEncoder(os.Stdout) + if err := e.Encode(f); err != nil { + log.Fatal(err) + } +} + +// test cvss v3.1 vector +var testCvssV3 = "CVSS:3.1/AV:L/AC:L/PR:H/UI:N/S:U/C:N/I:N/A:H" + +// Test cvss v3 parser +func testCvssV3Parser() { + // parse vector, check for error + v, err := cvss.NewVector(testCvssV3) + if err != nil { + log.Fatal(err) + } + + fmt.Println(v) +} + +// test cvss v2 vector +var testCvssV2 = "AV:L/AC:L/Au:N/C:N/I:N/A:P" + +// Test cvss v2 parser +func testCvssV2Parser() { + // parse vector, check for error + v, err := cvss.NewVector(testCvssV2) + if err != nil { + log.Fatal(err) + } + + fmt.Println(v) +} + +func main() { + testMetaParser() + // testFeedParser() + testCvssV3Parser() + testCvssV2Parser() +} |