@@ -145,20 +145,20 @@ var TypeMap = map[Type]string{
145145 TypeConstructed : "Constructed" ,
146146}
147147
148- var Debug bool = false
148+ var Debug = false
149149
150150func PrintBytes (out io.Writer , buf []byte , indent string ) {
151- data_lines := make ([]string , (len (buf )/ 30 )+ 1 )
152- num_lines := make ([]string , (len (buf )/ 30 )+ 1 )
151+ dataLines := make ([]string , (len (buf )/ 30 )+ 1 )
152+ numLines := make ([]string , (len (buf )/ 30 )+ 1 )
153153
154154 for i , b := range buf {
155- data_lines [i / 30 ] += fmt .Sprintf ("%02x " , b )
156- num_lines [i / 30 ] += fmt .Sprintf ("%02d " , (i + 1 )% 100 )
155+ dataLines [i / 30 ] += fmt .Sprintf ("%02x " , b )
156+ numLines [i / 30 ] += fmt .Sprintf ("%02d " , (i + 1 )% 100 )
157157 }
158158
159- for i := 0 ; i < len (data_lines ); i ++ {
160- out .Write ([]byte (indent + data_lines [i ] + "\n " ))
161- out .Write ([]byte (indent + num_lines [i ] + "\n \n " ))
159+ for i := 0 ; i < len (dataLines ); i ++ {
160+ _ , _ = out .Write ([]byte (indent + dataLines [i ] + "\n " ))
161+ _ , _ = out .Write ([]byte (indent + numLines [i ] + "\n \n " ))
162162 }
163163}
164164
@@ -171,20 +171,20 @@ func PrintPacket(p *Packet) {
171171}
172172
173173func printPacket (out io.Writer , p * Packet , indent int , printBytes bool ) {
174- indent_str := ""
174+ indentStr := ""
175175
176- for len (indent_str ) != indent {
177- indent_str += " "
176+ for len (indentStr ) != indent {
177+ indentStr += " "
178178 }
179179
180- class_str := ClassMap [p .ClassType ]
180+ classStr := ClassMap [p .ClassType ]
181181
182- tagtype_str := TypeMap [p .TagType ]
182+ tagTypeStr := TypeMap [p .TagType ]
183183
184- tag_str := fmt .Sprintf ("0x%02X" , p .Tag )
184+ tagStr := fmt .Sprintf ("0x%02X" , p .Tag )
185185
186186 if p .ClassType == ClassUniversal {
187- tag_str = tagMap [p .Tag ]
187+ tagStr = tagMap [p .Tag ]
188188 }
189189
190190 value := fmt .Sprint (p .Value )
@@ -194,18 +194,18 @@ func printPacket(out io.Writer, p *Packet, indent int, printBytes bool) {
194194 description = p .Description + ": "
195195 }
196196
197- fmt .Fprintf (out , "%s%s(%s, %s, %s) Len=%d %q\n " , indent_str , description , class_str , tagtype_str , tag_str , p .Data .Len (), value )
197+ _ , _ = fmt .Fprintf (out , "%s%s(%s, %s, %s) Len=%d %q\n " , indentStr , description , classStr , tagTypeStr , tagStr , p .Data .Len (), value )
198198
199199 if printBytes {
200- PrintBytes (out , p .Bytes (), indent_str )
200+ PrintBytes (out , p .Bytes (), indentStr )
201201 }
202202
203203 for _ , child := range p .Children {
204204 printPacket (out , child , indent + 1 , printBytes )
205205 }
206206}
207207
208- // ReadPacket reads a single Packet from the reader
208+ // ReadPacket reads a single Packet from the reader.
209209func ReadPacket (reader io.Reader ) (* Packet , error ) {
210210 p , _ , err := readPacket (reader )
211211 if err != nil {
@@ -241,7 +241,7 @@ func encodeInteger(i int64) []byte {
241241
242242 var j int
243243 for ; n > 0 ; n -- {
244- out [j ] = ( byte (i >> uint ((n - 1 )* 8 ) ))
244+ out [j ] = byte (i >> uint ((n - 1 )* 8 ))
245245 j ++
246246 }
247247
@@ -273,7 +273,7 @@ func DecodePacket(data []byte) *Packet {
273273}
274274
275275// DecodePacketErr decodes the given bytes into a single Packet
276- // If a decode error is encountered, nil is returned
276+ // If a decode error is encountered, nil is returned.
277277func DecodePacketErr (data []byte ) (* Packet , error ) {
278278 p , _ , err := readPacket (bytes .NewBuffer (data ))
279279 if err != nil {
@@ -282,7 +282,7 @@ func DecodePacketErr(data []byte) (*Packet, error) {
282282 return p , nil
283283}
284284
285- // readPacket reads a single Packet from the reader, returning the number of bytes read
285+ // readPacket reads a single Packet from the reader, returning the number of bytes read.
286286func readPacket (reader io.Reader ) (* Packet , int , error ) {
287287 identifier , length , read , err := readHeader (reader )
288288 if err != nil {
@@ -344,7 +344,7 @@ func readPacket(reader io.Reader) (*Packet, int, error) {
344344 if MaxPacketLengthBytes > 0 && int64 (length ) > MaxPacketLengthBytes {
345345 return nil , read , fmt .Errorf ("length %d greater than maximum %d" , length , MaxPacketLengthBytes )
346346 }
347- content := make ([]byte , length , length )
347+ content := make ([]byte , length )
348348 if length > 0 {
349349 _ , err := io .ReadFull (reader , content )
350350 if err != nil {
@@ -461,24 +461,24 @@ func (p *Packet) AppendChild(child *Packet) {
461461 p .Children = append (p .Children , child )
462462}
463463
464- func Encode (ClassType Class , TagType Type , Tag Tag , Value interface {}, Description string ) * Packet {
464+ func Encode (classType Class , tagType Type , tag Tag , value interface {}, description string ) * Packet {
465465 p := new (Packet )
466466
467- p .ClassType = ClassType
468- p .TagType = TagType
469- p .Tag = Tag
467+ p .ClassType = classType
468+ p .TagType = tagType
469+ p .Tag = tag
470470 p .Data = new (bytes.Buffer )
471471
472472 p .Children = make ([]* Packet , 0 , 2 )
473473
474- p .Value = Value
475- p .Description = Description
474+ p .Value = value
475+ p .Description = description
476476
477- if Value != nil {
478- v := reflect .ValueOf (Value )
477+ if value != nil {
478+ v := reflect .ValueOf (value )
479479
480- if ClassType == ClassUniversal {
481- switch Tag {
480+ if classType == ClassUniversal {
481+ switch tag {
482482 case TagOctetString :
483483 sv , ok := v .Interface ().(string )
484484
@@ -496,8 +496,8 @@ func Encode(ClassType Class, TagType Type, Tag Tag, Value interface{}, Descripti
496496 p .Data .Write (bv )
497497 }
498498 }
499- } else if ClassType == ClassContext {
500- switch Tag {
499+ } else if classType == ClassContext {
500+ switch tag {
501501 case TagEnumerated :
502502 bv , ok := v .Interface ().([]byte )
503503 if ok {
@@ -514,46 +514,46 @@ func Encode(ClassType Class, TagType Type, Tag Tag, Value interface{}, Descripti
514514 return p
515515}
516516
517- func NewSequence (Description string ) * Packet {
518- return Encode (ClassUniversal , TypeConstructed , TagSequence , nil , Description )
517+ func NewSequence (description string ) * Packet {
518+ return Encode (ClassUniversal , TypeConstructed , TagSequence , nil , description )
519519}
520520
521- func NewBoolean (ClassType Class , TagType Type , Tag Tag , Value bool , Description string ) * Packet {
521+ func NewBoolean (classType Class , tagType Type , tag Tag , value bool , description string ) * Packet {
522522 intValue := int64 (0 )
523523
524- if Value {
524+ if value {
525525 intValue = 1
526526 }
527527
528- p := Encode (ClassType , TagType , Tag , nil , Description )
528+ p := Encode (classType , tagType , tag , nil , description )
529529
530- p .Value = Value
530+ p .Value = value
531531 p .Data .Write (encodeInteger (intValue ))
532532
533533 return p
534534}
535535
536- // NewLDAPBoolean returns a RFC 4511-compliant Boolean packet
537- func NewLDAPBoolean (ClassType Class , TagType Type , Tag Tag , Value bool , Description string ) * Packet {
536+ // NewLDAPBoolean returns a RFC 4511-compliant Boolean packet.
537+ func NewLDAPBoolean (classType Class , tagType Type , tag Tag , value bool , description string ) * Packet {
538538 intValue := int64 (0 )
539539
540- if Value {
540+ if value {
541541 intValue = 255
542542 }
543543
544- p := Encode (ClassType , TagType , Tag , nil , Description )
544+ p := Encode (classType , tagType , tag , nil , description )
545545
546- p .Value = Value
546+ p .Value = value
547547 p .Data .Write (encodeInteger (intValue ))
548548
549549 return p
550550}
551551
552- func NewInteger (ClassType Class , TagType Type , Tag Tag , Value interface {}, Description string ) * Packet {
553- p := Encode (ClassType , TagType , Tag , nil , Description )
552+ func NewInteger (classType Class , tagType Type , tag Tag , value interface {}, description string ) * Packet {
553+ p := Encode (classType , tagType , tag , nil , description )
554554
555- p .Value = Value
556- switch v := Value .(type ) {
555+ p .Value = value
556+ switch v := value .(type ) {
557557 case int :
558558 p .Data .Write (encodeInteger (int64 (v )))
559559 case uint :
@@ -583,38 +583,38 @@ func NewInteger(ClassType Class, TagType Type, Tag Tag, Value interface{}, Descr
583583 return p
584584}
585585
586- func NewString (ClassType Class , TagType Type , Tag Tag , Value , Description string ) * Packet {
587- p := Encode (ClassType , TagType , Tag , nil , Description )
586+ func NewString (classType Class , tagType Type , tag Tag , value , description string ) * Packet {
587+ p := Encode (classType , tagType , tag , nil , description )
588588
589- p .Value = Value
590- p .Data .Write ([]byte (Value ))
589+ p .Value = value
590+ p .Data .Write ([]byte (value ))
591591
592592 return p
593593}
594594
595- func NewGeneralizedTime (ClassType Class , TagType Type , Tag Tag , Value time.Time , Description string ) * Packet {
596- p := Encode (ClassType , TagType , Tag , nil , Description )
595+ func NewGeneralizedTime (classType Class , tagType Type , tag Tag , value time.Time , description string ) * Packet {
596+ p := Encode (classType , tagType , tag , nil , description )
597597 var s string
598- if Value .Nanosecond () != 0 {
599- s = Value .Format (`20060102150405.000000Z` ) // FIXME how many fractional?
598+ if value .Nanosecond () != 0 {
599+ s = value .Format (`20060102150405.000000000Z` )
600600 } else {
601- s = Value .Format (`20060102150405Z` )
601+ s = value .Format (`20060102150405Z` )
602602 }
603603 p .Value = s
604604 p .Data .Write ([]byte (s ))
605- return p
605+ return p
606606}
607607
608- func NewReal (ClassType Class , TagType Type , Tag Tag , Value interface {}, Description string ) * Packet {
609- p := Encode (ClassType , TagType , Tag , nil , Description )
608+ func NewReal (classType Class , tagType Type , tag Tag , value interface {}, description string ) * Packet {
609+ p := Encode (classType , tagType , tag , nil , description )
610610
611- switch v := Value .(type ) {
611+ switch v := value .(type ) {
612612 case float64 :
613- p .Data .Write (encodeFloat (float64 ( v ) ))
613+ p .Data .Write (encodeFloat (v ))
614614 case float32 :
615615 p .Data .Write (encodeFloat (float64 (v )))
616616 default :
617617 panic (fmt .Sprintf ("Invalid type %T, expected float{64|32}" , v ))
618618 }
619619 return p
620- }
620+ }
0 commit comments