aboutsummaryrefslogtreecommitdiff
path: root/main.go
blob: 608d7104a8727d1bb06c3d4e1cb7f227b28632f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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.Metrics())
  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.Metrics())
  fmt.Println(v)
}

func main() {
  testMetaParser()
  // testFeedParser()
  testCvssV3Parser()
  testCvssV2Parser()
}