aboutsummaryrefslogtreecommitdiff
path: root/ber/params.go
blob: 3569e693cb88c8deb3a78d7fcff21fa445e2295c (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
package ber

import (
	"strings"
	"strconv"
)

type fieldParams struct {
	optional        bool
	explicit        bool
	application     bool
	contextSpecific bool
	defaultValue    *int64
	tag             *int
	stringType      Tag
	set             bool
	omitEmpty       bool
}

func parseFiledParams(s string) (fp fieldParams) {
	for _, part := range strings.Split(s, ",") {
		switch {
		case part == "optional":
			fp.optional = true
		case part == "explicit":
			fp.explicit = true
		case part == "ia5":
			fp.stringType = tagIA5String
		case part == "printable":
			fp.stringType = tagPrintableString
		case part == "utf8":
			fp.stringType = tagUTF8String
		case strings.HasPrefix(part, "default:"):
			i, err := strconv.ParseInt(part[8:], 10, 64)
			if err == nil {
				fp.defaultValue = new(int64)
				*fp.defaultValue = i
			}
		case strings.HasPrefix(part, "tag:"):
			i, err := strconv.Atoi(part[4:])
			if err == nil {
				fp.tag = new(int)
				*fp.tag = i
			}
		case part == "set":
			fp.set = true
		case part == "application":
			fp.application = true
			if fp.tag == nil {
				fp.tag = new(int)
			}
		case part == "context":
			fp.contextSpecific = true
			if fp.tag == nil {
				fp.tag = new(int)
			}
		case part == "omitempty":
			fp.omitEmpty = true
		}
	}
	return
}