forked from go-ldap/ldap
-
Notifications
You must be signed in to change notification settings - Fork 1
/
control_changenotify.go
56 lines (45 loc) · 1.62 KB
/
control_changenotify.go
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
package ldap
import (
"fmt"
"gopkg.in/asn1-ber.v1"
)
func init() {
ControlTypeMap[ControlTypeChangeNotify] = "Change Notification"
}
func NewControlChangeNotify() *ControlChangeNotify {
return &ControlChangeNotify{Criticality: true}
}
type ControlChangeNotify struct {
Criticality bool
Cookie []byte
}
func (c *ControlChangeNotify) GetControlType() string {
return ControlTypeChangeNotify
}
func (c *ControlChangeNotify) Encode() *ber.Packet {
packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Control")
packet.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, ControlTypeChangeNotify, "Control Type ("+ControlTypeMap[ControlTypeChangeNotify]+")"))
p2 := ber.Encode(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, nil, "Control Value (Change Notification)")
seq := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Search Control Value")
cookie := ber.Encode(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, nil, "Cookie")
cookie.Value = c.Cookie
cookie.Data.Write(c.Cookie)
seq.AppendChild(cookie)
p2.AppendChild(seq)
if c.Criticality {
packet.AppendChild(ber.NewBoolean(ber.ClassUniversal, ber.TypePrimitive, ber.TagBoolean, c.Criticality, "Criticality"))
}
packet.AppendChild(p2)
return packet
}
func (c *ControlChangeNotify) String() string {
return fmt.Sprintf(
"Control Type: %s (%q) Criticality: %t Cookie: %q",
ControlTypeMap[ControlTypeChangeNotify],
ControlTypeChangeNotify,
c.Criticality,
c.Cookie)
}
func (c *ControlChangeNotify) SetCookie(cookie []byte) {
c.Cookie = cookie
}