summaryrefslogtreecommitdiffstats
path: root/control.go
diff options
context:
space:
mode:
Diffstat (limited to 'control.go')
-rw-r--r--control.go62
1 files changed, 31 insertions, 31 deletions
diff --git a/control.go b/control.go
index dd46fea..8376dd7 100644
--- a/control.go
+++ b/control.go
@@ -6,7 +6,6 @@ package ldap
import (
"fmt"
-
"github.com/nmcclain/asn1-ber"
)
@@ -99,40 +98,41 @@ func FindControl(controls []Control, controlType string) Control {
func DecodeControl(packet *ber.Packet) Control {
ControlType := packet.Children[0].Value.(string)
- Criticality := false
-
packet.Children[0].Description = "Control Type (" + ControlTypeMap[ControlType] + ")"
- value := packet.Children[1]
- if len(packet.Children) == 3 {
- value = packet.Children[2]
- packet.Children[1].Description = "Criticality"
- Criticality = packet.Children[1].Value.(bool)
- }
+ c := new(ControlString)
+ c.ControlType = ControlType
+ c.Criticality = false
+
+ if len(packet.Children) > 1 {
+ value := packet.Children[1]
+ if len(packet.Children) == 3 {
+ value = packet.Children[2]
+ packet.Children[1].Description = "Criticality"
+ c.Criticality = packet.Children[1].Value.(bool)
+ }
- value.Description = "Control Value"
- switch ControlType {
- case ControlTypePaging:
- value.Description += " (Paging)"
- c := new(ControlPaging)
- if value.Value != nil {
- valueChildren := ber.DecodePacket(value.Data.Bytes())
- value.Data.Truncate(0)
- value.Value = nil
- value.AppendChild(valueChildren)
+ value.Description = "Control Value"
+ switch ControlType {
+ case ControlTypePaging:
+ value.Description += " (Paging)"
+ c := new(ControlPaging)
+ if value.Value != nil {
+ valueChildren := ber.DecodePacket(value.Data.Bytes())
+ value.Data.Truncate(0)
+ value.Value = nil
+ value.AppendChild(valueChildren)
+ }
+ value = value.Children[0]
+ value.Description = "Search Control Value"
+ value.Children[0].Description = "Paging Size"
+ value.Children[1].Description = "Cookie"
+ c.PagingSize = uint32(value.Children[0].Value.(uint64))
+ c.Cookie = value.Children[1].Data.Bytes()
+ value.Children[1].Value = c.Cookie
+ return c
}
- value = value.Children[0]
- value.Description = "Search Control Value"
- value.Children[0].Description = "Paging Size"
- value.Children[1].Description = "Cookie"
- c.PagingSize = uint32(value.Children[0].Value.(uint64))
- c.Cookie = value.Children[1].Data.Bytes()
- value.Children[1].Value = c.Cookie
- return c
+ c.ControlValue = value.Value.(string)
}
- c := new(ControlString)
- c.ControlType = ControlType
- c.Criticality = Criticality
- c.ControlValue = value.Value.(string)
return c
}