From c5bfd836d2331ec058d8835fa605af12fdac04cc Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Mon, 13 Jul 2015 19:27:05 +0200 Subject: add params --- ber/params.go | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 ber/params.go (limited to 'ber/params.go') diff --git a/ber/params.go b/ber/params.go new file mode 100644 index 0000000..3569e69 --- /dev/null +++ b/ber/params.go @@ -0,0 +1,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 +} -- cgit v1.2.3