forked from go-ldap/ldap
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontrol_syncstate.go
85 lines (66 loc) · 2.39 KB
/
control_syncstate.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package ldap
import (
"fmt"
"gopkg.in/asn1-ber.v1"
)
func init() {
ControlTypeMap[ControlTypeContentSyncState] = "Sync State"
}
type ControlContentSyncState struct {
State uint32
Uuid []byte
Cookie []byte
}
func (c *ControlContentSyncState) GetControlType() string {
return ControlTypeContentSyncState
}
func (c *ControlContentSyncState) Encode() *ber.Packet {
packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Control")
packet.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, ControlTypeContentSyncState, "Control Type ("+ControlTypeMap[ControlTypeContentSyncState]+")"))
p2 := ber.Encode(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, nil, "Control Value (Content Sync Info)")
seq := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Search Control Value")
seq.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, uint32(c.State), "State"))
entryUuid := ber.Encode(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, nil, "UUID")
entryUuid.Value = c.Uuid
entryUuid.Data.Write(c.Uuid)
seq.AppendChild(entryUuid)
if c.Cookie != nil {
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)
packet.AppendChild(p2)
return packet
}
func (c *ControlContentSyncState) decode(criticality bool, value *ber.Packet) {
value.Description = "Control Value (Sync State)"
if value.Value == nil {
return
}
valueChildren := ber.DecodePacket(value.Data.Bytes())
value.Data.Truncate(0)
value.Value = nil
value.AppendChild(valueChildren)
valueChildren.Children[0].Description = "Entry State"
c.State = uint32(valueChildren.Children[0].Value.(int64))
valueChildren.Children[1].Description = "Entry UUID"
c.Uuid = valueChildren.Children[1].Data.Bytes()
if len(valueChildren.Children) > 2 {
valueChildren.Children[2].Description = "Cookie"
c.Cookie = valueChildren.Children[2].Data.Bytes()
}
}
func (c *ControlContentSyncState) String() string {
return fmt.Sprintf(
"Control Type: %s (%q) State: %d Uuid: %x Cookie: %x",
ControlTypeMap[ControlTypeContentSyncState],
ControlTypeContentSyncState,
c.State,
c.Uuid,
c.Cookie)
}
func (c *ControlContentSyncState) SetCookie(cookie []byte) {
c.Cookie = cookie
}