MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / encodeValue

Method encodeValue

pager_lib/pyasn1/codec/ber/encoder.py:229–285  ·  view source on GitHub ↗
(self, value, asn1Spec, encodeFun, **options)

Source from the content-addressed store, hash-verified

227class OctetStringEncoder(AbstractItemEncoder):
228
229 def encodeValue(self, value, asn1Spec, encodeFun, **options):
230
231 if asn1Spec is None:
232 substrate = value.asOctets()
233
234 elif not isinstance(value, bytes):
235 substrate = asn1Spec.clone(value).asOctets()
236
237 else:
238 substrate = value
239
240 maxChunkSize = options.get('maxChunkSize', 0)
241
242 if not maxChunkSize or len(substrate) <= maxChunkSize:
243 return substrate, False, True
244
245 if LOG:
246 LOG('encoding into up to %s-octet chunks' % maxChunkSize)
247
248 # strip off explicit tags for inner chunks
249
250 if asn1Spec is None:
251 baseTag = value.tagSet.baseTag
252
253 # strip off explicit tags
254 if baseTag:
255 tagSet = tag.TagSet(baseTag, baseTag)
256
257 else:
258 tagSet = tag.TagSet()
259
260 asn1Spec = value.clone(tagSet=tagSet)
261
262 elif not isinstance(value, bytes):
263 baseTag = asn1Spec.tagSet.baseTag
264
265 # strip off explicit tags
266 if baseTag:
267 tagSet = tag.TagSet(baseTag, baseTag)
268
269 else:
270 tagSet = tag.TagSet()
271
272 asn1Spec = asn1Spec.clone(tagSet=tagSet)
273
274 pos = 0
275 substrate = b''
276
277 while True:
278 chunk = value[pos:pos + maxChunkSize]
279 if not chunk:
280 break
281
282 substrate += encodeFun(chunk, asn1Spec, **options)
283 pos += maxChunkSize
284
285 return substrate, True, True
286

Callers

nothing calls this directly

Calls 3

asOctetsMethod · 0.45
cloneMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected