aboutsummaryrefslogtreecommitdiff
path: root/goldap/control.go
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2021-09-16 13:41:01 +0200
committerQuentin Dufour <quentin@deuxfleurs.fr>2021-09-16 13:41:01 +0200
commit477d7014edc787ba9a977acd19fcbfc55531768b (patch)
treeac8b65be8634fa9526cd727da60893244d11e88a /goldap/control.go
parenta53641e773730ba171df2602c8d199968d6e6447 (diff)
downloadbottin-477d7014edc787ba9a977acd19fcbfc55531768b.tar.gz
bottin-477d7014edc787ba9a977acd19fcbfc55531768b.zip
Vendor goldap
Diffstat (limited to 'goldap/control.go')
-rw-r--r--goldap/control.go94
1 files changed, 94 insertions, 0 deletions
diff --git a/goldap/control.go b/goldap/control.go
new file mode 100644
index 0000000..3f94b67
--- /dev/null
+++ b/goldap/control.go
@@ -0,0 +1,94 @@
+package message
+
+import (
+ "errors"
+ "fmt"
+)
+
+//
+// Control ::= SEQUENCE {
+// controlType LDAPOID,
+// criticality BOOLEAN DEFAULT FALSE,
+// controlValue OCTET STRING OPTIONAL }
+
+func (control *Control) ControlType() LDAPOID {
+ return control.controlType
+}
+
+func (control *Control) Criticality() BOOLEAN {
+ return control.criticality
+}
+
+func (control *Control) ControlValue() *OCTETSTRING {
+ return control.controlValue
+}
+
+func readControl(bytes *Bytes) (control Control, err error) {
+ err = bytes.ReadSubBytes(classUniversal, tagSequence, control.readComponents)
+ if err != nil {
+ err = LdapError{fmt.Sprintf("readControl:\n%s", err.Error())}
+ return
+ }
+ return
+}
+
+func (control *Control) readComponents(bytes *Bytes) (err error) {
+ control.controlType, err = readLDAPOID(bytes)
+ if err != nil {
+ err = LdapError{fmt.Sprintf("readComponents:\n%s", err.Error())}
+ return
+ }
+ if bytes.HasMoreData() {
+ var tag TagAndLength
+ tag, err = bytes.PreviewTagAndLength()
+ if err != nil {
+ err = LdapError{fmt.Sprintf("readComponents:\n%s", err.Error())}
+ return
+ }
+ if tag.Tag == tagBoolean {
+ control.criticality, err = readBOOLEAN(bytes)
+ if err != nil {
+ err = LdapError{fmt.Sprintf("readComponents:\n%s", err.Error())}
+ return
+ }
+ if control.criticality == false {
+ err = errors.New(fmt.Sprintf("readComponents: criticality default value FALSE should not be specified"))
+ return
+ }
+ }
+ }
+ if bytes.HasMoreData() {
+ var octetstring OCTETSTRING
+ octetstring, err = readOCTETSTRING(bytes)
+ if err != nil {
+ err = LdapError{fmt.Sprintf("readComponents:\n%s", err.Error())}
+ return
+ }
+ control.controlValue = octetstring.Pointer()
+ }
+ return
+}
+
+func (control Control) write(bytes *Bytes) (size int) {
+ if control.controlValue != nil {
+ size += control.controlValue.write(bytes)
+ }
+ if control.criticality != BOOLEAN(false) {
+ size += control.criticality.write(bytes)
+ }
+ size += control.controlType.write(bytes)
+ size += bytes.WriteTagAndLength(classUniversal, isCompound, tagSequence, size)
+ return
+}
+
+func (control Control) size() (size int) {
+ if control.controlValue != nil {
+ size += control.controlValue.size()
+ }
+ if control.criticality != BOOLEAN(false) {
+ size += control.criticality.size()
+ }
+ size += control.controlType.size()
+ size += sizeTagAndLength(tagSequence, size)
+ return
+}