@@ -80,26 +80,6 @@ func (m multiEncoder) Encode(dst []byte) {
80
80
}
81
81
}
82
82
83
- type octetSorter [][]byte
84
-
85
- func (s octetSorter ) Len () int {
86
- return len (s )
87
- }
88
-
89
- func (s octetSorter ) Swap (i , j int ) {
90
- s [i ], s [j ] = s [j ], s [i ]
91
- }
92
-
93
- func (s octetSorter ) Less (i , j int ) bool {
94
- // Since we are using bytes.Compare to compare TLV encodings we
95
- // don't need to right pad s[i] and s[j] to the same length as
96
- // suggested in X690. If len(s[i]) < len(s[j]) the length octet of
97
- // s[i], which is the first determining byte, will inherently be
98
- // smaller than the length octet of s[j]. This lets us skip the
99
- // padding step.
100
- return bytes .Compare (s [i ], s [j ]) < 0
101
- }
102
-
103
83
type setEncoder []encoder
104
84
105
85
func (s setEncoder ) Len () int {
@@ -125,7 +105,15 @@ func (s setEncoder) Encode(dst []byte) {
125
105
e .Encode (l [i ])
126
106
}
127
107
128
- sort .Sort (octetSorter (l ))
108
+ sort .Slice (l , func (i , j int ) bool {
109
+ // Since we are using bytes.Compare to compare TLV encodings we
110
+ // don't need to right pad s[i] and s[j] to the same length as
111
+ // suggested in X690. If len(s[i]) < len(s[j]) the length octet of
112
+ // s[i], which is the first determining byte, will inherently be
113
+ // smaller than the length octet of s[j]. This lets us skip the
114
+ // padding step.
115
+ return bytes .Compare (l [i ], l [j ]) < 0
116
+ })
129
117
130
118
var off int
131
119
for _ , b := range l {
@@ -677,6 +665,15 @@ func makeField(v reflect.Value, params fieldParameters) (e encoder, err error) {
677
665
tag = TagSet
678
666
}
679
667
668
+ // makeField can be called for a slice that should be treated as a SET
669
+ // but doesn't have params.set set, for instance when using a slice
670
+ // with the SET type name suffix. In this case getUniversalType returns
671
+ // TagSet, but makeBody doesn't know about that so will treat the slice
672
+ // as a sequence. To work around this we set params.set.
673
+ if tag == TagSet && ! params .set {
674
+ params .set = true
675
+ }
676
+
680
677
t := new (taggedEncoder )
681
678
682
679
t .body , err = makeBody (v , params )
0 commit comments