Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def testLeading0x80Case4(self):
try:
decoder.decode(
ints2octs((6, 2, 0x80, 0x7F))
)
except error.PyAsn1Error:
pass
else:
assert 0, 'Leading 0x80 tolerated'
def testOptionalWithDefault(self):
s = self.__initOptionalWithDefault()
assert encoder.encode(s) == ints2octs((48, 128, 48, 128, 2, 1, 123, 0, 0, 0, 0))
def testOne(self):
assert encoder.encode(
(1, 3, 6, 0, 0xffffe), asn1Spec=univ.ObjectIdentifier()
) == ints2octs((6, 6, 43, 6, 0, 191, 255, 126))
def testDefModeOptionalWithOptional(self):
s = self.__initOptionalWithOptional()
assert encoder.encode(s) == ints2octs((48, 8, 48, 6, 4, 4, 116, 101, 115, 116))
def testDefMode2(self):
s = univ.SetOf()
s.append(univ.OctetString('ab'))
s.append(univ.OctetString('a'))
assert encoder.encode(s) == ints2octs((49, 128, 4, 1, 97, 4, 2, 97, 98, 0, 0))
def testEncoder(self):
assert encoder.encode(self.o) == ints2octs((127, 141, 245, 182, 253, 47, 3, 2, 1, 1))
bitNo -= 1
else:
bitNo = 7
r.append(byte)
byte = 0
if v in ('0', '1'):
v = int(v)
else:
raise error.PyAsn1Error(
'Non-binary OCTET STRING initializer %s' % (v,)
)
byte |= v << bitNo
r.append(byte)
return octets.ints2octs(r)
def fromHexString(self, value):
r = p = ()
for v in value:
if p:
r = r + (int(p+v, 16),)
p = ()
else:
p = v
if p:
r = r + (int(p+'0', 16),)
return octets.ints2octs(r)
def asOctets(self, padding=True):
"""Get BIT STRING as a sequence of octets.
Parameters
----------
padding: :class:`bool`
Allow left-padding if BIT STRING length is not a multiples of eight.
Raises
------
: :py:class:`pyasn1.error.PyAsn1Error`
If BIT STRING length is not multiples of eight and no padding is allowed.
"""
return octets.ints2octs(self.asNumbers(padding))
from pyasn1.type import char
from pyasn1.type import tag
from pyasn1.type import univ
from pyasn1.type import useful
__all__ = ['encode']
LOG = debug.registerLoggee(__name__, flags=debug.DEBUG_ENCODER)
class AbstractItemEncoder(object):
supportIndefLenMode = True
# An outcome of otherwise legit call `encodeFun(eoo.endOfOctets)`
eooIntegerSubstrate = (0, 0)
eooOctetsSubstrate = ints2octs(eooIntegerSubstrate)
# noinspection PyMethodMayBeStatic
def encodeTag(self, singleTag, isConstructed):
tagClass, tagFormat, tagId = singleTag
encodedTag = tagClass | tagFormat
if isConstructed:
encodedTag |= tag.tagFormatConstructed
if tagId < 31:
return encodedTag | tagId,
else:
substrate = tagId & 0x7f,
tagId >>= 7