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

Class BitStringPayloadDecoder

pager_lib/pyasn1/codec/ber/decoder.py:165–293  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

163
164
165class BitStringPayloadDecoder(AbstractSimplePayloadDecoder):
166 protoComponent = univ.BitString(())
167 supportConstructedForm = True
168
169 def valueDecoder(self, substrate, asn1Spec,
170 tagSet=None, length=None, state=None,
171 decodeFun=None, substrateFun=None,
172 **options):
173
174 if substrateFun:
175 asn1Object = self._createComponent(asn1Spec, tagSet, noValue, **options)
176
177 for chunk in substrateFun(asn1Object, substrate, length, options):
178 yield chunk
179
180 return
181
182 if not length:
183 raise error.PyAsn1Error('Empty BIT STRING substrate')
184
185 for chunk in isEndOfStream(substrate):
186 if isinstance(chunk, SubstrateUnderrunError):
187 yield chunk
188
189 if chunk:
190 raise error.PyAsn1Error('Empty BIT STRING substrate')
191
192 if tagSet[0].tagFormat == tag.tagFormatSimple: # XXX what tag to check?
193
194 for trailingBits in readFromStream(substrate, 1, options):
195 if isinstance(trailingBits, SubstrateUnderrunError):
196 yield trailingBits
197
198 trailingBits = ord(trailingBits)
199 if trailingBits > 7:
200 raise error.PyAsn1Error(
201 'Trailing bits overflow %s' % trailingBits
202 )
203
204 for chunk in readFromStream(substrate, length - 1, options):
205 if isinstance(chunk, SubstrateUnderrunError):
206 yield chunk
207
208 value = self.protoComponent.fromOctetString(
209 chunk, internalFormat=True, padding=trailingBits)
210
211 yield self._createComponent(asn1Spec, tagSet, value, **options)
212
213 return
214
215 if not self.supportConstructedForm:
216 raise error.PyAsn1Error('Constructed encoding form prohibited '
217 'at %s' % self.__class__.__name__)
218
219 if LOG:
220 LOG('assembling constructed serialization')
221
222 # All inner fragments are of the same type, treat them as octet string

Callers 2

decoder.pyFile · 0.70
decoder.pyFile · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected