aboutsummaryrefslogtreecommitdiff
path: root/ber
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-07-13 19:27:05 +0200
committerDimitri Sokolyuk <demon@dim13.org>2015-07-13 19:27:05 +0200
commitc5bfd836d2331ec058d8835fa605af12fdac04cc (patch)
treed081c25e72a4924046e3c92c3f78316127a51fc6 /ber
parent50a5a67ee1eab8abb377c9498803951da5e58b4d (diff)
add params
Diffstat (limited to 'ber')
-rw-r--r--ber/params.go62
1 files changed, 62 insertions, 0 deletions
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
+}