@@ -157,12 +157,15 @@ def encodeValue(self, value, asn1Spec, encodeFun, **options):
157
157
substrate = alignedValue .asOctets ()
158
158
return int2oct (len (substrate ) * 8 - valueLength ) + substrate , False , True
159
159
160
- tagSet = value .tagSet
160
+ baseTag = value .tagSet . baseTag
161
161
162
162
# strip off explicit tags
163
- alignedValue = alignedValue .clone (
164
- tagSet = tag .TagSet (tagSet .baseTag , tagSet .baseTag )
165
- )
163
+ if baseTag :
164
+ tagSet = tag .TagSet (baseTag , baseTag )
165
+ else :
166
+ tagSet = tag .TagSet ()
167
+
168
+ alignedValue = alignedValue .clone (tagSet = tagSet )
166
169
167
170
stop = 0
168
171
substrate = null
@@ -175,28 +178,52 @@ def encodeValue(self, value, asn1Spec, encodeFun, **options):
175
178
176
179
177
180
class OctetStringEncoder (AbstractItemEncoder ):
181
+
178
182
def encodeValue (self , value , asn1Spec , encodeFun , ** options ):
179
- if asn1Spec is None :
180
- # will strip off explicit tags
181
- tagSet = value .tagSet
182
- asn1Spec = value .clone (tagSet = tag .TagSet (tagSet .baseTag , tagSet .baseTag ))
183
183
184
- value = value .asOctets ()
184
+ if asn1Spec is None :
185
+ substrate = value .asOctets ()
185
186
186
187
elif not isOctetsType (value ):
187
- # will strip off explicit tags
188
- tagSet = asn1Spec .tagSet
189
- asn1Spec = asn1Spec .clone (tagSet = tag .TagSet (tagSet .baseTag , tagSet .baseTag ))
188
+ substrate = asn1Spec .clone (value ).asOctets ()
190
189
191
- value = asn1Spec .clone (value ).asOctets ()
190
+ else :
191
+ substrate = value
192
192
193
193
maxChunkSize = options .get ('maxChunkSize' , 0 )
194
- if not maxChunkSize or len (value ) <= maxChunkSize :
195
- return value , False , True
194
+
195
+ if not maxChunkSize or len (substrate ) <= maxChunkSize :
196
+ return substrate , False , True
196
197
197
198
else :
199
+
200
+ # strip off explicit tags for inner chunks
201
+
202
+ if asn1Spec is None :
203
+ baseTag = value .tagSet .baseTag
204
+
205
+ # strip off explicit tags
206
+ if baseTag :
207
+ tagSet = tag .TagSet (baseTag , baseTag )
208
+ else :
209
+ tagSet = tag .TagSet ()
210
+
211
+ asn1Spec = value .clone (tagSet = tagSet )
212
+
213
+ elif not isOctetsType (value ):
214
+ baseTag = asn1Spec .tagSet .baseTag
215
+
216
+ # strip off explicit tags
217
+ if baseTag :
218
+ tagSet = tag .TagSet (baseTag , baseTag )
219
+ else :
220
+ tagSet = tag .TagSet ()
221
+
222
+ asn1Spec = asn1Spec .clone (tagSet = tagSet )
223
+
198
224
pos = 0
199
225
substrate = null
226
+
200
227
while True :
201
228
chunk = value [pos :pos + maxChunkSize ]
202
229
if not chunk :
0 commit comments