aboutsummaryrefslogtreecommitdiff
path: root/cpe/part.go
blob: ef91f7c7b11a30f6e456cd58a431555168864994 (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
package cpe

//go:generate stringer -linecomment -type=Part

import (
  "fmt"
)

// CPE part
type Part byte

const (
  ApplicationPart Part = 'a' // a
  OperatingSystemPart Part = 'o' // o
  HardwarePart Part = 'h' // h
  AnyPart Part = '*' // *
  NAPart Part = '-' // -
)

// create new part from token
func newPart(t token) (Part, error) {
  switch t.Type {
  case anyToken:
    return AnyPart, nil
  case naToken:
    return NAPart, nil
  case valToken:
    switch t.Val {
    case "a":
      return ApplicationPart, nil
    case "o":
      return OperatingSystemPart, nil
    case "h":
      return HardwarePart, nil
    default:
      return 0, fmt.Errorf("unknown part: \"%s\"", t.Val)
    }
  default:
    return 0, fmt.Errorf("unknown token type: 0x%02x", byte(t.Type))
  }
}