@@ -89,7 +89,7 @@ func (c *ControlPaging) Encode() *ber.Packet {
8989
9090 p2 := ber .Encode (ber .ClassUniversal , ber .TypePrimitive , ber .TagOctetString , nil , "Control Value (Paging)" )
9191 seq := ber .Encode (ber .ClassUniversal , ber .TypeConstructed , ber .TagSequence , nil , "Search Control Value" )
92- seq .AppendChild (ber .NewInteger (ber .ClassUniversal , ber .TypePrimitive , ber .TagInteger , uint64 (c .PagingSize ), "Paging Size" ))
92+ seq .AppendChild (ber .NewInteger (ber .ClassUniversal , ber .TypePrimitive , ber .TagInteger , int64 (c .PagingSize ), "Paging Size" ))
9393 cookie := ber .Encode (ber .ClassUniversal , ber .TypePrimitive , ber .TagOctetString , nil , "Cookie" )
9494 cookie .Value = c .Cookie
9595 cookie .Data .Write (c .Cookie )
@@ -254,19 +254,54 @@ func FindControl(controls []Control, controlType string) Control {
254254
255255// DecodeControl returns a control read from the given packet, or nil if no recognized control can be made
256256func DecodeControl (packet * ber.Packet ) Control {
257- ControlType := packet .Children [0 ].Value .(string )
258- Criticality := false
257+ var (
258+ ControlType = ""
259+ Criticality = false
260+ value * ber.Packet
261+ )
262+
263+ switch len (packet .Children ) {
264+ case 0 :
265+ // at least one child is required for control type
266+ return nil
267+
268+ case 1 :
269+ // just type, no criticality or value
270+ packet .Children [0 ].Description = "Control Type (" + ControlTypeMap [ControlType ] + ")"
271+ ControlType = packet .Children [0 ].Value .(string )
272+
273+ case 2 :
274+ packet .Children [0 ].Description = "Control Type (" + ControlTypeMap [ControlType ] + ")"
275+ ControlType = packet .Children [0 ].Value .(string )
276+
277+ // Children[1] could be criticality or value (both are optional)
278+ // duck-type on whether this is a boolean
279+ if _ , ok := packet .Children [1 ].Value .(bool ); ok {
280+ packet .Children [1 ].Description = "Criticality"
281+ Criticality = packet .Children [1 ].Value .(bool )
282+ } else {
283+ packet .Children [1 ].Description = "Control Value"
284+ value = packet .Children [1 ]
285+ }
286+
287+ case 3 :
288+ packet .Children [0 ].Description = "Control Type (" + ControlTypeMap [ControlType ] + ")"
289+ ControlType = packet .Children [0 ].Value .(string )
259290
260- packet .Children [0 ].Description = "Control Type (" + ControlTypeMap [ControlType ] + ")"
261- value := packet .Children [1 ]
262- if len (packet .Children ) == 3 {
263- value = packet .Children [2 ]
264291 packet .Children [1 ].Description = "Criticality"
265292 Criticality = packet .Children [1 ].Value .(bool )
293+
294+ packet .Children [2 ].Description = "Control Value"
295+ value = packet .Children [2 ]
296+
297+ default :
298+ // more than 3 children is invalid
299+ return nil
266300 }
267301
268- value .Description = "Control Value"
269302 switch ControlType {
303+ case ControlTypeManageDsaIT :
304+ return NewControlManageDsaIT (Criticality )
270305 case ControlTypePaging :
271306 value .Description += " (Paging)"
272307 c := new (ControlPaging )
@@ -341,13 +376,16 @@ func DecodeControl(packet *ber.Packet) Control {
341376 c .Expire = expire
342377 value .Value = c .Expire
343378
379+ return c
380+ default :
381+ c := new (ControlString )
382+ c .ControlType = ControlType
383+ c .Criticality = Criticality
384+ if value != nil {
385+ c .ControlValue = value .Value .(string )
386+ }
344387 return c
345388 }
346- c := new (ControlString )
347- c .ControlType = ControlType
348- c .Criticality = Criticality
349- c .ControlValue = value .Value .(string )
350- return c
351389}
352390
353391// NewControlString returns a generic control
0 commit comments