diff options
author | robot-piglet <robot-piglet@yandex-team.com> | 2024-09-29 14:56:34 +0300 |
---|---|---|
committer | robot-piglet <robot-piglet@yandex-team.com> | 2024-09-29 15:07:41 +0300 |
commit | 879a377a0a58f7bf1b0c55ea8c0f525e33f35b53 (patch) | |
tree | e641b8333a1bfaba647b06775c352f4315f26ee5 /contrib/python/pyasn1/py3 | |
parent | d33d1897c75f511aed6d7a35b51fa4647cfd5fd4 (diff) | |
download | ydb-879a377a0a58f7bf1b0c55ea8c0f525e33f35b53.tar.gz |
Intermediate changes
commit_hash:02eb31a2fa9b8a7459367d02598ccdfb6d69f271
Diffstat (limited to 'contrib/python/pyasn1/py3')
36 files changed, 1213 insertions, 1760 deletions
diff --git a/contrib/python/pyasn1/py3/.dist-info/METADATA b/contrib/python/pyasn1/py3/.dist-info/METADATA index 10bf60c633..8d8613e6a6 100644 --- a/contrib/python/pyasn1/py3/.dist-info/METADATA +++ b/contrib/python/pyasn1/py3/.dist-info/METADATA @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: pyasn1 -Version: 0.6.0 +Version: 0.6.1 Summary: Pure-Python implementation of ASN.1 types and DER/BER/CER codecs (X.208) Home-page: https://github.com/pyasn1/pyasn1 Author: Ilya Etingof @@ -29,6 +29,7 @@ Classifier: Programming Language :: Python :: 3.9 Classifier: Programming Language :: Python :: 3.10 Classifier: Programming Language :: Python :: 3.11 Classifier: Programming Language :: Python :: 3.12 +Classifier: Programming Language :: Python :: 3.13 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: Topic :: Communications diff --git a/contrib/python/pyasn1/py3/pyasn1/__init__.py b/contrib/python/pyasn1/py3/pyasn1/__init__.py index 41a89c18d9..7fa1d9e630 100644 --- a/contrib/python/pyasn1/py3/pyasn1/__init__.py +++ b/contrib/python/pyasn1/py3/pyasn1/__init__.py @@ -1,2 +1,2 @@ # https://www.python.org/dev/peps/pep-0396/ -__version__ = '0.6.0' +__version__ = '0.6.1' diff --git a/contrib/python/pyasn1/py3/pyasn1/codec/ber/decoder.py b/contrib/python/pyasn1/py3/pyasn1/codec/ber/decoder.py index fd80fc8eb2..7e69ca1567 100644 --- a/contrib/python/pyasn1/py3/pyasn1/codec/ber/decoder.py +++ b/contrib/python/pyasn1/py3/pyasn1/codec/ber/decoder.py @@ -7,7 +7,7 @@ import io import os import sys - +import warnings from pyasn1 import debug from pyasn1 import error @@ -17,8 +17,6 @@ from pyasn1.codec.streaming import isEndOfStream from pyasn1.codec.streaming import peekIntoStream from pyasn1.codec.streaming import readFromStream from pyasn1.compat import _MISSING -from pyasn1.compat.integer import from_bytes -from pyasn1.compat.octets import oct2int, octs2ints, ints2octs, null from pyasn1.error import PyAsn1Error from pyasn1.type import base from pyasn1.type import char @@ -144,7 +142,7 @@ class IntegerPayloadDecoder(AbstractSimplePayloadDecoder): yield chunk if chunk: - value = from_bytes(chunk, signed=True) + value = int.from_bytes(bytes(chunk), 'big', signed=True) else: value = 0 @@ -220,7 +218,7 @@ class BitStringPayloadDecoder(AbstractSimplePayloadDecoder): # All inner fragments are of the same type, treat them as octet string substrateFun = self.substrateCollector - bitString = self.protoComponent.fromOctetString(null, internalFormat=True) + bitString = self.protoComponent.fromOctetString(b'', internalFormat=True) current_position = substrate.tell() @@ -231,7 +229,7 @@ class BitStringPayloadDecoder(AbstractSimplePayloadDecoder): if isinstance(component, SubstrateUnderrunError): yield component - trailingBits = oct2int(component[0]) + trailingBits = component[0] if trailingBits > 7: raise error.PyAsn1Error( 'Trailing bits overflow %s' % trailingBits @@ -260,7 +258,7 @@ class BitStringPayloadDecoder(AbstractSimplePayloadDecoder): # All inner fragments are of the same type, treat them as octet string substrateFun = self.substrateCollector - bitString = self.protoComponent.fromOctetString(null, internalFormat=True) + bitString = self.protoComponent.fromOctetString(b'', internalFormat=True) while True: # loop over fragments @@ -277,7 +275,7 @@ class BitStringPayloadDecoder(AbstractSimplePayloadDecoder): if component is eoo.endOfOctets: break - trailingBits = oct2int(component[0]) + trailingBits = component[0] if trailingBits > 7: raise error.PyAsn1Error( 'Trailing bits overflow %s' % trailingBits @@ -325,7 +323,7 @@ class OctetStringPayloadDecoder(AbstractSimplePayloadDecoder): # All inner fragments are of the same type, treat them as octet string substrateFun = self.substrateCollector - header = null + header = b'' original_position = substrate.tell() # head = popSubstream(substrate, length) @@ -355,7 +353,7 @@ class OctetStringPayloadDecoder(AbstractSimplePayloadDecoder): # All inner fragments are of the same type, treat them as octet string substrateFun = self.substrateCollector - header = null + header = b'' while True: # loop over fragments @@ -417,8 +415,6 @@ class ObjectIdentifierPayloadDecoder(AbstractSimplePayloadDecoder): if not chunk: raise error.PyAsn1Error('Empty substrate') - chunk = octs2ints(chunk) - oid = () index = 0 substrateLen = len(chunk) @@ -477,8 +473,6 @@ class RelativeOIDPayloadDecoder(AbstractSimplePayloadDecoder): if not chunk: raise error.PyAsn1Error('Empty substrate') - chunk = octs2ints(chunk) - reloid = () index = 0 substrateLen = len(chunk) @@ -528,7 +522,7 @@ class RealPayloadDecoder(AbstractSimplePayloadDecoder): yield self._createComponent(asn1Spec, tagSet, 0.0, **options) return - fo = oct2int(chunk[0]) + fo = chunk[0] chunk = chunk[1:] if fo & 0x80: # binary encoding if not chunk: @@ -540,7 +534,7 @@ class RealPayloadDecoder(AbstractSimplePayloadDecoder): n = (fo & 0x03) + 1 if n == 4: - n = oct2int(chunk[0]) + n = chunk[0] chunk = chunk[1:] eo, chunk = chunk[:n], chunk[n:] @@ -548,11 +542,11 @@ class RealPayloadDecoder(AbstractSimplePayloadDecoder): if not eo or not chunk: raise error.PyAsn1Error('Real exponent screwed') - e = oct2int(eo[0]) & 0x80 and -1 or 0 + e = eo[0] & 0x80 and -1 or 0 while eo: # exponent e <<= 8 - e |= oct2int(eo[0]) + e |= eo[0] eo = eo[1:] b = fo >> 4 & 0x03 # base bits @@ -569,7 +563,7 @@ class RealPayloadDecoder(AbstractSimplePayloadDecoder): while chunk: # value p <<= 8 - p |= oct2int(chunk[0]) + p |= chunk[0] chunk = chunk[1:] if fo & 0x40: # sign bit @@ -629,10 +623,10 @@ class ConstructedPayloadDecoderBase(AbstractConstructedPayloadDecoder): protoSequenceComponent = None def _getComponentTagMap(self, asn1Object, idx): - raise NotImplementedError() + raise NotImplementedError def _getComponentPositionByType(self, asn1Object, tagSet, idx): - raise NotImplementedError() + raise NotImplementedError def _decodeComponentsSchemaless( self, substrate, tagSet=None, decodeFun=None, @@ -880,7 +874,8 @@ class ConstructedPayloadDecoderBase(AbstractConstructedPayloadDecoder): else: inconsistency = asn1Object.isInconsistent if inconsistency: - raise inconsistency + raise error.PyAsn1Error( + f"ASN.1 object {asn1Object.__class__.__name__} is inconsistent") else: componentType = asn1Spec.componentType @@ -1105,7 +1100,8 @@ class ConstructedPayloadDecoderBase(AbstractConstructedPayloadDecoder): else: inconsistency = asn1Object.isInconsistent if inconsistency: - raise inconsistency + raise error.PyAsn1Error( + f"ASN.1 object {asn1Object.__class__.__name__} is inconsistent") else: componentType = asn1Spec.componentType @@ -1345,7 +1341,7 @@ class AnyPayloadDecoder(AbstractSimplePayloadDecoder): if isTagged: # tagged Any type -- consume header substrate - chunk = null + chunk = b'' if LOG: LOG('decoding as tagged ANY') @@ -1505,10 +1501,6 @@ TYPE_MAP = { univ.Any.typeId: AnyPayloadDecoder() } -# deprecated aliases, https://github.com/pyasn1/pyasn1/issues/9 -tagMap = TAG_MAP -typeMap = TYPE_MAP - # Put in non-ambiguous types for faster codec lookup for typeDecoder in TAG_MAP.values(): if typeDecoder.protoComponent is not None: @@ -1529,7 +1521,7 @@ for typeDecoder in TAG_MAP.values(): stStop) = [x for x in range(10)] -EOO_SENTINEL = ints2octs((0, 0)) +EOO_SENTINEL = bytes((0, 0)) class SingleItemDecoder(object): @@ -1687,7 +1679,7 @@ class SingleItemDecoder(object): length = 0 for lengthOctet in encodedLength: length <<= 8 - length |= oct2int(lengthOctet) + length |= lengthOctet size += 1 else: # 128 means indefinite @@ -2005,14 +1997,14 @@ class Decoder(object): def __call__(cls, substrate, asn1Spec=None, **options): """Turns BER/CER/DER octet stream into an ASN.1 object. - Takes BER/CER/DER octet-stream in form of :py:class:`bytes` (Python 3) - or :py:class:`str` (Python 2) and decode it into an ASN.1 object + Takes BER/CER/DER octet-stream in form of :py:class:`bytes` + and decode it into an ASN.1 object (e.g. :py:class:`~pyasn1.type.base.PyAsn1Item` derivative) which may be a scalar or an arbitrary nested structure. Parameters ---------- - substrate: :py:class:`bytes` (Python 3) or :py:class:`str` (Python 2) + substrate: :py:class:`bytes` BER/CER/DER octet-stream to parse Keyword Args @@ -2095,9 +2087,8 @@ class Decoder(object): """ try: substrate_gen = origSubstrateFun(asn1Object, substrate, length, options) - except TypeError: - _type, _value, traceback = sys.exc_info() - if traceback.tb_next: + except TypeError as _value: + if _value.__traceback__.tb_next: # Traceback depth > 1 means TypeError from inside user provided function raise # invariant maintained at Decoder.__call__ entry @@ -2119,7 +2110,7 @@ class Decoder(object): tail = next(readFromStream(substrate)) except error.EndOfStreamError: - tail = null + tail = b'' return asn1Object, tail @@ -2142,7 +2133,7 @@ class Decoder(object): #: #: Parameters #: ---------- -#: substrate: :py:class:`bytes` (Python 3) or :py:class:`str` (Python 2) +#: substrate: :py:class:`bytes` #: BER octet-stream #: #: Keyword Args @@ -2190,3 +2181,9 @@ class Decoder(object): #: 1 2 3 #: decode = Decoder() + +def __getattr__(attr: str): + if newAttr := {"tagMap": "TAG_MAP", "typeMap": "TYPE_MAP"}.get(attr): + warnings.warn(f"{attr} is deprecated. Please use {newAttr} instead.", DeprecationWarning) + return globals()[newAttr] + raise AttributeError(attr) diff --git a/contrib/python/pyasn1/py3/pyasn1/codec/ber/encoder.py b/contrib/python/pyasn1/py3/pyasn1/codec/ber/encoder.py index 7cc758ff2b..d16fb1f88b 100644 --- a/contrib/python/pyasn1/py3/pyasn1/codec/ber/encoder.py +++ b/contrib/python/pyasn1/py3/pyasn1/codec/ber/encoder.py @@ -5,14 +5,13 @@ # License: https://pyasn1.readthedocs.io/en/latest/license.html # import sys +import warnings from pyasn1 import debug from pyasn1 import error from pyasn1.codec.ber import eoo from pyasn1.compat import _MISSING from pyasn1.compat.integer import to_bytes -from pyasn1.compat.octets import (int2oct, oct2int, ints2octs, null, - str2octs, isOctetsType) from pyasn1.type import char from pyasn1.type import tag from pyasn1.type import univ @@ -28,7 +27,7 @@ class AbstractItemEncoder(object): # An outcome of otherwise legit call `encodeFun(eoo.endOfOctets)` eooIntegerSubstrate = (0, 0) - eooOctetsSubstrate = ints2octs(eooIntegerSubstrate) + eooOctetsSubstrate = bytes(eooIntegerSubstrate) # noinspection PyMethodMayBeStatic def encodeTag(self, singleTag, isConstructed): @@ -90,7 +89,7 @@ class AbstractItemEncoder(object): defMode = options.get('defMode', True) - substrate = null + substrate = b'' for idx, singleTag in enumerate(tagSet.superTags): @@ -103,10 +102,9 @@ class AbstractItemEncoder(object): value, asn1Spec, encodeFun, **options ) - except error.PyAsn1Error: - exc = sys.exc_info() + except error.PyAsn1Error as exc: raise error.PyAsn1Error( - 'Error encoding %r: %s' % (value, exc[1])) + 'Error encoding %r: %s' % (value, exc)) if LOG: LOG('encoded %svalue %s into %s' % ( @@ -127,16 +125,16 @@ class AbstractItemEncoder(object): if LOG: LOG('encoded %stag %s into %s' % ( isConstructed and 'constructed ' or '', - singleTag, debug.hexdump(ints2octs(header)))) + singleTag, debug.hexdump(bytes(header)))) header += self.encodeLength(len(substrate), defModeOverride) if LOG: LOG('encoded %s octets (tag + payload) into %s' % ( - len(substrate), debug.hexdump(ints2octs(header)))) + len(substrate), debug.hexdump(bytes(header)))) if isOctets: - substrate = ints2octs(header) + substrate + substrate = bytes(header) + substrate if not defModeOverride: substrate += self.eooOctetsSubstrate @@ -148,14 +146,14 @@ class AbstractItemEncoder(object): substrate += self.eooIntegerSubstrate if not isOctets: - substrate = ints2octs(substrate) + substrate = bytes(substrate) return substrate class EndOfOctetsEncoder(AbstractItemEncoder): def encodeValue(self, value, asn1Spec, encodeFun, **options): - return null, False, True + return b'', False, True class BooleanEncoder(AbstractItemEncoder): @@ -200,7 +198,7 @@ class BitStringEncoder(AbstractItemEncoder): maxChunkSize = options.get('maxChunkSize', 0) if not maxChunkSize or len(alignedValue) <= maxChunkSize * 8: substrate = alignedValue.asOctets() - return int2oct(len(substrate) * 8 - valueLength) + substrate, False, True + return bytes((len(substrate) * 8 - valueLength,)) + substrate, False, True if LOG: LOG('encoding into up to %s-octet chunks' % maxChunkSize) @@ -217,7 +215,7 @@ class BitStringEncoder(AbstractItemEncoder): alignedValue = alignedValue.clone(tagSet=tagSet) stop = 0 - substrate = null + substrate = b'' while stop < valueLength: start = stop stop = min(start + maxChunkSize * 8, valueLength) @@ -233,7 +231,7 @@ class OctetStringEncoder(AbstractItemEncoder): if asn1Spec is None: substrate = value.asOctets() - elif not isOctetsType(value): + elif not isinstance(value, bytes): substrate = asn1Spec.clone(value).asOctets() else: @@ -261,7 +259,7 @@ class OctetStringEncoder(AbstractItemEncoder): asn1Spec = value.clone(tagSet=tagSet) - elif not isOctetsType(value): + elif not isinstance(value, bytes): baseTag = asn1Spec.tagSet.baseTag # strip off explicit tags @@ -274,7 +272,7 @@ class OctetStringEncoder(AbstractItemEncoder): asn1Spec = asn1Spec.clone(tagSet=tagSet) pos = 0 - substrate = null + substrate = b'' while True: chunk = value[pos:pos + maxChunkSize] @@ -291,7 +289,7 @@ class NullEncoder(AbstractItemEncoder): supportIndefLenMode = False def encodeValue(self, value, asn1Spec, encodeFun, **options): - return null, False, True + return b'', False, True class ObjectIdentifierEncoder(AbstractItemEncoder): @@ -464,13 +462,13 @@ class RealEncoder(AbstractItemEncoder): m, b, e = value if not m: - return null, False, True + return b'', False, True if b == 10: if LOG: LOG('encoding REAL into character form') - return str2octs('\x03%dE%s%d' % (m, e == 0 and '+' or '', e)), False, True + return b'\x03%dE%s%d' % (m, e == 0 and b'+' or b'', e), False, True elif b == 2: fo = 0x80 # binary encoding @@ -507,20 +505,20 @@ class RealEncoder(AbstractItemEncoder): raise error.PyAsn1Error('Scale factor overflow') # bug if raised fo |= sf << 2 - eo = null + eo = b'' if e == 0 or e == -1: - eo = int2oct(e & 0xff) + eo = bytes((e & 0xff,)) else: while e not in (0, -1): - eo = int2oct(e & 0xff) + eo + eo = bytes((e & 0xff,)) + eo e >>= 8 - if e == 0 and eo and oct2int(eo[0]) & 0x80: - eo = int2oct(0) + eo + if e == 0 and eo and eo[0] & 0x80: + eo = bytes((0,)) + eo - if e == -1 and eo and not (oct2int(eo[0]) & 0x80): - eo = int2oct(0xff) + eo + if e == -1 and eo and not (eo[0] & 0x80): + eo = bytes((0xff,)) + eo n = len(eo) if n > 0xff: @@ -537,15 +535,15 @@ class RealEncoder(AbstractItemEncoder): else: fo |= 3 - eo = int2oct(n & 0xff) + eo + eo = bytes((n & 0xff,)) + eo - po = null + po = b'' while m: - po = int2oct(m & 0xff) + po + po = bytes((m & 0xff,)) + po m >>= 8 - substrate = int2oct(fo) + eo + po + substrate = bytes((fo,)) + eo + po return substrate, False, True @@ -560,7 +558,7 @@ class SequenceEncoder(AbstractItemEncoder): def encodeValue(self, value, asn1Spec, encodeFun, **options): - substrate = null + substrate = b'' omitEmptyOptionals = options.get( 'omitEmptyOptionals', self.omitEmptyOptionals) @@ -573,7 +571,8 @@ class SequenceEncoder(AbstractItemEncoder): # instance of ASN.1 schema inconsistency = value.isInconsistent if inconsistency: - raise inconsistency + raise error.PyAsn1Error( + f"ASN.1 object {value.__class__.__name__} is inconsistent") namedTypes = value.componentType @@ -681,7 +680,8 @@ class SequenceOfEncoder(AbstractItemEncoder): if asn1Spec is None: inconsistency = value.isInconsistent if inconsistency: - raise inconsistency + raise error.PyAsn1Error( + f"ASN.1 object {value.__class__.__name__} is inconsistent") else: asn1Spec = asn1Spec.componentType @@ -709,7 +709,7 @@ class SequenceOfEncoder(AbstractItemEncoder): chunks = self._encodeComponents( value, asn1Spec, encodeFun, **options) - return null.join(chunks), True, True + return b''.join(chunks), True, True class ChoiceEncoder(AbstractItemEncoder): @@ -734,7 +734,7 @@ class AnyEncoder(OctetStringEncoder): def encodeValue(self, value, asn1Spec, encodeFun, **options): if asn1Spec is None: value = value.asOctets() - elif not isOctetsType(value): + elif not isinstance(value, bytes): value = asn1Spec.clone(value).asOctets() return value, not options.get('defMode', True), True @@ -809,10 +809,6 @@ TYPE_MAP = { useful.UTCTime.typeId: OctetStringEncoder() } -# deprecated aliases, https://github.com/pyasn1/pyasn1/issues/9 -tagMap = TAG_MAP -typeMap = TYPE_MAP - class SingleItemEncoder(object): fixedDefLengthMode = None @@ -922,7 +918,7 @@ class Encoder(object): #: #: Returns #: ------- -#: : :py:class:`bytes` (Python 3) or :py:class:`str` (Python 2) +#: : :py:class:`bytes` #: Given ASN.1 object encoded into BER octetstream #: #: Raises @@ -950,3 +946,9 @@ class Encoder(object): #: b'0\t\x02\x01\x01\x02\x01\x02\x02\x01\x03' #: encode = Encoder() + +def __getattr__(attr: str): + if newAttr := {"tagMap": "TAG_MAP", "typeMap": "TYPE_MAP"}.get(attr): + warnings.warn(f"{attr} is deprecated. Please use {newAttr} instead.", DeprecationWarning) + return globals()[newAttr] + raise AttributeError(attr) diff --git a/contrib/python/pyasn1/py3/pyasn1/codec/cer/decoder.py b/contrib/python/pyasn1/py3/pyasn1/codec/cer/decoder.py index ed6391ff35..d6890f018b 100644 --- a/contrib/python/pyasn1/py3/pyasn1/codec/cer/decoder.py +++ b/contrib/python/pyasn1/py3/pyasn1/codec/cer/decoder.py @@ -4,10 +4,11 @@ # Copyright (c) 2005-2020, Ilya Etingof <etingof@gmail.com> # License: https://pyasn1.readthedocs.io/en/latest/license.html # +import warnings + from pyasn1 import error from pyasn1.codec.streaming import readFromStream from pyasn1.codec.ber import decoder -from pyasn1.compat.octets import oct2int from pyasn1.type import univ __all__ = ['decode', 'StreamingDecoder'] @@ -30,7 +31,7 @@ class BooleanPayloadDecoder(decoder.AbstractSimplePayloadDecoder): if isinstance(chunk, SubstrateUnderrunError): yield chunk - byte = oct2int(chunk[0]) + byte = chunk[0] # CER/DER specifies encoding of TRUE as 0xFF and FALSE as 0x0, while # BER allows any non-zero value as TRUE; cf. sections 8.2.2. and 11.1 @@ -62,10 +63,6 @@ TAG_MAP.update( TYPE_MAP = decoder.TYPE_MAP.copy() -# deprecated aliases, https://github.com/pyasn1/pyasn1/issues/9 -tagMap = TAG_MAP -typeMap = TYPE_MAP - # Put in non-ambiguous types for faster codec lookup for typeDecoder in TAG_MAP.values(): if typeDecoder.protoComponent is not None: @@ -101,7 +98,7 @@ class Decoder(decoder.Decoder): #: #: Parameters #: ---------- -#: substrate: :py:class:`bytes` (Python 3) or :py:class:`str` (Python 2) +#: substrate: :py:class:`bytes` #: CER octet-stream #: #: Keyword Args @@ -144,3 +141,9 @@ class Decoder(decoder.Decoder): #: 1 2 3 #: decode = Decoder() + +def __getattr__(attr: str): + if newAttr := {"tagMap": "TAG_MAP", "typeMap": "TYPE_MAP"}.get(attr): + warnings.warn(f"{attr} is deprecated. Please use {newAttr} instead.", DeprecationWarning) + return globals()[newAttr] + raise AttributeError(attr) diff --git a/contrib/python/pyasn1/py3/pyasn1/codec/cer/encoder.py b/contrib/python/pyasn1/py3/pyasn1/codec/cer/encoder.py index 0a198e3fdf..e16e9ece33 100644 --- a/contrib/python/pyasn1/py3/pyasn1/codec/cer/encoder.py +++ b/contrib/python/pyasn1/py3/pyasn1/codec/cer/encoder.py @@ -4,9 +4,10 @@ # Copyright (c) 2005-2020, Ilya Etingof <etingof@gmail.com> # License: https://pyasn1.readthedocs.io/en/latest/license.html # +import warnings + from pyasn1 import error from pyasn1.codec.ber import encoder -from pyasn1.compat.octets import str2octs, null from pyasn1.type import univ from pyasn1.type import useful @@ -116,7 +117,7 @@ class SetOfEncoder(encoder.SequenceOfEncoder): # sort by serialised and padded components if len(chunks) > 1: - zero = str2octs('\x00') + zero = b'\x00' maxLen = max(map(len, chunks)) paddedChunks = [ (x.ljust(maxLen, zero), x) for x in chunks @@ -125,19 +126,19 @@ class SetOfEncoder(encoder.SequenceOfEncoder): chunks = [x[1] for x in paddedChunks] - return null.join(chunks), True, True + return b''.join(chunks), True, True class SequenceOfEncoder(encoder.SequenceOfEncoder): def encodeValue(self, value, asn1Spec, encodeFun, **options): if options.get('ifNotEmpty', False) and not len(value): - return null, True, True + return b'', True, True chunks = self._encodeComponents( value, asn1Spec, encodeFun, **options) - return null.join(chunks), True, True + return b''.join(chunks), True, True class SetEncoder(encoder.SequenceEncoder): @@ -162,7 +163,7 @@ class SetEncoder(encoder.SequenceEncoder): def encodeValue(self, value, asn1Spec, encodeFun, **options): - substrate = null + substrate = b'' comps = [] compsMap = {} @@ -171,7 +172,8 @@ class SetEncoder(encoder.SequenceEncoder): # instance of ASN.1 schema inconsistency = value.isInconsistent if inconsistency: - raise inconsistency + raise error.PyAsn1Error( + f"ASN.1 object {value.__class__.__name__} is inconsistent") namedTypes = value.componentType @@ -260,10 +262,6 @@ TYPE_MAP.update({ univ.SequenceOf.typeId: SequenceOfEncoder() }) -# deprecated aliases, https://github.com/pyasn1/pyasn1/issues/9 -tagMap = TAG_MAP -typeMap = TYPE_MAP - class SingleItemEncoder(encoder.SingleItemEncoder): fixedDefLengthMode = False @@ -295,7 +293,7 @@ class Encoder(encoder.Encoder): #: #: Returns #: ------- -#: : :py:class:`bytes` (Python 3) or :py:class:`str` (Python 2) +#: : :py:class:`bytes` #: Given ASN.1 object encoded into BER octet-stream #: #: Raises @@ -325,3 +323,9 @@ class Encoder(encoder.Encoder): encode = Encoder() # EncoderFactory queries class instance and builds a map of tags -> encoders + +def __getattr__(attr: str): + if newAttr := {"tagMap": "TAG_MAP", "typeMap": "TYPE_MAP"}.get(attr): + warnings.warn(f"{attr} is deprecated. Please use {newAttr} instead.", DeprecationWarning) + return globals()[newAttr] + raise AttributeError(attr) diff --git a/contrib/python/pyasn1/py3/pyasn1/codec/der/decoder.py b/contrib/python/pyasn1/py3/pyasn1/codec/der/decoder.py index 215b72d9fd..d31a8565bb 100644 --- a/contrib/python/pyasn1/py3/pyasn1/codec/der/decoder.py +++ b/contrib/python/pyasn1/py3/pyasn1/codec/der/decoder.py @@ -4,6 +4,8 @@ # Copyright (c) 2005-2020, Ilya Etingof <etingof@gmail.com> # License: https://pyasn1.readthedocs.io/en/latest/license.html # +import warnings + from pyasn1.codec.cer import decoder from pyasn1.type import univ @@ -30,10 +32,6 @@ TAG_MAP.update( TYPE_MAP = decoder.TYPE_MAP.copy() -# deprecated aliases, https://github.com/pyasn1/pyasn1/issues/9 -tagMap = TAG_MAP -typeMap = TYPE_MAP - # Put in non-ambiguous types for faster codec lookup for typeDecoder in TAG_MAP.values(): if typeDecoder.protoComponent is not None: @@ -71,7 +69,7 @@ class Decoder(decoder.Decoder): #: #: Parameters #: ---------- -#: substrate: :py:class:`bytes` (Python 3) or :py:class:`str` (Python 2) +#: substrate: :py:class:`bytes` #: DER octet-stream #: #: Keyword Args @@ -114,3 +112,9 @@ class Decoder(decoder.Decoder): #: 1 2 3 #: decode = Decoder() + +def __getattr__(attr: str): + if newAttr := {"tagMap": "TAG_MAP", "typeMap": "TYPE_MAP"}.get(attr): + warnings.warn(f"{attr} is deprecated. Please use {newAttr} instead.", DeprecationWarning) + return globals()[newAttr] + raise AttributeError(attr) diff --git a/contrib/python/pyasn1/py3/pyasn1/codec/der/encoder.py b/contrib/python/pyasn1/py3/pyasn1/codec/der/encoder.py index c231edc164..f9a361020f 100644 --- a/contrib/python/pyasn1/py3/pyasn1/codec/der/encoder.py +++ b/contrib/python/pyasn1/py3/pyasn1/codec/der/encoder.py @@ -4,6 +4,8 @@ # Copyright (c) 2005-2020, Ilya Etingof <etingof@gmail.com> # License: https://pyasn1.readthedocs.io/en/latest/license.html # +import warnings + from pyasn1 import error from pyasn1.codec.cer import encoder from pyasn1.type import univ @@ -57,10 +59,6 @@ TYPE_MAP.update({ univ.Set.typeId: SetEncoder() }) -# deprecated aliases, https://github.com/pyasn1/pyasn1/issues/9 -tagMap = TAG_MAP -typeMap = TYPE_MAP - class SingleItemEncoder(encoder.SingleItemEncoder): fixedDefLengthMode = True @@ -92,7 +90,7 @@ class Encoder(encoder.Encoder): #: #: Returns #: ------- -#: : :py:class:`bytes` (Python 3) or :py:class:`str` (Python 2) +#: : :py:class:`bytes` #: Given ASN.1 object encoded into BER octet-stream #: #: Raises @@ -120,3 +118,9 @@ class Encoder(encoder.Encoder): #: b'0\t\x02\x01\x01\x02\x01\x02\x02\x01\x03' #: encode = Encoder() + +def __getattr__(attr: str): + if newAttr := {"tagMap": "TAG_MAP", "typeMap": "TYPE_MAP"}.get(attr): + warnings.warn(f"{attr} is deprecated. Please use {newAttr} instead.", DeprecationWarning) + return globals()[newAttr] + raise AttributeError(attr) diff --git a/contrib/python/pyasn1/py3/pyasn1/codec/native/decoder.py b/contrib/python/pyasn1/py3/pyasn1/codec/native/decoder.py index a63bfce9b3..9ac01ff6f3 100644 --- a/contrib/python/pyasn1/py3/pyasn1/codec/native/decoder.py +++ b/contrib/python/pyasn1/py3/pyasn1/codec/native/decoder.py @@ -4,6 +4,8 @@ # Copyright (c) 2005-2020, Ilya Etingof <etingof@gmail.com> # License: https://pyasn1.readthedocs.io/en/latest/license.html # +import warnings + from pyasn1 import debug from pyasn1 import error from pyasn1.compat import _MISSING @@ -133,11 +135,6 @@ TYPE_MAP = { } -# deprecated aliases, https://github.com/pyasn1/pyasn1/issues/9 -tagMap = TAG_MAP -typeMap = TYPE_MAP - - class SingleItemDecoder(object): TAG_MAP = TAG_MAP @@ -239,3 +236,9 @@ class Decoder(object): #: 1 2 3 #: decode = Decoder() + +def __getattr__(attr: str): + if newAttr := {"tagMap": "TAG_MAP", "typeMap": "TYPE_MAP"}.get(attr): + warnings.warn(f"{attr} is deprecated. Please use {newAttr} instead.", DeprecationWarning) + return globals()[newAttr] + raise AttributeError(attr) diff --git a/contrib/python/pyasn1/py3/pyasn1/codec/native/encoder.py b/contrib/python/pyasn1/py3/pyasn1/codec/native/encoder.py index 421815e806..6219ae458c 100644 --- a/contrib/python/pyasn1/py3/pyasn1/codec/native/encoder.py +++ b/contrib/python/pyasn1/py3/pyasn1/codec/native/encoder.py @@ -5,6 +5,7 @@ # License: https://pyasn1.readthedocs.io/en/latest/license.html # from collections import OrderedDict +import warnings from pyasn1 import debug from pyasn1 import error @@ -76,7 +77,8 @@ class SetEncoder(AbstractItemEncoder): def encode(self, value, encodeFun, **options): inconsistency = value.isInconsistent if inconsistency: - raise inconsistency + raise error.PyAsn1Error( + f"ASN.1 object {value.__class__.__name__} is inconsistent") namedTypes = value.componentType substrate = self.protoDict() @@ -96,7 +98,8 @@ class SequenceOfEncoder(AbstractItemEncoder): def encode(self, value, encodeFun, **options): inconsistency = value.isInconsistent if inconsistency: - raise inconsistency + raise error.PyAsn1Error( + f"ASN.1 object {value.__class__.__name__} is inconsistent") return [encodeFun(x, **options) for x in value] @@ -177,10 +180,6 @@ TYPE_MAP = { useful.UTCTime.typeId: OctetStringEncoder() } -# deprecated aliases, https://github.com/pyasn1/pyasn1/issues/9 -tagMap = TAG_MAP -typeMap = TYPE_MAP - class SingleItemEncoder(object): @@ -278,3 +277,9 @@ class Encoder(object): #: [1, 2, 3] #: encode = SingleItemEncoder() + +def __getattr__(attr: str): + if newAttr := {"tagMap": "TAG_MAP", "typeMap": "TYPE_MAP"}.get(attr): + warnings.warn(f"{attr} is deprecated. Please use {newAttr} instead.", DeprecationWarning) + return globals()[newAttr] + raise AttributeError(attr) diff --git a/contrib/python/pyasn1/py3/pyasn1/codec/streaming.py b/contrib/python/pyasn1/py3/pyasn1/codec/streaming.py index 231681c177..c35f24899b 100644 --- a/contrib/python/pyasn1/py3/pyasn1/codec/streaming.py +++ b/contrib/python/pyasn1/py3/pyasn1/codec/streaming.py @@ -6,14 +6,10 @@ # import io import os -import sys from pyasn1 import error from pyasn1.type import univ -_PY2 = sys.version_info < (3,) - - class CachingStreamWrapper(io.IOBase): """Wrapper around non-seekable streams. @@ -108,14 +104,8 @@ def asSeekableStream(substrate): return io.BytesIO(substrate.asOctets()) try: - # Special case: impossible to set attributes on `file` built-in - # XXX: broken, BufferedReader expects a "readable" attribute. - if _PY2 and isinstance(substrate, file): - return io.BufferedReader(substrate) - - elif substrate.seekable(): # Will fail for most invalid types + if substrate.seekable(): # Will fail for most invalid types return substrate - else: return CachingStreamWrapper(substrate) diff --git a/contrib/python/pyasn1/py3/pyasn1/compat/integer.py b/contrib/python/pyasn1/py3/pyasn1/compat/integer.py index b41d849fcd..306210e5d9 100644 --- a/contrib/python/pyasn1/py3/pyasn1/compat/integer.py +++ b/contrib/python/pyasn1/py3/pyasn1/compat/integer.py @@ -4,100 +4,10 @@ # Copyright (c) 2005-2020, Ilya Etingof <etingof@gmail.com> # License: https://pyasn1.readthedocs.io/en/latest/license.html # -import sys -import platform +def to_bytes(value, signed=False, length=0): + length = max(value.bit_length(), length) -from pyasn1.compat.octets import oct2int, null, ensureString + if signed and length % 8 == 0: + length += 1 - -implementation = platform.python_implementation() - -if sys.version_info[0] < 3: - from binascii import a2b_hex, b2a_hex - - def from_bytes(octets, signed=False): - if not octets: - return 0 - - value = long(b2a_hex(ensureString(octets)), 16) - - if signed and oct2int(octets[0]) & 0x80: - return value - (1 << len(octets) * 8) - - return value - - def to_bytes(value, signed=False, length=0): - if value < 0: - if signed: - bits = bitLength(value) - - # two's complement form - maxValue = 1 << bits - valueToEncode = (value + maxValue) % maxValue - - else: - raise OverflowError('can\'t convert negative int to unsigned') - elif value == 0 and length == 0: - return null - else: - bits = 0 - valueToEncode = value - - hexValue = hex(valueToEncode)[2:] - if hexValue.endswith('L'): - hexValue = hexValue[:-1] - - if len(hexValue) & 1: - hexValue = '0' + hexValue - - # padding may be needed for two's complement encoding - if value != valueToEncode or length: - hexLength = len(hexValue) * 4 - - padLength = max(length, bits) - - if padLength > hexLength: - hexValue = '00' * ((padLength - hexLength - 1) // 8 + 1) + hexValue - elif length and hexLength - length > 7: - raise OverflowError('int too big to convert') - - firstOctet = int(hexValue[:2], 16) - - if signed: - if firstOctet & 0x80: - if value >= 0: - hexValue = '00' + hexValue - elif value < 0: - hexValue = 'ff' + hexValue - - octets_value = a2b_hex(hexValue) - - return octets_value - - def bitLength(number): - # bits in unsigned number - hexValue = hex(abs(number)) - bits = len(hexValue) - 2 - if hexValue.endswith('L'): - bits -= 1 - if bits & 1: - bits += 1 - bits *= 4 - # TODO: strip lhs zeros - return bits - -else: - - def from_bytes(octets, signed=False): - return int.from_bytes(bytes(octets), 'big', signed=signed) - - def to_bytes(value, signed=False, length=0): - length = max(value.bit_length(), length) - - if signed and length % 8 == 0: - length += 1 - - return value.to_bytes(length // 8 + (length % 8 and 1 or 0), 'big', signed=signed) - - def bitLength(number): - return int(number).bit_length() + return value.to_bytes(length // 8 + (length % 8 and 1 or 0), 'big', signed=signed) diff --git a/contrib/python/pyasn1/py3/pyasn1/compat/octets.py b/contrib/python/pyasn1/py3/pyasn1/compat/octets.py deleted file mode 100644 index d871f46c8a..0000000000 --- a/contrib/python/pyasn1/py3/pyasn1/compat/octets.py +++ /dev/null @@ -1,46 +0,0 @@ -# -# This file is part of pyasn1 software. -# -# Copyright (c) 2005-2020, Ilya Etingof <etingof@gmail.com> -# License: https://pyasn1.readthedocs.io/en/latest/license.html -# -from sys import version_info - -if version_info[0] <= 2: - int2oct = chr - # noinspection PyPep8 - ints2octs = lambda s: ''.join([int2oct(x) for x in s]) - null = '' - oct2int = ord - # TODO: refactor to return a sequence of ints - # noinspection PyPep8 - octs2ints = lambda s: [oct2int(x) for x in s] - # noinspection PyPep8 - str2octs = lambda x: x - # noinspection PyPep8 - octs2str = lambda x: x - # noinspection PyPep8 - isOctetsType = lambda s: isinstance(s, str) - # noinspection PyPep8 - isStringType = lambda s: isinstance(s, (str, unicode)) - # noinspection PyPep8 - ensureString = str -else: - ints2octs = bytes - # noinspection PyPep8 - int2oct = lambda x: ints2octs((x,)) - null = ints2octs() - # noinspection PyPep8 - oct2int = lambda x: x - # noinspection PyPep8 - octs2ints = lambda x: x - # noinspection PyPep8 - str2octs = lambda x: x.encode('iso-8859-1') - # noinspection PyPep8 - octs2str = lambda x: x.decode('iso-8859-1') - # noinspection PyPep8 - isOctetsType = lambda s: isinstance(s, bytes) - # noinspection PyPep8 - isStringType = lambda s: isinstance(s, str) - # noinspection PyPep8 - ensureString = bytes diff --git a/contrib/python/pyasn1/py3/pyasn1/debug.py b/contrib/python/pyasn1/py3/pyasn1/debug.py index 6be80c3a70..0719423546 100644 --- a/contrib/python/pyasn1/py3/pyasn1/debug.py +++ b/contrib/python/pyasn1/py3/pyasn1/debug.py @@ -9,7 +9,6 @@ import sys from pyasn1 import __version__ from pyasn1 import error -from pyasn1.compat.octets import octs2ints __all__ = ['Debug', 'setLogger', 'hexdump'] @@ -127,7 +126,7 @@ def registerLoggee(module, name='LOG', flags=DEBUG_NONE): def hexdump(octets): return ' '.join( ['%s%.2X' % (n % 16 == 0 and ('\n%.5d: ' % n) or '', x) - for n, x in zip(range(len(octets)), octs2ints(octets))] + for n, x in zip(range(len(octets)), octets)] ) diff --git a/contrib/python/pyasn1/py3/pyasn1/type/base.py b/contrib/python/pyasn1/py3/pyasn1/type/base.py index ac92c51afb..aa86e520c8 100644 --- a/contrib/python/pyasn1/py3/pyasn1/type/base.py +++ b/contrib/python/pyasn1/py3/pyasn1/type/base.py @@ -140,7 +140,7 @@ class Asn1Type(Asn1Item): return True def prettyPrint(self, scope=0): - raise NotImplementedError() + raise NotImplementedError # backward compatibility @@ -267,9 +267,8 @@ class SimpleAsn1Type(Asn1Type): try: self.subtypeSpec(value) - except error.PyAsn1Error: - exType, exValue, exTb = sys.exc_info() - raise exType('%s at %s' % (exValue, self.__class__.__name__)) + except error.PyAsn1Error as exValue: + raise type(exValue)('%s at %s' % (exValue, self.__class__.__name__)) self._value = value @@ -290,7 +289,9 @@ class SimpleAsn1Type(Asn1Type): return '<%s>' % representation def __eq__(self, other): - return self is other and True or self._value == other + if self is other: + return True + return self._value == other def __ne__(self, other): return self._value != other @@ -307,12 +308,8 @@ class SimpleAsn1Type(Asn1Type): def __ge__(self, other): return self._value >= other - if sys.version_info[0] <= 2: - def __nonzero__(self): - return self._value and True or False - else: - def __bool__(self): - return self._value and True or False + def __bool__(self): + return bool(self._value) def __hash__(self): return hash(self._value) @@ -563,12 +560,8 @@ class ConstructedAsn1Type(Asn1Type): def __ge__(self, other): return self.components >= other - if sys.version_info[0] <= 2: - def __nonzero__(self): - return bool(self.components) - else: - def __bool__(self): - return bool(self.components) + def __bool__(self): + return bool(self.components) @property def components(self): diff --git a/contrib/python/pyasn1/py3/pyasn1/type/char.py b/contrib/python/pyasn1/py3/pyasn1/type/char.py index 13fbc7fa27..ec65f00621 100644 --- a/contrib/python/pyasn1/py3/pyasn1/type/char.py +++ b/contrib/python/pyasn1/py3/pyasn1/type/char.py @@ -22,15 +22,14 @@ class AbstractCharacterString(univ.OctetString): """Creates |ASN.1| schema or value object. |ASN.1| class is based on :class:`~pyasn1.type.base.SimpleAsn1Type`, - its objects are immutable and duck-type Python 2 :class:`str` or Python 3 - :class:`bytes`. When used in octet-stream context, |ASN.1| type assumes + its objects are immutable and duck-type :class:`bytes`. + When used in octet-stream context, |ASN.1| type assumes "|encoding|" encoding. Keyword Args ------------ - value: :class:`unicode`, :class:`str`, :class:`bytes` or |ASN.1| object - :class:`unicode` object (Python 2) or :class:`str` (Python 3), - alternatively :class:`str` (Python 2) or :class:`bytes` (Python 3) + value: :class:`str`, :class:`bytes` or |ASN.1| object + :class:`str`, alternatively :class:`bytes` representing octet-stream of serialised unicode string (note `encoding` parameter) or |ASN.1| class instance. If `value` is not given, schema object will be created. @@ -44,8 +43,8 @@ class AbstractCharacterString(univ.OctetString): instantiation. encoding: :py:class:`str` - Unicode codec ID to encode/decode :class:`unicode` (Python 2) or - :class:`str` (Python 3) the payload when |ASN.1| object is used + Unicode codec ID to encode/decode + :class:`str` the payload when |ASN.1| object is used in octet-stream context. Raises @@ -54,88 +53,42 @@ class AbstractCharacterString(univ.OctetString): On constraint violation or bad initializer. """ - if sys.version_info[0] <= 2: - def __str__(self): - try: - # `str` is Py2 text representation - return self._value.encode(self.encoding) - - except UnicodeEncodeError: - exc = sys.exc_info()[1] - raise error.PyAsn1UnicodeEncodeError( - "Can't encode string '%s' with codec " - "%s" % (self._value, self.encoding), exc - ) - - def __unicode__(self): - return unicode(self._value) - - def prettyIn(self, value): - try: - if isinstance(value, unicode): - return value - elif isinstance(value, str): - return value.decode(self.encoding) - elif isinstance(value, (tuple, list)): - return self.prettyIn(''.join([chr(x) for x in value])) - elif isinstance(value, univ.OctetString): - return value.asOctets().decode(self.encoding) - else: - return unicode(value) - - except (UnicodeDecodeError, LookupError): - exc = sys.exc_info()[1] - raise error.PyAsn1UnicodeDecodeError( - "Can't decode string '%s' with codec " - "%s" % (value, self.encoding), exc - ) - - def asOctets(self, padding=True): - return str(self) - - def asNumbers(self, padding=True): - return tuple([ord(x) for x in str(self)]) - - else: - def __str__(self): - # `unicode` is Py3 text representation - return str(self._value) - - def __bytes__(self): - try: - return self._value.encode(self.encoding) - except UnicodeEncodeError: - exc = sys.exc_info()[1] - raise error.PyAsn1UnicodeEncodeError( - "Can't encode string '%s' with codec " - "%s" % (self._value, self.encoding), exc - ) - - def prettyIn(self, value): - try: - if isinstance(value, str): - return value - elif isinstance(value, bytes): - return value.decode(self.encoding) - elif isinstance(value, (tuple, list)): - return self.prettyIn(bytes(value)) - elif isinstance(value, univ.OctetString): - return value.asOctets().decode(self.encoding) - else: - return str(value) - - except (UnicodeDecodeError, LookupError): - exc = sys.exc_info()[1] - raise error.PyAsn1UnicodeDecodeError( - "Can't decode string '%s' with codec " - "%s" % (value, self.encoding), exc - ) - - def asOctets(self, padding=True): - return bytes(self) - - def asNumbers(self, padding=True): - return tuple(bytes(self)) + def __str__(self): + return str(self._value) + + def __bytes__(self): + try: + return self._value.encode(self.encoding) + except UnicodeEncodeError as exc: + raise error.PyAsn1UnicodeEncodeError( + "Can't encode string '%s' with codec " + "%s" % (self._value, self.encoding), exc + ) + + def prettyIn(self, value): + try: + if isinstance(value, str): + return value + elif isinstance(value, bytes): + return value.decode(self.encoding) + elif isinstance(value, (tuple, list)): + return self.prettyIn(bytes(value)) + elif isinstance(value, univ.OctetString): + return value.asOctets().decode(self.encoding) + else: + return str(value) + + except (UnicodeDecodeError, LookupError) as exc: + raise error.PyAsn1UnicodeDecodeError( + "Can't decode string '%s' with codec " + "%s" % (value, self.encoding), exc + ) + + def asOctets(self, padding=True): + return bytes(self) + + def asNumbers(self, padding=True): + return tuple(bytes(self)) # # See OctetString.prettyPrint() for the explanation diff --git a/contrib/python/pyasn1/py3/pyasn1/type/constraint.py b/contrib/python/pyasn1/py3/pyasn1/type/constraint.py index 34b0060d9f..02368d0a3c 100644 --- a/contrib/python/pyasn1/py3/pyasn1/type/constraint.py +++ b/contrib/python/pyasn1/py3/pyasn1/type/constraint.py @@ -31,9 +31,9 @@ class AbstractConstraint(object): try: self._testValue(value, idx) - except error.ValueConstraintError: + except error.ValueConstraintError as exc: raise error.ValueConstraintError( - '%s failed at: %r' % (self, sys.exc_info()[1]) + '%s failed at: %r' % (self, exc) ) def __repr__(self): @@ -46,7 +46,9 @@ class AbstractConstraint(object): return '<%s>' % representation def __eq__(self, other): - return self is other and True or self._values == other + if self is other: + return True + return self._values == other def __ne__(self, other): return self._values != other @@ -63,12 +65,8 @@ class AbstractConstraint(object): def __ge__(self, other): return self._values >= other - if sys.version_info[0] <= 2: - def __nonzero__(self): - return self._values and True or False - else: - def __bool__(self): - return self._values and True or False + def __bool__(self): + return bool(self._values) def __hash__(self): return self.__hash @@ -150,9 +148,6 @@ class SingleValueConstraint(AbstractConstraint): def __iter__(self): return iter(self._set) - def __sub__(self, constraint): - return self.__class__(*(self._set.difference(constraint))) - def __add__(self, constraint): return self.__class__(*(self._set.union(constraint))) diff --git a/contrib/python/pyasn1/py3/pyasn1/type/namedtype.py b/contrib/python/pyasn1/py3/pyasn1/type/namedtype.py index 8dbc81f3c7..5f6c4ca352 100644 --- a/contrib/python/pyasn1/py3/pyasn1/type/namedtype.py +++ b/contrib/python/pyasn1/py3/pyasn1/type/namedtype.py @@ -13,13 +13,6 @@ from pyasn1.type import tagmap __all__ = ['NamedType', 'OptionalNamedType', 'DefaultedNamedType', 'NamedTypes'] -try: - any - -except NameError: - any = lambda x: bool(filter(bool, x)) - - class NamedType(object): """Create named field object for a constructed ASN.1 type. @@ -211,12 +204,8 @@ class NamedTypes(object): def __iter__(self): return (x[0] for x in self.__namedTypes) - if sys.version_info[0] <= 2: - def __nonzero__(self): - return self.__namedTypesLen > 0 - else: - def __bool__(self): - return self.__namedTypesLen > 0 + def __bool__(self): + return self.__namedTypesLen > 0 def __len__(self): return self.__namedTypesLen diff --git a/contrib/python/pyasn1/py3/pyasn1/type/tag.py b/contrib/python/pyasn1/py3/pyasn1/type/tag.py index a21a405eb1..ccb8b00cad 100644 --- a/contrib/python/pyasn1/py3/pyasn1/type/tag.py +++ b/contrib/python/pyasn1/py3/pyasn1/type/tag.py @@ -98,7 +98,7 @@ class Tag(object): elif idx == 2: return self.__tagId else: - raise IndexError() + raise IndexError def __iter__(self): yield self.__tagClass diff --git a/contrib/python/pyasn1/py3/pyasn1/type/tagmap.py b/contrib/python/pyasn1/py3/pyasn1/type/tagmap.py index 2f0e660264..7f8a955ac2 100644 --- a/contrib/python/pyasn1/py3/pyasn1/type/tagmap.py +++ b/contrib/python/pyasn1/py3/pyasn1/type/tagmap.py @@ -46,7 +46,7 @@ class TagMap(object): return self.__presentTypes[tagSet] except KeyError: if self.__defaultType is None: - raise KeyError() + raise elif tagSet in self.__skipTypes: raise error.PyAsn1Error('Key in negative map') else: diff --git a/contrib/python/pyasn1/py3/pyasn1/type/univ.py b/contrib/python/pyasn1/py3/pyasn1/type/univ.py index 28e32bd9d0..9aff5e6951 100644 --- a/contrib/python/pyasn1/py3/pyasn1/type/univ.py +++ b/contrib/python/pyasn1/py3/pyasn1/type/univ.py @@ -10,7 +10,6 @@ import sys from pyasn1 import error from pyasn1.codec.ber import eoo from pyasn1.compat import integer -from pyasn1.compat import octets from pyasn1.type import base from pyasn1.type import constraint from pyasn1.type import namedtype @@ -165,40 +164,23 @@ class Integer(base.SimpleAsn1Type): def __rfloordiv__(self, value): return self.clone(value // self._value) - if sys.version_info[0] <= 2: - def __div__(self, value): - if isinstance(value, float): - return Real(self._value / value) - else: - return self.clone(self._value / value) - - def __rdiv__(self, value): - if isinstance(value, float): - return Real(value / self._value) - else: - return self.clone(value / self._value) - else: - def __truediv__(self, value): - return Real(self._value / value) + def __truediv__(self, value): + return Real(self._value / value) - def __rtruediv__(self, value): - return Real(value / self._value) + def __rtruediv__(self, value): + return Real(value / self._value) - def __divmod__(self, value): - return self.clone(divmod(self._value, value)) + def __divmod__(self, value): + return self.clone(divmod(self._value, value)) - def __rdivmod__(self, value): - return self.clone(divmod(value, self._value)) + def __rdivmod__(self, value): + return self.clone(divmod(value, self._value)) - __hash__ = base.SimpleAsn1Type.__hash__ + __hash__ = base.SimpleAsn1Type.__hash__ def __int__(self): return int(self._value) - if sys.version_info[0] <= 2: - def __long__(self): - return long(self._value) - def __float__(self): return float(self._value) @@ -259,9 +241,9 @@ class Integer(base.SimpleAsn1Type): try: return self.namedValues[value] - except KeyError: + except KeyError as exc: raise error.PyAsn1Error( - 'Can\'t coerce %r into integer: %s' % (value, sys.exc_info()[1]) + 'Can\'t coerce %r into integer: %s' % (value, exc) ) def prettyOut(self, value): @@ -340,23 +322,18 @@ class Boolean(Integer): # Optimization for faster codec lookup typeId = Integer.getTypeId() -if sys.version_info[0] < 3: - SizedIntegerBase = long -else: - SizedIntegerBase = int - -class SizedInteger(SizedIntegerBase): +class SizedInteger(int): bitLength = leadingZeroBits = None def setBitLength(self, bitLength): self.bitLength = bitLength - self.leadingZeroBits = max(bitLength - integer.bitLength(self), 0) + self.leadingZeroBits = max(bitLength - self.bit_length(), 0) return self def __len__(self): if self.bitLength is None: - self.setBitLength(integer.bitLength(self)) + self.setBitLength(self.bit_length()) return self.bitLength @@ -556,17 +533,13 @@ class BitString(base.SimpleAsn1Type): def __float__(self): return float(self._value) - if sys.version_info[0] < 3: - def __long__(self): - return self._value - def asNumbers(self): """Get |ASN.1| value as a sequence of 8-bit integers. If |ASN.1| object length is not a multiple of 8, result will be left-padded with zeros. """ - return tuple(octets.octs2ints(self.asOctets())) + return tuple(self.asOctets()) def asOctets(self): """Get |ASN.1| value as a sequence of octets. @@ -599,8 +572,8 @@ class BitString(base.SimpleAsn1Type): try: value = SizedInteger(value, 16).setBitLength(len(value) * 4) - except ValueError: - raise error.PyAsn1Error('%s.fromHexString() error: %s' % (cls.__name__, sys.exc_info()[1])) + except ValueError as exc: + raise error.PyAsn1Error('%s.fromHexString() error: %s' % (cls.__name__, exc)) if prepend is not None: value = SizedInteger( @@ -624,8 +597,8 @@ class BitString(base.SimpleAsn1Type): try: value = SizedInteger(value or '0', 2).setBitLength(len(value)) - except ValueError: - raise error.PyAsn1Error('%s.fromBinaryString() error: %s' % (cls.__name__, sys.exc_info()[1])) + except ValueError as exc: + raise error.PyAsn1Error('%s.fromBinaryString() error: %s' % (cls.__name__, exc)) if prepend is not None: value = SizedInteger( @@ -643,10 +616,10 @@ class BitString(base.SimpleAsn1Type): Parameters ---------- - value: :class:`str` (Py2) or :class:`bytes` (Py3) - Text string like '\\\\x01\\\\xff' (Py2) or b'\\\\x01\\\\xff' (Py3) + value: :class:`bytes` + Text string like b'\\\\x01\\\\xff' """ - value = SizedInteger(integer.from_bytes(value) >> padding).setBitLength(len(value) * 8 - padding) + value = SizedInteger(int.from_bytes(bytes(value), 'big') >> padding).setBitLength(len(value) * 8 - padding) if prepend is not None: value = SizedInteger( @@ -661,7 +634,7 @@ class BitString(base.SimpleAsn1Type): def prettyIn(self, value): if isinstance(value, SizedInteger): return value - elif octets.isStringType(value): + elif isinstance(value, str): if not value: return SizedInteger(0).setBitLength(0) @@ -708,7 +681,7 @@ class BitString(base.SimpleAsn1Type): elif isinstance(value, BitString): return SizedInteger(value).setBitLength(len(value)) - elif isinstance(value, intTypes): + elif isinstance(value, int): return SizedInteger(value) else: @@ -721,15 +694,14 @@ class OctetString(base.SimpleAsn1Type): """Create |ASN.1| schema or value object. |ASN.1| class is based on :class:`~pyasn1.type.base.SimpleAsn1Type`, its - objects are immutable and duck-type Python 2 :class:`str` or - Python 3 :class:`bytes`. When used in Unicode context, |ASN.1| type + objects are immutable and duck-type :class:`bytes`. + When used in Unicode context, |ASN.1| type assumes "|encoding|" serialisation. Keyword Args ------------ value: :class:`unicode`, :class:`str`, :class:`bytes` or |ASN.1| object - class:`str` (Python 2) or :class:`bytes` (Python 3), alternatively - class:`unicode` object (Python 2) or :class:`str` (Python 3) + :class:`bytes`, alternatively :class:`str` representing character string to be serialised into octets (note `encoding` parameter) or |ASN.1| object. If `value` is not given, schema object will be created. @@ -743,8 +715,8 @@ class OctetString(base.SimpleAsn1Type): instantiation. encoding: :py:class:`str` - Unicode codec ID to encode/decode :class:`unicode` (Python 2) or - :class:`str` (Python 3) the payload when |ASN.1| object is used + Unicode codec ID to encode/decode + :class:`str` the payload when |ASN.1| object is used in text string context. binValue: :py:class:`str` @@ -821,101 +793,50 @@ class OctetString(base.SimpleAsn1Type): base.SimpleAsn1Type.__init__(self, value, **kwargs) - if sys.version_info[0] <= 2: - def prettyIn(self, value): - if isinstance(value, str): - return value - - elif isinstance(value, unicode): - try: - return value.encode(self.encoding) - - except (LookupError, UnicodeEncodeError): - exc = sys.exc_info()[1] - raise error.PyAsn1UnicodeEncodeError( - "Can't encode string '%s' with codec " - "%s" % (value, self.encoding), exc - ) - - elif isinstance(value, (tuple, list)): - try: - return ''.join([chr(x) for x in value]) - - except ValueError: - raise error.PyAsn1Error( - "Bad %s initializer '%s'" % (self.__class__.__name__, value) - ) - - else: - return str(value) - - def __str__(self): - return str(self._value) + def prettyIn(self, value): + if isinstance(value, bytes): + return value - def __unicode__(self): + elif isinstance(value, str): try: - return self._value.decode(self.encoding) + return value.encode(self.encoding) - except UnicodeDecodeError: - exc = sys.exc_info()[1] - raise error.PyAsn1UnicodeDecodeError( - "Can't decode string '%s' with codec " - "%s" % (self._value, self.encoding), exc + except UnicodeEncodeError as exc: + raise error.PyAsn1UnicodeEncodeError( + "Can't encode string '%s' with '%s' " + "codec" % (value, self.encoding), exc ) + elif isinstance(value, OctetString): # a shortcut, bytes() would work the same way + return value.asOctets() - def asOctets(self): - return str(self._value) - - def asNumbers(self): - return tuple([ord(x) for x in self._value]) + elif isinstance(value, base.SimpleAsn1Type): # this mostly targets Integer objects + return self.prettyIn(str(value)) - else: - def prettyIn(self, value): - if isinstance(value, bytes): - return value - - elif isinstance(value, str): - try: - return value.encode(self.encoding) - - except UnicodeEncodeError: - exc = sys.exc_info()[1] - raise error.PyAsn1UnicodeEncodeError( - "Can't encode string '%s' with '%s' " - "codec" % (value, self.encoding), exc - ) - elif isinstance(value, OctetString): # a shortcut, bytes() would work the same way - return value.asOctets() - - elif isinstance(value, base.SimpleAsn1Type): # this mostly targets Integer objects - return self.prettyIn(str(value)) + elif isinstance(value, (tuple, list)): + return self.prettyIn(bytes(value)) - elif isinstance(value, (tuple, list)): - return self.prettyIn(bytes(value)) + else: + return bytes(value) - else: - return bytes(value) + def __str__(self): + try: + return self._value.decode(self.encoding) - def __str__(self): - try: - return self._value.decode(self.encoding) - - except UnicodeDecodeError: - exc = sys.exc_info()[1] - raise error.PyAsn1UnicodeDecodeError( - "Can't decode string '%s' with '%s' codec at " - "'%s'" % (self._value, self.encoding, - self.__class__.__name__), exc - ) + except UnicodeDecodeError as exc: + raise error.PyAsn1UnicodeDecodeError( + "Can't decode string '%s' with '%s' codec at " + "'%s'" % (self._value, self.encoding, + self.__class__.__name__), exc + ) - def __bytes__(self): - return bytes(self._value) + def __bytes__(self): + return bytes(self._value) - def asOctets(self): - return bytes(self._value) + def asOctets(self): + return bytes(self._value) - def asNumbers(self): - return tuple(self._value) + def asNumbers(self): + return tuple(self._value) # # Normally, `.prettyPrint()` is called from `__str__()`. Historically, @@ -984,7 +905,7 @@ class OctetString(base.SimpleAsn1Type): r.append(byte) - return octets.ints2octs(r) + return bytes(r) @staticmethod def fromHexString(value): @@ -1006,7 +927,7 @@ class OctetString(base.SimpleAsn1Type): if p: r.append(int(p + '0', 16)) - return octets.ints2octs(r) + return bytes(r) # Immutable sequence object protocol @@ -1087,7 +1008,7 @@ class Null(OctetString): tagSet = tag.initTagSet( tag.Tag(tag.tagClassUniversal, tag.tagFormatSimple, 0x05) ) - subtypeSpec = OctetString.subtypeSpec + constraint.SingleValueConstraint(octets.str2octs('')) + subtypeSpec = OctetString.subtypeSpec + constraint.SingleValueConstraint(b'') # Optimization for faster codec lookup typeId = OctetString.getTypeId() @@ -1096,14 +1017,7 @@ class Null(OctetString): if value: return value - return octets.str2octs('') - -if sys.version_info[0] <= 2: - intTypes = (int, long) -else: - intTypes = (int,) - -numericTypes = intTypes + (float,) + return b'' class ObjectIdentifier(base.SimpleAsn1Type): @@ -1215,24 +1129,25 @@ class ObjectIdentifier(base.SimpleAsn1Type): def prettyIn(self, value): if isinstance(value, ObjectIdentifier): return tuple(value) - elif octets.isStringType(value): + elif isinstance(value, str): if '-' in value: raise error.PyAsn1Error( + # sys.exc_info in case prettyIn was called while handling an exception 'Malformed Object ID %s at %s: %s' % (value, self.__class__.__name__, sys.exc_info()[1]) ) try: return tuple([int(subOid) for subOid in value.split('.') if subOid]) - except ValueError: + except ValueError as exc: raise error.PyAsn1Error( - 'Malformed Object ID %s at %s: %s' % (value, self.__class__.__name__, sys.exc_info()[1]) + 'Malformed Object ID %s at %s: %s' % (value, self.__class__.__name__, exc) ) try: tupleOfInts = tuple([int(subOid) for subOid in value if subOid >= 0]) - except (ValueError, TypeError): + except (ValueError, TypeError) as exc: raise error.PyAsn1Error( - 'Malformed Object ID %s at %s: %s' % (value, self.__class__.__name__, sys.exc_info()[1]) + 'Malformed Object ID %s at %s: %s' % (value, self.__class__.__name__, exc) ) if len(tupleOfInts) == len(value): @@ -1343,24 +1258,25 @@ class RelativeOID(base.SimpleAsn1Type): def prettyIn(self, value): if isinstance(value, RelativeOID): return tuple(value) - elif octets.isStringType(value): + elif isinstance(value, str): if '-' in value: raise error.PyAsn1Error( + # sys.exc_info in case prettyIn was called while handling an exception 'Malformed RELATIVE-OID %s at %s: %s' % (value, self.__class__.__name__, sys.exc_info()[1]) ) try: return tuple([int(subOid) for subOid in value.split('.') if subOid]) - except ValueError: + except ValueError as exc: raise error.PyAsn1Error( - 'Malformed RELATIVE-OID %s at %s: %s' % (value, self.__class__.__name__, sys.exc_info()[1]) + 'Malformed RELATIVE-OID %s at %s: %s' % (value, self.__class__.__name__, exc) ) try: tupleOfInts = tuple([int(subOid) for subOid in value if subOid >= 0]) - except (ValueError, TypeError): + except (ValueError, TypeError) as exc: raise error.PyAsn1Error( - 'Malformed RELATIVE-OID %s at %s: %s' % (value, self.__class__.__name__, sys.exc_info()[1]) + 'Malformed RELATIVE-OID %s at %s: %s' % (value, self.__class__.__name__, exc) ) if len(tupleOfInts) == len(value): @@ -1452,9 +1368,9 @@ class Real(base.SimpleAsn1Type): def prettyIn(self, value): if isinstance(value, tuple) and len(value) == 3: - if (not isinstance(value[0], numericTypes) or - not isinstance(value[1], intTypes) or - not isinstance(value[2], intTypes)): + if (not isinstance(value[0], (int, float)) or + not isinstance(value[1], int) or + not isinstance(value[2], int)): raise error.PyAsn1Error('Lame Real value syntax: %s' % (value,)) if (isinstance(value[0], float) and self._inf and value[0] in self._inf): @@ -1466,10 +1382,10 @@ class Real(base.SimpleAsn1Type): if value[1] == 10: value = self.__normalizeBase10(value) return value - elif isinstance(value, intTypes): + elif isinstance(value, int): return self.__normalizeBase10((value, 10, 0)) - elif isinstance(value, float) or octets.isStringType(value): - if octets.isStringType(value): + elif isinstance(value, float) or isinstance(value, str): + if isinstance(value, str): try: value = float(value) except ValueError: @@ -1556,32 +1472,21 @@ class Real(base.SimpleAsn1Type): def __rpow__(self, value): return self.clone(pow(value, float(self))) - if sys.version_info[0] <= 2: - def __div__(self, value): - return self.clone(float(self) / value) + def __truediv__(self, value): + return self.clone(float(self) / value) - def __rdiv__(self, value): - return self.clone(value / float(self)) - else: - def __truediv__(self, value): - return self.clone(float(self) / value) + def __rtruediv__(self, value): + return self.clone(value / float(self)) - def __rtruediv__(self, value): - return self.clone(value / float(self)) + def __divmod__(self, value): + return self.clone(float(self) // value) - def __divmod__(self, value): - return self.clone(float(self) // value) - - def __rdivmod__(self, value): - return self.clone(value // float(self)) + def __rdivmod__(self, value): + return self.clone(value // float(self)) def __int__(self): return int(float(self)) - if sys.version_info[0] <= 2: - def __long__(self): - return long(float(self)) - def __float__(self): if self._value in self._inf: return self._value @@ -1633,14 +1538,10 @@ class Real(base.SimpleAsn1Type): def __ge__(self, value): return float(self) >= value - if sys.version_info[0] <= 2: - def __nonzero__(self): - return bool(float(self)) - else: - def __bool__(self): - return bool(float(self)) + def __bool__(self): + return bool(float(self)) - __hash__ = base.SimpleAsn1Type.__hash__ + __hash__ = base.SimpleAsn1Type.__hash__ def __getitem__(self, idx): if self._value in self._inf: @@ -1785,15 +1686,15 @@ class SequenceOfAndSetOfBase(base.ConstructedAsn1Type): try: return self.getComponentByPosition(idx) - except error.PyAsn1Error: - raise IndexError(sys.exc_info()[1]) + except error.PyAsn1Error as exc: + raise IndexError(exc) def __setitem__(self, idx, value): try: self.setComponentByPosition(idx, value) - except error.PyAsn1Error: - raise IndexError(sys.exc_info()[1]) + except error.PyAsn1Error as exc: + raise IndexError(exc) def append(self, value): if self._componentValues is noValue: @@ -1826,8 +1727,8 @@ class SequenceOfAndSetOfBase(base.ConstructedAsn1Type): try: return indices[values.index(value, start, stop)] - except error.PyAsn1Error: - raise ValueError(sys.exc_info()[1]) + except error.PyAsn1Error as exc: + raise ValueError(exc) def reverse(self): self._componentValues.reverse() @@ -2184,8 +2085,7 @@ class SequenceOfAndSetOfBase(base.ConstructedAsn1Type): # Represent SequenceOf/SetOf as a bare dict to constraints chain self.subtypeSpec(mapping) - except error.PyAsn1Error: - exc = sys.exc_info()[1] + except error.PyAsn1Error as exc: return exc return False @@ -2336,38 +2236,38 @@ class SequenceAndSetBase(base.ConstructedAsn1Type): self._dynamicNames = self._componentTypeLen or self.DynamicNames() def __getitem__(self, idx): - if octets.isStringType(idx): + if isinstance(idx, str): try: return self.getComponentByName(idx) - except error.PyAsn1Error: + except error.PyAsn1Error as exc: # duck-typing dict - raise KeyError(sys.exc_info()[1]) + raise KeyError(exc) else: try: return self.getComponentByPosition(idx) - except error.PyAsn1Error: + except error.PyAsn1Error as exc: # duck-typing list - raise IndexError(sys.exc_info()[1]) + raise IndexError(exc) def __setitem__(self, idx, value): - if octets.isStringType(idx): + if isinstance(idx, str): try: self.setComponentByName(idx, value) - except error.PyAsn1Error: + except error.PyAsn1Error as exc: # duck-typing dict - raise KeyError(sys.exc_info()[1]) + raise KeyError(exc) else: try: self.setComponentByPosition(idx, value) - except error.PyAsn1Error: + except error.PyAsn1Error as exc: # duck-typing list - raise IndexError(sys.exc_info()[1]) + raise IndexError(exc) def __contains__(self, key): if self._componentTypeLen: @@ -2816,8 +2716,7 @@ class SequenceAndSetBase(base.ConstructedAsn1Type): # Represent Sequence/Set as a bare dict to constraints chain self.subtypeSpec(mapping) - except error.PyAsn1Error: - exc = sys.exc_info()[1] + except error.PyAsn1Error as exc: return exc return False @@ -3126,12 +3025,8 @@ class Choice(Set): return self._componentValues[self._currentIdx] >= other return NotImplemented - if sys.version_info[0] <= 2: - def __nonzero__(self): - return self._componentValues and True or False - else: - def __bool__(self): - return self._componentValues and True or False + def __bool__(self): + return bool(self._componentValues) def __len__(self): return self._currentIdx is not None and 1 or 0 @@ -3336,15 +3231,14 @@ class Any(OctetString): """Create |ASN.1| schema or value object. |ASN.1| class is based on :class:`~pyasn1.type.base.SimpleAsn1Type`, - its objects are immutable and duck-type Python 2 :class:`str` or Python 3 - :class:`bytes`. When used in Unicode context, |ASN.1| type assumes + its objects are immutable and duck-type :class:`bytes`. + When used in Unicode context, |ASN.1| type assumes "|encoding|" serialisation. Keyword Args ------------ value: :class:`unicode`, :class:`str`, :class:`bytes` or |ASN.1| object - :class:`str` (Python 2) or :class:`bytes` (Python 3), alternatively - :class:`unicode` object (Python 2) or :class:`str` (Python 3) + :class:`bytes`, alternatively :class:`str` representing character string to be serialised into octets (note `encoding` parameter) or |ASN.1| object. If `value` is not given, schema object will be created. @@ -3358,8 +3252,8 @@ class Any(OctetString): instantiation. encoding: :py:class:`str` - Unicode codec ID to encode/decode :class:`unicode` (Python 2) or - :class:`str` (Python 3) the payload when |ASN.1| object is used + Unicode codec ID to encode/decode + :class:`str` the payload when |ASN.1| object is used in text string context. binValue: :py:class:`str` diff --git a/contrib/python/pyasn1/py3/tests/codec/ber/test_decoder.py b/contrib/python/pyasn1/py3/tests/codec/ber/test_decoder.py index 20da0abc30..2b07ae0a8b 100644 --- a/contrib/python/pyasn1/py3/tests/codec/ber/test_decoder.py +++ b/contrib/python/pyasn1/py3/tests/codec/ber/test_decoder.py @@ -22,70 +22,69 @@ from pyasn1.type import char from pyasn1.codec import streaming from pyasn1.codec.ber import decoder from pyasn1.codec.ber import eoo -from pyasn1.compat.octets import ints2octs, str2octs, null from pyasn1 import error class LargeTagDecoderTestCase(BaseTestCase): def testLargeTag(self): - assert decoder.decode(ints2octs((127, 141, 245, 182, 253, 47, 3, 2, 1, 1))) == (1, null) + assert decoder.decode(bytes((127, 141, 245, 182, 253, 47, 3, 2, 1, 1))) == (1, b'') def testLongTag(self): - assert decoder.decode(ints2octs((0x1f, 2, 1, 0)))[0].tagSet == univ.Integer.tagSet + assert decoder.decode(bytes((0x1f, 2, 1, 0)))[0].tagSet == univ.Integer.tagSet def testTagsEquivalence(self): integer = univ.Integer(2).subtype(implicitTag=tag.Tag(tag.tagClassContext, 0, 0)) - assert decoder.decode(ints2octs((0x9f, 0x80, 0x00, 0x02, 0x01, 0x02)), asn1Spec=integer) == decoder.decode( - ints2octs((0x9f, 0x00, 0x02, 0x01, 0x02)), asn1Spec=integer) + assert decoder.decode(bytes((0x9f, 0x80, 0x00, 0x02, 0x01, 0x02)), asn1Spec=integer) == decoder.decode( + bytes((0x9f, 0x00, 0x02, 0x01, 0x02)), asn1Spec=integer) class DecoderCacheTestCase(BaseTestCase): def testCache(self): - assert decoder.decode(ints2octs((0x1f, 2, 1, 0))) == decoder.decode(ints2octs((0x1f, 2, 1, 0))) + assert decoder.decode(bytes((0x1f, 2, 1, 0))) == decoder.decode(bytes((0x1f, 2, 1, 0))) class IntegerDecoderTestCase(BaseTestCase): def testPosInt(self): - assert decoder.decode(ints2octs((2, 1, 12))) == (12, null) + assert decoder.decode(bytes((2, 1, 12))) == (12, b'') def testNegInt(self): - assert decoder.decode(ints2octs((2, 1, 244))) == (-12, null) + assert decoder.decode(bytes((2, 1, 244))) == (-12, b'') def testZero(self): - assert decoder.decode(ints2octs((2, 0))) == (0, null) + assert decoder.decode(bytes((2, 0))) == (0, b'') def testZeroLong(self): - assert decoder.decode(ints2octs((2, 1, 0))) == (0, null) + assert decoder.decode(bytes((2, 1, 0))) == (0, b'') def testMinusOne(self): - assert decoder.decode(ints2octs((2, 1, 255))) == (-1, null) + assert decoder.decode(bytes((2, 1, 255))) == (-1, b'') def testPosLong(self): assert decoder.decode( - ints2octs((2, 9, 0, 255, 255, 255, 255, 255, 255, 255, 255)) - ) == (0xffffffffffffffff, null) + bytes((2, 9, 0, 255, 255, 255, 255, 255, 255, 255, 255)) + ) == (0xffffffffffffffff, b'') def testNegLong(self): assert decoder.decode( - ints2octs((2, 9, 255, 0, 0, 0, 0, 0, 0, 0, 1)) - ) == (-0xffffffffffffffff, null) + bytes((2, 9, 255, 0, 0, 0, 0, 0, 0, 0, 1)) + ) == (-0xffffffffffffffff, b'') def testSpec(self): try: decoder.decode( - ints2octs((2, 1, 12)), asn1Spec=univ.Null() - ) == (12, null) + bytes((2, 1, 12)), asn1Spec=univ.Null() + ) == (12, b'') except error.PyAsn1Error: pass else: assert 0, 'wrong asn1Spec worked out' assert decoder.decode( - ints2octs((2, 1, 12)), asn1Spec=univ.Integer() - ) == (12, null) + bytes((2, 1, 12)), asn1Spec=univ.Integer() + ) == (12, b'') def testTagFormat(self): try: - decoder.decode(ints2octs((34, 1, 12))) + decoder.decode(bytes((34, 1, 12))) except error.PyAsn1Error: pass else: @@ -94,20 +93,20 @@ class IntegerDecoderTestCase(BaseTestCase): class BooleanDecoderTestCase(BaseTestCase): def testTrue(self): - assert decoder.decode(ints2octs((1, 1, 1))) == (1, null) + assert decoder.decode(bytes((1, 1, 1))) == (1, b'') def testTrueNeg(self): - assert decoder.decode(ints2octs((1, 1, 255))) == (1, null) + assert decoder.decode(bytes((1, 1, 255))) == (1, b'') def testExtraTrue(self): - assert decoder.decode(ints2octs((1, 1, 1, 0, 120, 50, 50))) == (1, ints2octs((0, 120, 50, 50))) + assert decoder.decode(bytes((1, 1, 1, 0, 120, 50, 50))) == (1, bytes((0, 120, 50, 50))) def testFalse(self): - assert decoder.decode(ints2octs((1, 1, 0))) == (0, null) + assert decoder.decode(bytes((1, 1, 0))) == (0, b'') def testTagFormat(self): try: - decoder.decode(ints2octs((33, 1, 1))) + decoder.decode(bytes((33, 1, 1))) except error.PyAsn1Error: pass else: @@ -117,51 +116,51 @@ class BooleanDecoderTestCase(BaseTestCase): class BitStringDecoderTestCase(BaseTestCase): def testDefMode(self): assert decoder.decode( - ints2octs((3, 3, 1, 169, 138)) - ) == ((1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1), null) + bytes((3, 3, 1, 169, 138)) + ) == ((1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1), b'') def testIndefMode(self): assert decoder.decode( - ints2octs((3, 3, 1, 169, 138)) - ) == ((1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1), null) + bytes((3, 3, 1, 169, 138)) + ) == ((1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1), b'') def testDefModeChunked(self): assert decoder.decode( - ints2octs((35, 8, 3, 2, 0, 169, 3, 2, 1, 138)) - ) == ((1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1), null) + bytes((35, 8, 3, 2, 0, 169, 3, 2, 1, 138)) + ) == ((1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1), b'') def testIndefModeChunked(self): assert decoder.decode( - ints2octs((35, 128, 3, 2, 0, 169, 3, 2, 1, 138, 0, 0)) - ) == ((1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1), null) + bytes((35, 128, 3, 2, 0, 169, 3, 2, 1, 138, 0, 0)) + ) == ((1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1), b'') def testDefModeChunkedSubst(self): assert decoder.decode( - ints2octs((35, 8, 3, 2, 0, 169, 3, 2, 1, 138)), + bytes((35, 8, 3, 2, 0, 169, 3, 2, 1, 138)), substrateFun=lambda a, b, c, d: streaming.readFromStream(b, c) - ) == (ints2octs((3, 2, 0, 169, 3, 2, 1, 138)), str2octs('')) + ) == (bytes((3, 2, 0, 169, 3, 2, 1, 138)), b'') def testDefModeChunkedSubstV04(self): assert decoder.decode( - ints2octs((35, 8, 3, 2, 0, 169, 3, 2, 1, 138)), + bytes((35, 8, 3, 2, 0, 169, 3, 2, 1, 138)), substrateFun=lambda a, b, c: (b, b[c:]) - ) == (ints2octs((3, 2, 0, 169, 3, 2, 1, 138)), str2octs('')) + ) == (bytes((3, 2, 0, 169, 3, 2, 1, 138)), b'') def testIndefModeChunkedSubst(self): assert decoder.decode( - ints2octs((35, 128, 3, 2, 0, 169, 3, 2, 1, 138, 0, 0)), + bytes((35, 128, 3, 2, 0, 169, 3, 2, 1, 138, 0, 0)), substrateFun=lambda a, b, c, d: streaming.readFromStream(b, c) - ) == (ints2octs((3, 2, 0, 169, 3, 2, 1, 138, 0, 0)), str2octs('')) + ) == (bytes((3, 2, 0, 169, 3, 2, 1, 138, 0, 0)), b'') def testIndefModeChunkedSubstV04(self): assert decoder.decode( - ints2octs((35, 128, 3, 2, 0, 169, 3, 2, 1, 138, 0, 0)), + bytes((35, 128, 3, 2, 0, 169, 3, 2, 1, 138, 0, 0)), substrateFun=lambda a, b, c: (b, b[c:]) - ) == (ints2octs((3, 2, 0, 169, 3, 2, 1, 138, 0, 0)), str2octs('')) + ) == (bytes((3, 2, 0, 169, 3, 2, 1, 138, 0, 0)), b'') def testTypeChecking(self): try: - decoder.decode(ints2octs((35, 4, 2, 2, 42, 42))) + decoder.decode(bytes((35, 4, 2, 2, 42, 42))) except error.PyAsn1Error: pass else: @@ -171,54 +170,54 @@ class BitStringDecoderTestCase(BaseTestCase): class OctetStringDecoderTestCase(BaseTestCase): def testDefMode(self): assert decoder.decode( - ints2octs((4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120)) - ) == (str2octs('Quick brown fox'), null) + bytes((4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120)) + ) == (b'Quick brown fox', b'') def testIndefMode(self): assert decoder.decode( - ints2octs((36, 128, 4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 0, 0)) - ) == (str2octs('Quick brown fox'), null) + bytes((36, 128, 4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 0, 0)) + ) == (b'Quick brown fox', b'') def testDefModeChunked(self): assert decoder.decode( - ints2octs( + bytes( (36, 23, 4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111, 120)) - ) == (str2octs('Quick brown fox'), null) + ) == (b'Quick brown fox', b'') def testIndefModeChunked(self): assert decoder.decode( - ints2octs((36, 128, 4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111, 120, 0, 0)) - ) == (str2octs('Quick brown fox'), null) + bytes((36, 128, 4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111, 120, 0, 0)) + ) == (b'Quick brown fox', b'') def testDefModeChunkedSubst(self): assert decoder.decode( - ints2octs( + bytes( (36, 23, 4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111, 120)), substrateFun=lambda a, b, c, d: streaming.readFromStream(b, c) - ) == (ints2octs((4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111, 120)), str2octs('')) + ) == (bytes((4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111, 120)), b'') def testDefModeChunkedSubstV04(self): assert decoder.decode( - ints2octs( + bytes( (36, 23, 4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111, 120)), substrateFun=lambda a, b, c: (b, b[c:]) - ) == (ints2octs((4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111, 120)), str2octs('')) + ) == (bytes((4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111, 120)), b'') def testIndefModeChunkedSubst(self): assert decoder.decode( - ints2octs((36, 128, 4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111, + bytes((36, 128, 4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111, 120, 0, 0)), substrateFun=lambda a, b, c, d: streaming.readFromStream(b, c) - ) == (ints2octs( - (4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111, 120, 0, 0)), str2octs('')) + ) == (bytes( + (4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111, 120, 0, 0)), b'') def testIndefModeChunkedSubstV04(self): assert decoder.decode( - ints2octs((36, 128, 4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111, + bytes((36, 128, 4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111, 120, 0, 0)), substrateFun=lambda a, b, c: (b, b[c:]) - ) == (ints2octs( - (4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111, 120, 0, 0)), str2octs('')) + ) == (bytes( + (4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111, 120, 0, 0)), b'') class ExpTaggedOctetStringDecoderTestCase(BaseTestCase): @@ -232,7 +231,7 @@ class ExpTaggedOctetStringDecoderTestCase(BaseTestCase): def testDefMode(self): o, r = decoder.decode( - ints2octs((101, 17, 4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120)) + bytes((101, 17, 4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120)) ) assert not r assert self.o == o @@ -241,7 +240,7 @@ class ExpTaggedOctetStringDecoderTestCase(BaseTestCase): def testIndefMode(self): o, r = decoder.decode( - ints2octs((101, 128, 36, 128, 4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 0, 0, 0, 0)) + bytes((101, 128, 36, 128, 4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 0, 0, 0, 0)) ) assert not r assert self.o == o @@ -250,7 +249,7 @@ class ExpTaggedOctetStringDecoderTestCase(BaseTestCase): def testDefModeChunked(self): o, r = decoder.decode( - ints2octs((101, 25, 36, 23, 4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111, 120)) + bytes((101, 25, 36, 23, 4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111, 120)) ) assert not r assert self.o == o @@ -259,7 +258,7 @@ class ExpTaggedOctetStringDecoderTestCase(BaseTestCase): def testIndefModeChunked(self): o, r = decoder.decode( - ints2octs((101, 128, 36, 128, 4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111, 120, 0, 0, 0, 0)) + bytes((101, 128, 36, 128, 4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111, 120, 0, 0, 0, 0)) ) assert not r assert self.o == o @@ -268,42 +267,42 @@ class ExpTaggedOctetStringDecoderTestCase(BaseTestCase): def testDefModeSubst(self): assert decoder.decode( - ints2octs((101, 17, 4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120)), + bytes((101, 17, 4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120)), substrateFun=lambda a, b, c, d: streaming.readFromStream(b, c) - ) == (ints2octs((4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120)), str2octs('')) + ) == (bytes((4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120)), b'') def testDefModeSubstV04(self): assert decoder.decode( - ints2octs((101, 17, 4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120)), + bytes((101, 17, 4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120)), substrateFun=lambda a, b, c: (b, b[c:]) - ) == (ints2octs((4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120)), str2octs('')) + ) == (bytes((4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120)), b'') def testIndefModeSubst(self): assert decoder.decode( - ints2octs(( + bytes(( 101, 128, 36, 128, 4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 0, 0, 0, 0)), substrateFun=lambda a, b, c, d: streaming.readFromStream(b, c) - ) == (ints2octs( - (36, 128, 4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 0, 0, 0, 0)), str2octs('')) + ) == (bytes( + (36, 128, 4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 0, 0, 0, 0)), b'') def testIndefModeSubstV04(self): assert decoder.decode( - ints2octs(( + bytes(( 101, 128, 36, 128, 4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 0, 0, 0, 0)), substrateFun=lambda a, b, c: (b, b[c:]) - ) == (ints2octs( - (36, 128, 4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 0, 0, 0, 0)), str2octs('')) + ) == (bytes( + (36, 128, 4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 0, 0, 0, 0)), b'') class NullDecoderTestCase(BaseTestCase): def testNull(self): - assert decoder.decode(ints2octs((5, 0))) == (null, null) + assert decoder.decode(bytes((5, 0))) == (b'', b'') def testTagFormat(self): try: - decoder.decode(ints2octs((37, 0))) + decoder.decode(bytes((37, 0))) except error.PyAsn1Error: pass else: @@ -315,63 +314,63 @@ class NullDecoderTestCase(BaseTestCase): class ObjectIdentifierDecoderTestCase(BaseTestCase): def testOne(self): assert decoder.decode( - ints2octs((6, 6, 43, 6, 0, 191, 255, 126)) - ) == ((1, 3, 6, 0, 0xffffe), null) + bytes((6, 6, 43, 6, 0, 191, 255, 126)) + ) == ((1, 3, 6, 0, 0xffffe), b'') def testEdge1(self): assert decoder.decode( - ints2octs((6, 1, 39)) - ) == ((0, 39), null) + bytes((6, 1, 39)) + ) == ((0, 39), b'') def testEdge2(self): assert decoder.decode( - ints2octs((6, 1, 79)) - ) == ((1, 39), null) + bytes((6, 1, 79)) + ) == ((1, 39), b'') def testEdge3(self): assert decoder.decode( - ints2octs((6, 1, 120)) - ) == ((2, 40), null) + bytes((6, 1, 120)) + ) == ((2, 40), b'') def testEdge4(self): assert decoder.decode( - ints2octs((6, 5, 0x90, 0x80, 0x80, 0x80, 0x4F)) - ) == ((2, 0xffffffff), null) + bytes((6, 5, 0x90, 0x80, 0x80, 0x80, 0x4F)) + ) == ((2, 0xffffffff), b'') def testEdge5(self): assert decoder.decode( - ints2octs((6, 1, 0x7F)) - ) == ((2, 47), null) + bytes((6, 1, 0x7F)) + ) == ((2, 47), b'') def testEdge6(self): assert decoder.decode( - ints2octs((6, 2, 0x81, 0x00)) - ) == ((2, 48), null) + bytes((6, 2, 0x81, 0x00)) + ) == ((2, 48), b'') def testEdge7(self): assert decoder.decode( - ints2octs((6, 3, 0x81, 0x34, 0x03)) - ) == ((2, 100, 3), null) + bytes((6, 3, 0x81, 0x34, 0x03)) + ) == ((2, 100, 3), b'') def testEdge8(self): assert decoder.decode( - ints2octs((6, 2, 133, 0)) - ) == ((2, 560), null) + bytes((6, 2, 133, 0)) + ) == ((2, 560), b'') def testEdge9(self): assert decoder.decode( - ints2octs((6, 4, 0x88, 0x84, 0x87, 0x02)) - ) == ((2, 16843570), null) + bytes((6, 4, 0x88, 0x84, 0x87, 0x02)) + ) == ((2, 16843570), b'') def testNonLeading0x80(self): assert decoder.decode( - ints2octs((6, 5, 85, 4, 129, 128, 0)), - ) == ((2, 5, 4, 16384), null) + bytes((6, 5, 85, 4, 129, 128, 0)), + ) == ((2, 5, 4, 16384), b'') def testLeading0x80Case1(self): try: decoder.decode( - ints2octs((6, 5, 85, 4, 128, 129, 0)) + bytes((6, 5, 85, 4, 128, 129, 0)) ) except error.PyAsn1Error: pass @@ -381,7 +380,7 @@ class ObjectIdentifierDecoderTestCase(BaseTestCase): def testLeading0x80Case2(self): try: decoder.decode( - ints2octs((6, 7, 1, 0x80, 0x80, 0x80, 0x80, 0x80, 0x7F)) + bytes((6, 7, 1, 0x80, 0x80, 0x80, 0x80, 0x80, 0x7F)) ) except error.PyAsn1Error: pass @@ -391,7 +390,7 @@ class ObjectIdentifierDecoderTestCase(BaseTestCase): def testLeading0x80Case3(self): try: decoder.decode( - ints2octs((6, 2, 0x80, 1)) + bytes((6, 2, 0x80, 1)) ) except error.PyAsn1Error: pass @@ -401,7 +400,7 @@ class ObjectIdentifierDecoderTestCase(BaseTestCase): def testLeading0x80Case4(self): try: decoder.decode( - ints2octs((6, 2, 0x80, 0x7F)) + bytes((6, 2, 0x80, 0x7F)) ) except error.PyAsn1Error: pass @@ -410,7 +409,7 @@ class ObjectIdentifierDecoderTestCase(BaseTestCase): def testTagFormat(self): try: - decoder.decode(ints2octs((38, 1, 239))) + decoder.decode(bytes((38, 1, 239))) except error.PyAsn1Error: pass else: @@ -418,7 +417,7 @@ class ObjectIdentifierDecoderTestCase(BaseTestCase): def testZeroLength(self): try: - decoder.decode(ints2octs((6, 0, 0))) + decoder.decode(bytes((6, 0, 0))) except error.PyAsn1Error: pass else: @@ -426,7 +425,7 @@ class ObjectIdentifierDecoderTestCase(BaseTestCase): def testIndefiniteLength(self): try: - decoder.decode(ints2octs((6, 128, 0))) + decoder.decode(bytes((6, 128, 0))) except error.PyAsn1Error: pass else: @@ -434,7 +433,7 @@ class ObjectIdentifierDecoderTestCase(BaseTestCase): def testReservedLength(self): try: - decoder.decode(ints2octs((6, 255, 0))) + decoder.decode(bytes((6, 255, 0))) except error.PyAsn1Error: pass else: @@ -442,40 +441,40 @@ class ObjectIdentifierDecoderTestCase(BaseTestCase): def testLarge1(self): assert decoder.decode( - ints2octs((0x06, 0x11, 0x83, 0xC6, 0xDF, 0xD4, 0xCC, 0xB3, 0xFF, 0xFF, 0xFE, 0xF0, 0xB8, 0xD6, 0xB8, 0xCB, 0xE2, 0xB7, 0x17)) - ) == ((2, 18446744073709551535184467440737095), null) + bytes((0x06, 0x11, 0x83, 0xC6, 0xDF, 0xD4, 0xCC, 0xB3, 0xFF, 0xFF, 0xFE, 0xF0, 0xB8, 0xD6, 0xB8, 0xCB, 0xE2, 0xB7, 0x17)) + ) == ((2, 18446744073709551535184467440737095), b'') def testLarge2(self): assert decoder.decode( - ints2octs((0x06, 0x13, 0x88, 0x37, 0x83, 0xC6, 0xDF, 0xD4, 0xCC, 0xB3, 0xFF, 0xFF, 0xFE, 0xF0, 0xB8, 0xD6, 0xB8, 0xCB, 0xE2, 0xB6, 0x47)) - ) == ((2, 999, 18446744073709551535184467440737095), null) + bytes((0x06, 0x13, 0x88, 0x37, 0x83, 0xC6, 0xDF, 0xD4, 0xCC, 0xB3, 0xFF, 0xFF, 0xFE, 0xF0, 0xB8, 0xD6, 0xB8, 0xCB, 0xE2, 0xB6, 0x47)) + ) == ((2, 999, 18446744073709551535184467440737095), b'') class RelativeOIDDecoderTestCase(BaseTestCase): def testOne(self): - obj, rest = decoder.decode(ints2octs((13, 1, 39))) + obj, rest = decoder.decode(bytes((13, 1, 39))) assert str(obj) == '39' - assert rest == null + assert rest == b'' def testTwo(self): assert decoder.decode( - ints2octs((13, 2, 5, 6)) - ) == ((5, 6), null) + bytes((13, 2, 5, 6)) + ) == ((5, 6), b'') def testThree(self): assert decoder.decode( - ints2octs((13, 3, 5, 6, 7)) - ) == ((5, 6, 7), null) + bytes((13, 3, 5, 6, 7)) + ) == ((5, 6, 7), b'') def testNonLeading0x80(self): assert decoder.decode( - ints2octs((13, 5, 85, 4, 129, 128, 0)), - ) == ((85, 4, 16384), null) + bytes((13, 5, 85, 4, 129, 128, 0)), + ) == ((85, 4, 16384), b'') def testLeading0x80(self): try: decoder.decode( - ints2octs((13, 5, 85, 4, 128, 129, 0)) + bytes((13, 5, 85, 4, 128, 129, 0)) ) except error.PyAsn1Error: pass @@ -484,7 +483,7 @@ class RelativeOIDDecoderTestCase(BaseTestCase): def testTagFormat(self): try: - decoder.decode(ints2octs((38, 1, 239))) + decoder.decode(bytes((38, 1, 239))) except error.PyAsn1Error: pass else: @@ -492,7 +491,7 @@ class RelativeOIDDecoderTestCase(BaseTestCase): def testZeroLength(self): try: - decoder.decode(ints2octs((13, 0, 0))) + decoder.decode(bytes((13, 0, 0))) except error.PyAsn1Error: pass else: @@ -500,7 +499,7 @@ class RelativeOIDDecoderTestCase(BaseTestCase): def testIndefiniteLength(self): try: - decoder.decode(ints2octs((13, 128, 0))) + decoder.decode(bytes((13, 128, 0))) except error.PyAsn1Error: pass else: @@ -508,7 +507,7 @@ class RelativeOIDDecoderTestCase(BaseTestCase): def testReservedLength(self): try: - decoder.decode(ints2octs((13, 255, 0))) + decoder.decode(bytes((13, 255, 0))) except error.PyAsn1Error: pass else: @@ -516,71 +515,71 @@ class RelativeOIDDecoderTestCase(BaseTestCase): def testLarge(self): assert decoder.decode( - ints2octs((0x0D, 0x13, 0x88, 0x37, 0x83, 0xC6, 0xDF, 0xD4, 0xCC, 0xB3, 0xFF, 0xFF, 0xFE, 0xF0, 0xB8, 0xD6, 0xB8, 0xCB, 0xE2, 0xB6, 0x47)) - ) == ((1079, 18446744073709551535184467440737095), null) + bytes((0x0D, 0x13, 0x88, 0x37, 0x83, 0xC6, 0xDF, 0xD4, 0xCC, 0xB3, 0xFF, 0xFF, 0xFE, 0xF0, 0xB8, 0xD6, 0xB8, 0xCB, 0xE2, 0xB6, 0x47)) + ) == ((1079, 18446744073709551535184467440737095), b'') class RealDecoderTestCase(BaseTestCase): def testChar(self): assert decoder.decode( - ints2octs((9, 7, 3, 49, 50, 51, 69, 49, 49)) - ) == (univ.Real((123, 10, 11)), null) + bytes((9, 7, 3, 49, 50, 51, 69, 49, 49)) + ) == (univ.Real((123, 10, 11)), b'') def testBin1(self): # check base = 2 assert decoder.decode( # (0.5, 2, 0) encoded with base = 2 - ints2octs((9, 3, 128, 255, 1)) - ) == (univ.Real((1, 2, -1)), null) + bytes((9, 3, 128, 255, 1)) + ) == (univ.Real((1, 2, -1)), b'') def testBin2(self): # check base = 2 and scale factor assert decoder.decode( # (3.25, 2, 0) encoded with base = 8 - ints2octs((9, 3, 148, 255, 13)) - ) == (univ.Real((26, 2, -3)), null) + bytes((9, 3, 148, 255, 13)) + ) == (univ.Real((26, 2, -3)), b'') def testBin3(self): # check base = 16 assert decoder.decode( # (0.00390625, 2, 0) encoded with base = 16 - ints2octs((9, 3, 160, 254, 1)) - ) == (univ.Real((1, 2, -8)), null) + bytes((9, 3, 160, 254, 1)) + ) == (univ.Real((1, 2, -8)), b'') def testBin4(self): # check exponent = 0 assert decoder.decode( # (1, 2, 0) encoded with base = 2 - ints2octs((9, 3, 128, 0, 1)) - ) == (univ.Real((1, 2, 0)), null) + bytes((9, 3, 128, 0, 1)) + ) == (univ.Real((1, 2, 0)), b'') def testBin5(self): # case of 2 octs for exponent and negative exponent assert decoder.decode( # (3, 2, -1020) encoded with base = 16 - ints2octs((9, 4, 161, 255, 1, 3)) - ) == (univ.Real((3, 2, -1020)), null) + bytes((9, 4, 161, 255, 1, 3)) + ) == (univ.Real((3, 2, -1020)), b'') # TODO: this requires Real type comparison fix # def testBin6(self): # assert decoder.decode( -# ints2octs((9, 5, 162, 0, 255, 255, 1)) -# ) == (univ.Real((1, 2, 262140)), null) +# bytes((9, 5, 162, 0, 255, 255, 1)) +# ) == (univ.Real((1, 2, 262140)), b'') # def testBin7(self): # assert decoder.decode( -# ints2octs((9, 7, 227, 4, 1, 35, 69, 103, 1)) -# ) == (univ.Real((-1, 2, 76354972)), null) +# bytes((9, 7, 227, 4, 1, 35, 69, 103, 1)) +# ) == (univ.Real((-1, 2, 76354972)), b'') def testPlusInf(self): assert decoder.decode( - ints2octs((9, 1, 64)) - ) == (univ.Real('inf'), null) + bytes((9, 1, 64)) + ) == (univ.Real('inf'), b'') def testMinusInf(self): assert decoder.decode( - ints2octs((9, 1, 65)) - ) == (univ.Real('-inf'), null) + bytes((9, 1, 65)) + ) == (univ.Real('-inf'), b'') def testEmpty(self): assert decoder.decode( - ints2octs((9, 0)) - ) == (univ.Real(0.0), null) + bytes((9, 0)) + ) == (univ.Real(0.0), b'') def testTagFormat(self): try: - decoder.decode(ints2octs((41, 0))) + decoder.decode(bytes((41, 0))) except error.PyAsn1Error: pass else: @@ -588,7 +587,7 @@ class RealDecoderTestCase(BaseTestCase): def testShortEncoding(self): try: - decoder.decode(ints2octs((9, 1, 131))) + decoder.decode(bytes((9, 1, 131))) except error.PyAsn1Error: pass else: @@ -597,17 +596,17 @@ class RealDecoderTestCase(BaseTestCase): class UniversalStringDecoderTestCase(BaseTestCase): def testDecoder(self): - assert decoder.decode(ints2octs((28, 12, 0, 0, 0, 97, 0, 0, 0, 98, 0, 0, 0, 99))) == (char.UniversalString(sys.version_info[0] >= 3 and 'abc' or unicode('abc')), null) + assert decoder.decode(bytes((28, 12, 0, 0, 0, 97, 0, 0, 0, 98, 0, 0, 0, 99))) == (char.UniversalString('abc'), b'') class BMPStringDecoderTestCase(BaseTestCase): def testDecoder(self): - assert decoder.decode(ints2octs((30, 6, 0, 97, 0, 98, 0, 99))) == (char.BMPString(sys.version_info[0] >= 3 and 'abc' or unicode('abc')), null) + assert decoder.decode(bytes((30, 6, 0, 97, 0, 98, 0, 99))) == (char.BMPString('abc'), b'') class UTF8StringDecoderTestCase(BaseTestCase): def testDecoder(self): - assert decoder.decode(ints2octs((12, 3, 97, 98, 99))) == (char.UTF8String(sys.version_info[0] >= 3 and 'abc' or unicode('abc')), null) + assert decoder.decode(bytes((12, 3, 97, 98, 99))) == (char.UTF8String('abc'), b'') class SequenceOfDecoderTestCase(BaseTestCase): @@ -619,28 +618,28 @@ class SequenceOfDecoderTestCase(BaseTestCase): def testDefMode(self): assert decoder.decode( - ints2octs((48, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) - ) == (self.s, null) + bytes((48, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) + ) == (self.s, b'') def testIndefMode(self): assert decoder.decode( - ints2octs((48, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0)) - ) == (self.s, null) + bytes((48, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0)) + ) == (self.s, b'') def testDefModeChunked(self): assert decoder.decode( - ints2octs((48, 19, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110)) - ) == (self.s, null) + bytes((48, 19, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110)) + ) == (self.s, b'') def testIndefModeChunked(self): assert decoder.decode( - ints2octs((48, 128, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 0, 0)) - ) == (self.s, null) + bytes((48, 128, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 0, 0)) + ) == (self.s, b'') def testSchemalessDecoder(self): assert decoder.decode( - ints2octs((48, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)), asn1Spec=univ.SequenceOf() - ) == (self.s, null) + bytes((48, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)), asn1Spec=univ.SequenceOf() + ) == (self.s, b'') class ExpTaggedSequenceOfDecoderTestCase(BaseTestCase): @@ -648,19 +647,19 @@ class ExpTaggedSequenceOfDecoderTestCase(BaseTestCase): def testWithSchema(self): s = univ.SequenceOf().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 3)) s2, r = decoder.decode( - ints2octs((163, 15, 48, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)), asn1Spec=s + bytes((163, 15, 48, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)), asn1Spec=s ) assert not r - assert s2 == [str2octs('quick brown')] + assert s2 == [b'quick brown'] assert s.tagSet == s2.tagSet def testWithoutSchema(self): s = univ.SequenceOf().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 3)) s2, r = decoder.decode( - ints2octs((163, 15, 48, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) + bytes((163, 15, 48, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) ) assert not r - assert s2 == [str2octs('quick brown')] + assert s2 == [b'quick brown'] assert s.tagSet == s2.tagSet @@ -672,23 +671,23 @@ class SequenceOfDecoderWithSchemaTestCase(BaseTestCase): def testDefMode(self): assert decoder.decode( - ints2octs((48, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)), asn1Spec=self.s - ) == (self.s, null) + bytes((48, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)), asn1Spec=self.s + ) == (self.s, b'') def testIndefMode(self): assert decoder.decode( - ints2octs((48, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0)), asn1Spec=self.s - ) == (self.s, null) + bytes((48, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0)), asn1Spec=self.s + ) == (self.s, b'') def testDefModeChunked(self): assert decoder.decode( - ints2octs((48, 19, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110)), asn1Spec=self.s - ) == (self.s, null) + bytes((48, 19, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110)), asn1Spec=self.s + ) == (self.s, b'') def testIndefModeChunked(self): assert decoder.decode( - ints2octs((48, 128, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 0, 0)), asn1Spec=self.s - ) == (self.s, null) + bytes((48, 128, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 0, 0)), asn1Spec=self.s + ) == (self.s, b'') class SetOfDecoderTestCase(BaseTestCase): @@ -699,28 +698,28 @@ class SetOfDecoderTestCase(BaseTestCase): def testDefMode(self): assert decoder.decode( - ints2octs((49, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) - ) == (self.s, null) + bytes((49, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) + ) == (self.s, b'') def testIndefMode(self): assert decoder.decode( - ints2octs((49, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0)) - ) == (self.s, null) + bytes((49, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0)) + ) == (self.s, b'') def testDefModeChunked(self): assert decoder.decode( - ints2octs((49, 19, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110)) - ) == (self.s, null) + bytes((49, 19, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110)) + ) == (self.s, b'') def testIndefModeChunked(self): assert decoder.decode( - ints2octs((49, 128, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 0, 0)) - ) == (self.s, null) + bytes((49, 128, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 0, 0)) + ) == (self.s, b'') def testSchemalessDecoder(self): assert decoder.decode( - ints2octs((49, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)), asn1Spec=univ.SetOf() - ) == (self.s, null) + bytes((49, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)), asn1Spec=univ.SetOf() + ) == (self.s, b'') class SetOfDecoderWithSchemaTestCase(BaseTestCase): @@ -731,23 +730,23 @@ class SetOfDecoderWithSchemaTestCase(BaseTestCase): def testDefMode(self): assert decoder.decode( - ints2octs((49, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)), asn1Spec=self.s - ) == (self.s, null) + bytes((49, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)), asn1Spec=self.s + ) == (self.s, b'') def testIndefMode(self): assert decoder.decode( - ints2octs((49, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0)), asn1Spec=self.s - ) == (self.s, null) + bytes((49, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0)), asn1Spec=self.s + ) == (self.s, b'') def testDefModeChunked(self): assert decoder.decode( - ints2octs((49, 19, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110)), asn1Spec=self.s - ) == (self.s, null) + bytes((49, 19, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110)), asn1Spec=self.s + ) == (self.s, b'') def testIndefModeChunked(self): assert decoder.decode( - ints2octs((49, 128, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 0, 0)), asn1Spec=self.s - ) == (self.s, null) + bytes((49, 128, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 0, 0)), asn1Spec=self.s + ) == (self.s, b'') class SequenceDecoderTestCase(BaseTestCase): @@ -755,66 +754,66 @@ class SequenceDecoderTestCase(BaseTestCase): BaseTestCase.setUp(self) self.s = univ.Sequence( componentType=namedtype.NamedTypes( - namedtype.NamedType('place-holder', univ.Null(null)), - namedtype.NamedType('first-name', univ.OctetString(null)), + namedtype.NamedType('place-holder', univ.Null(b'')), + namedtype.NamedType('first-name', univ.OctetString(b'')), namedtype.NamedType('age', univ.Integer(33)) ) ) - self.s.setComponentByPosition(0, univ.Null(null)) + self.s.setComponentByPosition(0, univ.Null(b'')) self.s.setComponentByPosition(1, univ.OctetString('quick brown')) self.s.setComponentByPosition(2, univ.Integer(1)) def testWithOptionalAndDefaultedDefMode(self): assert decoder.decode( - ints2octs((48, 18, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)) - ) == (self.s, null) + bytes((48, 18, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)) + ) == (self.s, b'') def testWithOptionalAndDefaultedIndefMode(self): assert decoder.decode( - ints2octs((48, 128, 5, 0, 36, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)) - ) == (self.s, null) + bytes((48, 128, 5, 0, 36, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)) + ) == (self.s, b'') def testWithOptionalAndDefaultedDefModeChunked(self): assert decoder.decode( - ints2octs( + bytes( (48, 24, 5, 0, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 2, 1, 1)) - ) == (self.s, null) + ) == (self.s, b'') def testWithOptionalAndDefaultedIndefModeChunked(self): assert decoder.decode( - ints2octs((48, 128, 5, 0, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)) - ) == (self.s, null) + bytes((48, 128, 5, 0, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)) + ) == (self.s, b'') def testWithOptionalAndDefaultedDefModeSubst(self): assert decoder.decode( - ints2octs((48, 18, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)), + bytes((48, 18, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)), substrateFun=lambda a, b, c, d: streaming.readFromStream(b, c) - ) == (ints2octs((5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)), str2octs('')) + ) == (bytes((5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)), b'') def testWithOptionalAndDefaultedDefModeSubstV04(self): assert decoder.decode( - ints2octs((48, 18, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)), + bytes((48, 18, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)), substrateFun=lambda a, b, c: (b, b[c:]) - ) == (ints2octs((5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)), str2octs('')) + ) == (bytes((5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)), b'') def testWithOptionalAndDefaultedIndefModeSubst(self): assert decoder.decode( - ints2octs((48, 128, 5, 0, 36, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)), + bytes((48, 128, 5, 0, 36, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)), substrateFun=lambda a, b, c, d: streaming.readFromStream(b, c) - ) == (ints2octs( - (5, 0, 36, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)), str2octs('')) + ) == (bytes( + (5, 0, 36, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)), b'') def testWithOptionalAndDefaultedIndefModeSubstV04(self): assert decoder.decode( - ints2octs((48, 128, 5, 0, 36, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)), + bytes((48, 128, 5, 0, 36, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)), substrateFun=lambda a, b, c: (b, b[c:]) - ) == (ints2octs( - (5, 0, 36, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)), str2octs('')) + ) == (bytes( + (5, 0, 36, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)), b'') def testTagFormat(self): try: decoder.decode( - ints2octs((16, 18, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)) + bytes((16, 18, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)) ) except error.PyAsn1Error: pass @@ -827,7 +826,7 @@ class SequenceDecoderWithSchemaTestCase(BaseTestCase): BaseTestCase.setUp(self) self.s = univ.Sequence( componentType=namedtype.NamedTypes( - namedtype.NamedType('place-holder', univ.Null(null)), + namedtype.NamedType('place-holder', univ.Null(b'')), namedtype.OptionalNamedType('first-name', univ.OctetString()), namedtype.DefaultedNamedType('age', univ.Integer(33)), ) @@ -835,128 +834,128 @@ class SequenceDecoderWithSchemaTestCase(BaseTestCase): def __init(self): self.s.clear() - self.s.setComponentByPosition(0, univ.Null(null)) + self.s.setComponentByPosition(0, univ.Null(b'')) def __initWithOptional(self): self.s.clear() - self.s.setComponentByPosition(0, univ.Null(null)) + self.s.setComponentByPosition(0, univ.Null(b'')) self.s.setComponentByPosition(1, univ.OctetString('quick brown')) def __initWithDefaulted(self): self.s.clear() - self.s.setComponentByPosition(0, univ.Null(null)) + self.s.setComponentByPosition(0, univ.Null(b'')) self.s.setComponentByPosition(2, univ.Integer(1)) def __initWithOptionalAndDefaulted(self): self.s.clear() - self.s.setComponentByPosition(0, univ.Null(null)) + self.s.setComponentByPosition(0, univ.Null(b'')) self.s.setComponentByPosition(1, univ.OctetString('quick brown')) self.s.setComponentByPosition(2, univ.Integer(1)) def testDefMode(self): self.__init() assert decoder.decode( - ints2octs((48, 2, 5, 0)), asn1Spec=self.s - ) == (self.s, null) + bytes((48, 2, 5, 0)), asn1Spec=self.s + ) == (self.s, b'') def testIndefMode(self): self.__init() assert decoder.decode( - ints2octs((48, 128, 5, 0, 0, 0)), asn1Spec=self.s - ) == (self.s, null) + bytes((48, 128, 5, 0, 0, 0)), asn1Spec=self.s + ) == (self.s, b'') def testDefModeChunked(self): self.__init() assert decoder.decode( - ints2octs((48, 2, 5, 0)), asn1Spec=self.s - ) == (self.s, null) + bytes((48, 2, 5, 0)), asn1Spec=self.s + ) == (self.s, b'') def testIndefModeChunked(self): self.__init() assert decoder.decode( - ints2octs((48, 128, 5, 0, 0, 0)), asn1Spec=self.s - ) == (self.s, null) + bytes((48, 128, 5, 0, 0, 0)), asn1Spec=self.s + ) == (self.s, b'') def testWithOptionalDefMode(self): self.__initWithOptional() assert decoder.decode( - ints2octs((48, 15, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)), asn1Spec=self.s - ) == (self.s, null) + bytes((48, 15, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)), asn1Spec=self.s + ) == (self.s, b'') def testWithOptionaIndefMode(self): self.__initWithOptional() assert decoder.decode( - ints2octs((48, 128, 5, 0, 36, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 0, 0)), + bytes((48, 128, 5, 0, 36, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 0, 0)), asn1Spec=self.s - ) == (self.s, null) + ) == (self.s, b'') def testWithOptionalDefModeChunked(self): self.__initWithOptional() assert decoder.decode( - ints2octs((48, 21, 5, 0, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110)), + bytes((48, 21, 5, 0, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110)), asn1Spec=self.s - ) == (self.s, null) + ) == (self.s, b'') def testWithOptionalIndefModeChunked(self): self.__initWithOptional() assert decoder.decode( - ints2octs((48, 128, 5, 0, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, + bytes((48, 128, 5, 0, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 0, 0)), asn1Spec=self.s - ) == (self.s, null) + ) == (self.s, b'') def testWithDefaultedDefMode(self): self.__initWithDefaulted() assert decoder.decode( - ints2octs((48, 5, 5, 0, 2, 1, 1)), asn1Spec=self.s - ) == (self.s, null) + bytes((48, 5, 5, 0, 2, 1, 1)), asn1Spec=self.s + ) == (self.s, b'') def testWithDefaultedIndefMode(self): self.__initWithDefaulted() assert decoder.decode( - ints2octs((48, 128, 5, 0, 2, 1, 1, 0, 0)), asn1Spec=self.s - ) == (self.s, null) + bytes((48, 128, 5, 0, 2, 1, 1, 0, 0)), asn1Spec=self.s + ) == (self.s, b'') def testWithDefaultedDefModeChunked(self): self.__initWithDefaulted() assert decoder.decode( - ints2octs((48, 5, 5, 0, 2, 1, 1)), asn1Spec=self.s - ) == (self.s, null) + bytes((48, 5, 5, 0, 2, 1, 1)), asn1Spec=self.s + ) == (self.s, b'') def testWithDefaultedIndefModeChunked(self): self.__initWithDefaulted() assert decoder.decode( - ints2octs((48, 128, 5, 0, 2, 1, 1, 0, 0)), asn1Spec=self.s - ) == (self.s, null) + bytes((48, 128, 5, 0, 2, 1, 1, 0, 0)), asn1Spec=self.s + ) == (self.s, b'') def testWithOptionalAndDefaultedDefMode(self): self.__initWithOptionalAndDefaulted() assert decoder.decode( - ints2octs((48, 18, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)), + bytes((48, 18, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)), asn1Spec=self.s - ) == (self.s, null) + ) == (self.s, b'') def testWithOptionalAndDefaultedIndefMode(self): self.__initWithOptionalAndDefaulted() assert decoder.decode( - ints2octs((48, 128, 5, 0, 36, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 2, 1, 1, + bytes((48, 128, 5, 0, 36, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)), asn1Spec=self.s - ) == (self.s, null) + ) == (self.s, b'') def testWithOptionalAndDefaultedDefModeChunked(self): self.__initWithOptionalAndDefaulted() assert decoder.decode( - ints2octs( + bytes( (48, 24, 5, 0, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 2, 1, 1)), asn1Spec=self.s - ) == (self.s, null) + ) == (self.s, b'') def testWithOptionalAndDefaultedIndefModeChunked(self): self.__initWithOptionalAndDefaulted() assert decoder.decode( - ints2octs((48, 128, 5, 0, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, + bytes((48, 128, 5, 0, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)), asn1Spec=self.s - ) == (self.s, null) + ) == (self.s, b'') class SequenceDecoderWithUntaggedOpenTypesTestCase(BaseTestCase): @@ -975,7 +974,7 @@ class SequenceDecoderWithUntaggedOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesChoiceOne(self): s, r = decoder.decode( - ints2octs((48, 6, 2, 1, 1, 2, 1, 12)), asn1Spec=self.s, + bytes((48, 6, 2, 1, 1, 2, 1, 12)), asn1Spec=self.s, decodeOpenTypes=True ) assert not r @@ -984,7 +983,7 @@ class SequenceDecoderWithUntaggedOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesChoiceTwo(self): s, r = decoder.decode( - ints2octs((48, 16, 2, 1, 2, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)), asn1Spec=self.s, + bytes((48, 16, 2, 1, 2, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)), asn1Spec=self.s, decodeOpenTypes=True ) assert not r @@ -994,7 +993,7 @@ class SequenceDecoderWithUntaggedOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesUnknownType(self): try: s, r = decoder.decode( - ints2octs((48, 6, 2, 1, 2, 6, 1, 39)), asn1Spec=self.s, + bytes((48, 6, 2, 1, 2, 6, 1, 39)), asn1Spec=self.s, decodeOpenTypes=True ) @@ -1006,7 +1005,7 @@ class SequenceDecoderWithUntaggedOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesUnknownId(self): s, r = decoder.decode( - ints2octs((48, 6, 2, 1, 3, 6, 1, 39)), asn1Spec=self.s, + bytes((48, 6, 2, 1, 3, 6, 1, 39)), asn1Spec=self.s, decodeOpenTypes=True ) assert not r @@ -1015,19 +1014,19 @@ class SequenceDecoderWithUntaggedOpenTypesTestCase(BaseTestCase): def testDontDecodeOpenTypesChoiceOne(self): s, r = decoder.decode( - ints2octs((48, 6, 2, 1, 1, 2, 1, 12)), asn1Spec=self.s + bytes((48, 6, 2, 1, 1, 2, 1, 12)), asn1Spec=self.s ) assert not r assert s[0] == 1 - assert s[1] == ints2octs((2, 1, 12)) + assert s[1] == bytes((2, 1, 12)) def testDontDecodeOpenTypesChoiceTwo(self): s, r = decoder.decode( - ints2octs((48, 16, 2, 1, 2, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)), asn1Spec=self.s + bytes((48, 16, 2, 1, 2, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)), asn1Spec=self.s ) assert not r assert s[0] == 2 - assert s[1] == ints2octs((4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) + assert s[1] == bytes((4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) class SequenceDecoderWithImplicitlyTaggedOpenTypesTestCase(BaseTestCase): @@ -1048,7 +1047,7 @@ class SequenceDecoderWithImplicitlyTaggedOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesChoiceOne(self): s, r = decoder.decode( - ints2octs((48, 8, 2, 1, 1, 131, 3, 2, 1, 12)), asn1Spec=self.s, decodeOpenTypes=True + bytes((48, 8, 2, 1, 1, 131, 3, 2, 1, 12)), asn1Spec=self.s, decodeOpenTypes=True ) assert not r assert s[0] == 1 @@ -1056,7 +1055,7 @@ class SequenceDecoderWithImplicitlyTaggedOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesUnknownId(self): s, r = decoder.decode( - ints2octs((48, 8, 2, 1, 3, 131, 3, 2, 1, 12)), asn1Spec=self.s, decodeOpenTypes=True + bytes((48, 8, 2, 1, 3, 131, 3, 2, 1, 12)), asn1Spec=self.s, decodeOpenTypes=True ) assert not r assert s[0] == 3 @@ -1081,7 +1080,7 @@ class SequenceDecoderWithExplicitlyTaggedOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesChoiceOne(self): s, r = decoder.decode( - ints2octs((48, 8, 2, 1, 1, 163, 3, 2, 1, 12)), asn1Spec=self.s, decodeOpenTypes=True + bytes((48, 8, 2, 1, 1, 163, 3, 2, 1, 12)), asn1Spec=self.s, decodeOpenTypes=True ) assert not r assert s[0] == 1 @@ -1089,7 +1088,7 @@ class SequenceDecoderWithExplicitlyTaggedOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesUnknownId(self): s, r = decoder.decode( - ints2octs((48, 8, 2, 1, 3, 163, 3, 2, 1, 12)), asn1Spec=self.s, decodeOpenTypes=True + bytes((48, 8, 2, 1, 3, 163, 3, 2, 1, 12)), asn1Spec=self.s, decodeOpenTypes=True ) assert not r assert s[0] == 3 @@ -1113,7 +1112,7 @@ class SequenceDecoderWithUnaggedSetOfOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesChoiceOne(self): s, r = decoder.decode( - ints2octs((48, 8, 2, 1, 1, 49, 3, 2, 1, 12)), asn1Spec=self.s, + bytes((48, 8, 2, 1, 1, 49, 3, 2, 1, 12)), asn1Spec=self.s, decodeOpenTypes=True ) assert not r @@ -1122,7 +1121,7 @@ class SequenceDecoderWithUnaggedSetOfOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesChoiceTwo(self): s, r = decoder.decode( - ints2octs((48, 18, 2, 1, 2, 49, 13, 4, 11, 113, 117, 105, 99, + bytes((48, 18, 2, 1, 2, 49, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)), asn1Spec=self.s, decodeOpenTypes=True ) @@ -1133,7 +1132,7 @@ class SequenceDecoderWithUnaggedSetOfOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesUnknownType(self): try: s, r = decoder.decode( - ints2octs((48, 6, 2, 1, 2, 6, 1, 39)), asn1Spec=self.s, + bytes((48, 6, 2, 1, 2, 6, 1, 39)), asn1Spec=self.s, decodeOpenTypes=True ) @@ -1145,7 +1144,7 @@ class SequenceDecoderWithUnaggedSetOfOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesUnknownId(self): s, r = decoder.decode( - ints2octs((48, 8, 2, 1, 3, 49, 3, 2, 1, 12)), asn1Spec=self.s, + bytes((48, 8, 2, 1, 3, 49, 3, 2, 1, 12)), asn1Spec=self.s, decodeOpenTypes=True ) assert not r @@ -1154,20 +1153,20 @@ class SequenceDecoderWithUnaggedSetOfOpenTypesTestCase(BaseTestCase): def testDontDecodeOpenTypesChoiceOne(self): s, r = decoder.decode( - ints2octs((48, 8, 2, 1, 1, 49, 3, 2, 1, 12)), asn1Spec=self.s + bytes((48, 8, 2, 1, 1, 49, 3, 2, 1, 12)), asn1Spec=self.s ) assert not r assert s[0] == 1 - assert s[1][0] == ints2octs((2, 1, 12)) + assert s[1][0] == bytes((2, 1, 12)) def testDontDecodeOpenTypesChoiceTwo(self): s, r = decoder.decode( - ints2octs((48, 18, 2, 1, 2, 49, 13, 4, 11, 113, 117, 105, 99, + bytes((48, 18, 2, 1, 2, 49, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)), asn1Spec=self.s ) assert not r assert s[0] == 2 - assert s[1][0] == ints2octs((4, 11, 113, 117, 105, 99, 107, 32, 98, 114, + assert s[1][0] == bytes((4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) @@ -1193,7 +1192,7 @@ class SequenceDecoderWithImplicitlyTaggedSetOfOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesChoiceOne(self): s, r = decoder.decode( - ints2octs((48, 10, 2, 1, 1, 49, 5, 131, 3, 2, 1, 12)), + bytes((48, 10, 2, 1, 1, 49, 5, 131, 3, 2, 1, 12)), asn1Spec=self.s, decodeOpenTypes=True ) assert not r @@ -1202,7 +1201,7 @@ class SequenceDecoderWithImplicitlyTaggedSetOfOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesUnknownId(self): s, r = decoder.decode( - ints2octs((48, 10, 2, 1, 3, 49, 5, 131, 3, 2, 1, 12)), + bytes((48, 10, 2, 1, 3, 49, 5, 131, 3, 2, 1, 12)), asn1Spec=self.s, decodeOpenTypes=True ) assert not r @@ -1232,7 +1231,7 @@ class SequenceDecoderWithExplicitlyTaggedSetOfOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesChoiceOne(self): s, r = decoder.decode( - ints2octs((48, 10, 2, 1, 1, 49, 5, 131, 3, 2, 1, 12)), + bytes((48, 10, 2, 1, 1, 49, 5, 131, 3, 2, 1, 12)), asn1Spec=self.s, decodeOpenTypes=True ) assert not r @@ -1241,7 +1240,7 @@ class SequenceDecoderWithExplicitlyTaggedSetOfOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesUnknownId(self): s, r = decoder.decode( - ints2octs( (48, 10, 2, 1, 3, 49, 5, 131, 3, 2, 1, 12)), + bytes( (48, 10, 2, 1, 3, 49, 5, 131, 3, 2, 1, 12)), asn1Spec=self.s, decodeOpenTypes=True ) assert not r @@ -1254,66 +1253,66 @@ class SetDecoderTestCase(BaseTestCase): BaseTestCase.setUp(self) self.s = univ.Set( componentType=namedtype.NamedTypes( - namedtype.NamedType('place-holder', univ.Null(null)), - namedtype.NamedType('first-name', univ.OctetString(null)), + namedtype.NamedType('place-holder', univ.Null(b'')), + namedtype.NamedType('first-name', univ.OctetString(b'')), namedtype.NamedType('age', univ.Integer(33)) ) ) - self.s.setComponentByPosition(0, univ.Null(null)) + self.s.setComponentByPosition(0, univ.Null(b'')) self.s.setComponentByPosition(1, univ.OctetString('quick brown')) self.s.setComponentByPosition(2, univ.Integer(1)) def testWithOptionalAndDefaultedDefMode(self): assert decoder.decode( - ints2octs((49, 18, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)) - ) == (self.s, null) + bytes((49, 18, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)) + ) == (self.s, b'') def testWithOptionalAndDefaultedIndefMode(self): assert decoder.decode( - ints2octs((49, 128, 5, 0, 36, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)) - ) == (self.s, null) + bytes((49, 128, 5, 0, 36, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)) + ) == (self.s, b'') def testWithOptionalAndDefaultedDefModeChunked(self): assert decoder.decode( - ints2octs( + bytes( (49, 24, 5, 0, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 2, 1, 1)) - ) == (self.s, null) + ) == (self.s, b'') def testWithOptionalAndDefaultedIndefModeChunked(self): assert decoder.decode( - ints2octs((49, 128, 5, 0, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)) - ) == (self.s, null) + bytes((49, 128, 5, 0, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)) + ) == (self.s, b'') def testWithOptionalAndDefaultedDefModeSubst(self): assert decoder.decode( - ints2octs((49, 18, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)), + bytes((49, 18, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)), substrateFun=lambda a, b, c, d: streaming.readFromStream(b, c) - ) == (ints2octs((5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)), str2octs('')) + ) == (bytes((5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)), b'') def testWithOptionalAndDefaultedDefModeSubstV04(self): assert decoder.decode( - ints2octs((49, 18, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)), + bytes((49, 18, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)), substrateFun=lambda a, b, c: (b, b[c:]) - ) == (ints2octs((5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)), str2octs('')) + ) == (bytes((5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)), b'') def testWithOptionalAndDefaultedIndefModeSubst(self): assert decoder.decode( - ints2octs((49, 128, 5, 0, 36, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)), + bytes((49, 128, 5, 0, 36, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)), substrateFun=lambda a, b, c, d: streaming.readFromStream(b, c) - ) == (ints2octs( - (5, 0, 36, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)), str2octs('')) + ) == (bytes( + (5, 0, 36, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)), b'') def testWithOptionalAndDefaultedIndefModeSubstV04(self): assert decoder.decode( - ints2octs((49, 128, 5, 0, 36, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)), + bytes((49, 128, 5, 0, 36, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)), substrateFun=lambda a, b, c: (b, b[c:]) - ) == (ints2octs( - (5, 0, 36, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)), str2octs('')) + ) == (bytes( + (5, 0, 36, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)), b'') def testTagFormat(self): try: decoder.decode( - ints2octs((16, 18, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)) + bytes((16, 18, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)) ) except error.PyAsn1Error: pass @@ -1326,7 +1325,7 @@ class SetDecoderWithSchemaTestCase(BaseTestCase): BaseTestCase.setUp(self) self.s = univ.Set( componentType=namedtype.NamedTypes( - namedtype.NamedType('place-holder', univ.Null(null)), + namedtype.NamedType('place-holder', univ.Null(b'')), namedtype.OptionalNamedType('first-name', univ.OctetString()), namedtype.DefaultedNamedType('age', univ.Integer(33)), ) @@ -1334,131 +1333,131 @@ class SetDecoderWithSchemaTestCase(BaseTestCase): def __init(self): self.s.clear() - self.s.setComponentByPosition(0, univ.Null(null)) + self.s.setComponentByPosition(0, univ.Null(b'')) def __initWithOptional(self): self.s.clear() - self.s.setComponentByPosition(0, univ.Null(null)) + self.s.setComponentByPosition(0, univ.Null(b'')) self.s.setComponentByPosition(1, univ.OctetString('quick brown')) def __initWithDefaulted(self): self.s.clear() - self.s.setComponentByPosition(0, univ.Null(null)) + self.s.setComponentByPosition(0, univ.Null(b'')) self.s.setComponentByPosition(2, univ.Integer(1)) def __initWithOptionalAndDefaulted(self): self.s.clear() - self.s.setComponentByPosition(0, univ.Null(null)) + self.s.setComponentByPosition(0, univ.Null(b'')) self.s.setComponentByPosition(1, univ.OctetString('quick brown')) self.s.setComponentByPosition(2, univ.Integer(1)) def testDefMode(self): self.__init() assert decoder.decode( - ints2octs((49, 128, 5, 0, 0, 0)), asn1Spec=self.s - ) == (self.s, null) + bytes((49, 128, 5, 0, 0, 0)), asn1Spec=self.s + ) == (self.s, b'') def testIndefMode(self): self.__init() assert decoder.decode( - ints2octs((49, 128, 5, 0, 0, 0)), asn1Spec=self.s - ) == (self.s, null) + bytes((49, 128, 5, 0, 0, 0)), asn1Spec=self.s + ) == (self.s, b'') def testDefModeChunked(self): self.__init() assert decoder.decode( - ints2octs((49, 2, 5, 0)), asn1Spec=self.s - ) == (self.s, null) + bytes((49, 2, 5, 0)), asn1Spec=self.s + ) == (self.s, b'') def testIndefModeChunked(self): self.__init() assert decoder.decode( - ints2octs((49, 128, 5, 0, 0, 0)), asn1Spec=self.s - ) == (self.s, null) + bytes((49, 128, 5, 0, 0, 0)), asn1Spec=self.s + ) == (self.s, b'') def testWithOptionalDefMode(self): self.__initWithOptional() assert decoder.decode( - ints2octs((49, 15, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)), asn1Spec=self.s - ) == (self.s, null) + bytes((49, 15, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)), asn1Spec=self.s + ) == (self.s, b'') def testWithOptionalIndefMode(self): self.__initWithOptional() assert decoder.decode( - ints2octs((49, 128, 5, 0, 36, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 0, 0)), asn1Spec=self.s - ) == (self.s, null) + bytes((49, 128, 5, 0, 36, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 0, 0)), asn1Spec=self.s + ) == (self.s, b'') def testWithOptionalDefModeChunked(self): self.__initWithOptional() assert decoder.decode( - ints2octs((49, 21, 5, 0, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110)), asn1Spec=self.s - ) == (self.s, null) + bytes((49, 21, 5, 0, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110)), asn1Spec=self.s + ) == (self.s, b'') def testWithOptionalIndefModeChunked(self): self.__initWithOptional() assert decoder.decode( - ints2octs((49, 128, 5, 0, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 0, 0)), asn1Spec=self.s - ) == (self.s, null) + bytes((49, 128, 5, 0, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 0, 0)), asn1Spec=self.s + ) == (self.s, b'') def testWithDefaultedDefMode(self): self.__initWithDefaulted() assert decoder.decode( - ints2octs((49, 5, 5, 0, 2, 1, 1)), asn1Spec=self.s - ) == (self.s, null) + bytes((49, 5, 5, 0, 2, 1, 1)), asn1Spec=self.s + ) == (self.s, b'') def testWithDefaultedIndefMode(self): self.__initWithDefaulted() assert decoder.decode( - ints2octs((49, 128, 5, 0, 2, 1, 1, 0, 0)), asn1Spec=self.s - ) == (self.s, null) + bytes((49, 128, 5, 0, 2, 1, 1, 0, 0)), asn1Spec=self.s + ) == (self.s, b'') def testWithDefaultedDefModeChunked(self): self.__initWithDefaulted() assert decoder.decode( - ints2octs((49, 5, 5, 0, 2, 1, 1)), asn1Spec=self.s - ) == (self.s, null) + bytes((49, 5, 5, 0, 2, 1, 1)), asn1Spec=self.s + ) == (self.s, b'') def testWithDefaultedIndefModeChunked(self): self.__initWithDefaulted() assert decoder.decode( - ints2octs((49, 128, 5, 0, 2, 1, 1, 0, 0)), asn1Spec=self.s - ) == (self.s, null) + bytes((49, 128, 5, 0, 2, 1, 1, 0, 0)), asn1Spec=self.s + ) == (self.s, b'') def testWithOptionalAndDefaultedDefMode(self): self.__initWithOptionalAndDefaulted() assert decoder.decode( - ints2octs((49, 18, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)), asn1Spec=self.s - ) == (self.s, null) + bytes((49, 18, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)), asn1Spec=self.s + ) == (self.s, b'') def testWithOptionalAndDefaultedDefModeReordered(self): self.__initWithOptionalAndDefaulted() assert decoder.decode( - ints2octs((49, 18, 2, 1, 1, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 5, 0)), asn1Spec=self.s - ) == (self.s, null) + bytes((49, 18, 2, 1, 1, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 5, 0)), asn1Spec=self.s + ) == (self.s, b'') def testWithOptionalAndDefaultedIndefMode(self): self.__initWithOptionalAndDefaulted() assert decoder.decode( - ints2octs((49, 128, 5, 0, 36, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)), asn1Spec=self.s - ) == (self.s, null) + bytes((49, 128, 5, 0, 36, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)), asn1Spec=self.s + ) == (self.s, b'') def testWithOptionalAndDefaultedIndefModeReordered(self): self.__initWithOptionalAndDefaulted() assert decoder.decode( - ints2octs((49, 128, 2, 1, 1, 5, 0, 36, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 0, 0)), asn1Spec=self.s - ) == (self.s, null) + bytes((49, 128, 2, 1, 1, 5, 0, 36, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 0, 0)), asn1Spec=self.s + ) == (self.s, b'') def testWithOptionalAndDefaultedDefModeChunked(self): self.__initWithOptionalAndDefaulted() assert decoder.decode( - ints2octs((49, 24, 5, 0, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 2, 1, 1)), asn1Spec=self.s - ) == (self.s, null) + bytes((49, 24, 5, 0, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 2, 1, 1)), asn1Spec=self.s + ) == (self.s, b'') def testWithOptionalAndDefaultedIndefModeChunked(self): self.__initWithOptionalAndDefaulted() assert decoder.decode( - ints2octs((49, 128, 5, 0, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)), asn1Spec=self.s - ) == (self.s, null) + bytes((49, 128, 5, 0, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)), asn1Spec=self.s + ) == (self.s, b'') class SequenceOfWithExpTaggedOctetStringDecoder(BaseTestCase): @@ -1471,37 +1470,37 @@ class SequenceOfWithExpTaggedOctetStringDecoder(BaseTestCase): self.s2 = univ.SequenceOf() def testDefModeSchema(self): - s, r = decoder.decode(ints2octs((48, 5, 163, 3, 4, 1, 113)), asn1Spec=self.s) + s, r = decoder.decode(bytes((48, 5, 163, 3, 4, 1, 113)), asn1Spec=self.s) assert not r assert s == self.s assert s.tagSet == self.s.tagSet def testIndefModeSchema(self): - s, r = decoder.decode(ints2octs((48, 128, 163, 128, 4, 1, 113, 0, 0, 0, 0)), asn1Spec=self.s) + s, r = decoder.decode(bytes((48, 128, 163, 128, 4, 1, 113, 0, 0, 0, 0)), asn1Spec=self.s) assert not r assert s == self.s assert s.tagSet == self.s.tagSet def testDefModeNoComponent(self): - s, r = decoder.decode(ints2octs((48, 5, 163, 3, 4, 1, 113)), asn1Spec=self.s2) + s, r = decoder.decode(bytes((48, 5, 163, 3, 4, 1, 113)), asn1Spec=self.s2) assert not r assert s == self.s assert s.tagSet == self.s.tagSet def testIndefModeNoComponent(self): - s, r = decoder.decode(ints2octs((48, 128, 163, 128, 4, 1, 113, 0, 0, 0, 0)), asn1Spec=self.s2) + s, r = decoder.decode(bytes((48, 128, 163, 128, 4, 1, 113, 0, 0, 0, 0)), asn1Spec=self.s2) assert not r assert s == self.s assert s.tagSet == self.s.tagSet def testDefModeSchemaless(self): - s, r = decoder.decode(ints2octs((48, 5, 163, 3, 4, 1, 113))) + s, r = decoder.decode(bytes((48, 5, 163, 3, 4, 1, 113))) assert not r assert s == self.s assert s.tagSet == self.s.tagSet def testIndefModeSchemaless(self): - s, r = decoder.decode(ints2octs((48, 128, 163, 128, 4, 1, 113, 0, 0, 0, 0))) + s, r = decoder.decode(bytes((48, 128, 163, 128, 4, 1, 113, 0, 0, 0, 0))) assert not r assert s == self.s assert s.tagSet == self.s.tagSet @@ -1521,37 +1520,37 @@ class SequenceWithExpTaggedOctetStringDecoder(BaseTestCase): self.s2 = univ.Sequence() def testDefModeSchema(self): - s, r = decoder.decode(ints2octs((48, 5, 163, 3, 4, 1, 113)), asn1Spec=self.s) + s, r = decoder.decode(bytes((48, 5, 163, 3, 4, 1, 113)), asn1Spec=self.s) assert not r assert s == self.s assert s.tagSet == self.s.tagSet def testIndefModeSchema(self): - s, r = decoder.decode(ints2octs((48, 128, 163, 128, 4, 1, 113, 0, 0, 0, 0)), asn1Spec=self.s) + s, r = decoder.decode(bytes((48, 128, 163, 128, 4, 1, 113, 0, 0, 0, 0)), asn1Spec=self.s) assert not r assert s == self.s assert s.tagSet == self.s.tagSet def testDefModeNoComponent(self): - s, r = decoder.decode(ints2octs((48, 5, 163, 3, 4, 1, 113)), asn1Spec=self.s2) + s, r = decoder.decode(bytes((48, 5, 163, 3, 4, 1, 113)), asn1Spec=self.s2) assert not r assert s == self.s assert s.tagSet == self.s.tagSet def testIndefModeNoComponent(self): - s, r = decoder.decode(ints2octs((48, 128, 163, 128, 4, 1, 113, 0, 0, 0, 0)), asn1Spec=self.s2) + s, r = decoder.decode(bytes((48, 128, 163, 128, 4, 1, 113, 0, 0, 0, 0)), asn1Spec=self.s2) assert not r assert s == self.s assert s.tagSet == self.s.tagSet def testDefModeSchemaless(self): - s, r = decoder.decode(ints2octs((48, 5, 163, 3, 4, 1, 113))) + s, r = decoder.decode(bytes((48, 5, 163, 3, 4, 1, 113))) assert not r assert s == self.s assert s.tagSet == self.s.tagSet def testIndefModeSchemaless(self): - s, r = decoder.decode(ints2octs((48, 128, 163, 128, 4, 1, 113, 0, 0, 0, 0))) + s, r = decoder.decode(bytes((48, 128, 163, 128, 4, 1, 113, 0, 0, 0, 0))) assert not r assert s == self.s assert s.tagSet == self.s.tagSet @@ -1562,39 +1561,39 @@ class ChoiceDecoderTestCase(BaseTestCase): BaseTestCase.setUp(self) self.s = univ.Choice( componentType=namedtype.NamedTypes( - namedtype.NamedType('place-holder', univ.Null(null)), + namedtype.NamedType('place-holder', univ.Null(b'')), namedtype.NamedType('number', univ.Integer(0)), namedtype.NamedType('string', univ.OctetString()) ) ) def testBySpec(self): - self.s.setComponentByPosition(0, univ.Null(null)) + self.s.setComponentByPosition(0, univ.Null(b'')) assert decoder.decode( - ints2octs((5, 0)), asn1Spec=self.s - ) == (self.s, null) + bytes((5, 0)), asn1Spec=self.s + ) == (self.s, b'') def testWithoutSpec(self): - self.s.setComponentByPosition(0, univ.Null(null)) - assert decoder.decode(ints2octs((5, 0))) == (self.s, null) - assert decoder.decode(ints2octs((5, 0))) == (univ.Null(null), null) + self.s.setComponentByPosition(0, univ.Null(b'')) + assert decoder.decode(bytes((5, 0))) == (self.s, b'') + assert decoder.decode(bytes((5, 0))) == (univ.Null(b''), b'') def testUndefLength(self): self.s.setComponentByPosition(2, univ.OctetString('abcdefgh')) - assert decoder.decode(ints2octs((36, 128, 4, 3, 97, 98, 99, 4, 3, 100, 101, 102, 4, 2, 103, 104, 0, 0)), - asn1Spec=self.s) == (self.s, null) + assert decoder.decode(bytes((36, 128, 4, 3, 97, 98, 99, 4, 3, 100, 101, 102, 4, 2, 103, 104, 0, 0)), + asn1Spec=self.s) == (self.s, b'') def testExplicitTag(self): s = self.s.subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 4)) - s.setComponentByPosition(0, univ.Null(null)) - assert decoder.decode(ints2octs((164, 2, 5, 0)), asn1Spec=s) == (s, null) + s.setComponentByPosition(0, univ.Null(b'')) + assert decoder.decode(bytes((164, 2, 5, 0)), asn1Spec=s) == (s, b'') def testExplicitTagUndefLength(self): s = self.s.subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 4)) - s.setComponentByPosition(0, univ.Null(null)) - assert decoder.decode(ints2octs((164, 128, 5, 0, 0, 0)), asn1Spec=s) == (s, null) + s.setComponentByPosition(0, univ.Null(b'')) + assert decoder.decode(bytes((164, 128, 5, 0, 0, 0)), asn1Spec=s) == (s, b'') class AnyDecoderTestCase(BaseTestCase): @@ -1604,88 +1603,88 @@ class AnyDecoderTestCase(BaseTestCase): def testByUntagged(self): assert decoder.decode( - ints2octs((4, 3, 102, 111, 120)), asn1Spec=self.s - ) == (univ.Any('\004\003fox'), null) + bytes((4, 3, 102, 111, 120)), asn1Spec=self.s + ) == (univ.Any('\004\003fox'), b'') def testTaggedEx(self): s = univ.Any('\004\003fox').subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 4)) - assert decoder.decode(ints2octs((164, 5, 4, 3, 102, 111, 120)), asn1Spec=s) == (s, null) + assert decoder.decode(bytes((164, 5, 4, 3, 102, 111, 120)), asn1Spec=s) == (s, b'') def testTaggedIm(self): s = univ.Any('\004\003fox').subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 4)) - assert decoder.decode(ints2octs((132, 5, 4, 3, 102, 111, 120)), asn1Spec=s) == (s, null) + assert decoder.decode(bytes((132, 5, 4, 3, 102, 111, 120)), asn1Spec=s) == (s, b'') def testByUntaggedIndefMode(self): assert decoder.decode( - ints2octs((4, 3, 102, 111, 120)), asn1Spec=self.s - ) == (univ.Any('\004\003fox'), null) + bytes((4, 3, 102, 111, 120)), asn1Spec=self.s + ) == (univ.Any('\004\003fox'), b'') def testTaggedExIndefMode(self): s = univ.Any('\004\003fox').subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 4)) - assert decoder.decode(ints2octs((164, 128, 4, 3, 102, 111, 120, 0, 0)), asn1Spec=s) == (s, null) + assert decoder.decode(bytes((164, 128, 4, 3, 102, 111, 120, 0, 0)), asn1Spec=s) == (s, b'') def testTaggedImIndefMode(self): s = univ.Any('\004\003fox').subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 4)) - assert decoder.decode(ints2octs((164, 128, 4, 3, 102, 111, 120, 0, 0)), asn1Spec=s) == (s, null) + assert decoder.decode(bytes((164, 128, 4, 3, 102, 111, 120, 0, 0)), asn1Spec=s) == (s, b'') def testByUntaggedSubst(self): assert decoder.decode( - ints2octs((4, 3, 102, 111, 120)), + bytes((4, 3, 102, 111, 120)), asn1Spec=self.s, substrateFun=lambda a, b, c, d: streaming.readFromStream(b, c) - ) == (ints2octs((4, 3, 102, 111, 120)), str2octs('')) + ) == (bytes((4, 3, 102, 111, 120)), b'') def testByUntaggedSubstV04(self): assert decoder.decode( - ints2octs((4, 3, 102, 111, 120)), + bytes((4, 3, 102, 111, 120)), asn1Spec=self.s, substrateFun=lambda a, b, c: (b, b[c:]) - ) == (ints2octs((4, 3, 102, 111, 120)), str2octs('')) + ) == (bytes((4, 3, 102, 111, 120)), b'') def testTaggedExSubst(self): assert decoder.decode( - ints2octs((164, 5, 4, 3, 102, 111, 120)), + bytes((164, 5, 4, 3, 102, 111, 120)), asn1Spec=self.s, substrateFun=lambda a, b, c, d: streaming.readFromStream(b, c) - ) == (ints2octs((164, 5, 4, 3, 102, 111, 120)), str2octs('')) + ) == (bytes((164, 5, 4, 3, 102, 111, 120)), b'') def testTaggedExSubstV04(self): assert decoder.decode( - ints2octs((164, 5, 4, 3, 102, 111, 120)), + bytes((164, 5, 4, 3, 102, 111, 120)), asn1Spec=self.s, substrateFun=lambda a, b, c: (b, b[c:]) - ) == (ints2octs((164, 5, 4, 3, 102, 111, 120)), str2octs('')) + ) == (bytes((164, 5, 4, 3, 102, 111, 120)), b'') class EndOfOctetsTestCase(BaseTestCase): def testUnexpectedEoo(self): try: - decoder.decode(ints2octs((0, 0))) + decoder.decode(bytes((0, 0))) except error.PyAsn1Error: pass else: assert 0, 'end-of-contents octets accepted at top level' def testExpectedEoo(self): - result, remainder = decoder.decode(ints2octs((0, 0)), allowEoo=True) + result, remainder = decoder.decode(bytes((0, 0)), allowEoo=True) assert eoo.endOfOctets.isSameTypeWith(result) and result == eoo.endOfOctets and result is eoo.endOfOctets - assert remainder == null + assert remainder == b'' def testDefiniteNoEoo(self): try: - decoder.decode(ints2octs((0x23, 0x02, 0x00, 0x00))) + decoder.decode(bytes((0x23, 0x02, 0x00, 0x00))) except error.PyAsn1Error: pass else: assert 0, 'end-of-contents octets accepted inside definite-length encoding' def testIndefiniteEoo(self): - result, remainder = decoder.decode(ints2octs((0x23, 0x80, 0x00, 0x00))) - assert result == () and remainder == null, 'incorrect decoding of indefinite length end-of-octets' + result, remainder = decoder.decode(bytes((0x23, 0x80, 0x00, 0x00))) + assert result == () and remainder == b'', 'incorrect decoding of indefinite length end-of-octets' def testNoLongFormEoo(self): try: - decoder.decode(ints2octs((0x23, 0x80, 0x00, 0x81, 0x00))) + decoder.decode(bytes((0x23, 0x80, 0x00, 0x81, 0x00))) except error.PyAsn1Error: pass else: @@ -1693,7 +1692,7 @@ class EndOfOctetsTestCase(BaseTestCase): def testNoConstructedEoo(self): try: - decoder.decode(ints2octs((0x23, 0x80, 0x20, 0x00))) + decoder.decode(bytes((0x23, 0x80, 0x20, 0x00))) except error.PyAsn1Error: pass else: @@ -1701,7 +1700,7 @@ class EndOfOctetsTestCase(BaseTestCase): def testNoEooData(self): try: - decoder.decode(ints2octs((0x23, 0x80, 0x00, 0x01, 0x00))) + decoder.decode(bytes((0x23, 0x80, 0x00, 0x01, 0x00))) except error.PyAsn1Error: pass else: @@ -1713,16 +1712,16 @@ class NonStringDecoderTestCase(BaseTestCase): BaseTestCase.setUp(self) self.s = univ.Sequence( componentType=namedtype.NamedTypes( - namedtype.NamedType('place-holder', univ.Null(null)), - namedtype.NamedType('first-name', univ.OctetString(null)), + namedtype.NamedType('place-holder', univ.Null(b'')), + namedtype.NamedType('first-name', univ.OctetString(b'')), namedtype.NamedType('age', univ.Integer(33)) ) ) - self.s.setComponentByPosition(0, univ.Null(null)) + self.s.setComponentByPosition(0, univ.Null(b'')) self.s.setComponentByPosition(1, univ.OctetString('quick brown')) self.s.setComponentByPosition(2, univ.Integer(1)) - self.substrate = ints2octs([48, 18, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1]) + self.substrate = bytes([48, 18, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1]) def testOctetString(self): s = list(decoder.StreamingDecoder( @@ -1740,22 +1739,20 @@ class ErrorOnDecodingTestCase(BaseTestCase): def testErrorCondition(self): decode = decoder.SingleItemDecoder( tagMap=decoder.TAG_MAP, typeMap=decoder.TYPE_MAP) - substrate = ints2octs((00, 1, 2)) + substrate = bytes((00, 1, 2)) stream = streaming.asSeekableStream(substrate) try: asn1Object = next(decode(stream)) except error.PyAsn1Error: - exc = sys.exc_info()[1] - assert isinstance(exc, error.PyAsn1Error), ( - 'Unexpected exception raised %r' % (exc,)) + pass else: assert False, 'Unexpected decoder result %r' % (asn1Object,) def testRawDump(self): - substrate = ints2octs((31, 8, 2, 1, 1, 131, 3, 2, 1, 12)) + substrate = bytes((31, 8, 2, 1, 1, 131, 3, 2, 1, 12)) stream = streaming.asSeekableStream(substrate) class SingleItemEncoder(decoder.SingleItemDecoder): @@ -1775,18 +1772,17 @@ class ErrorOnDecodingTestCase(BaseTestCase): 'Unexpected raw dump type %r' % (asn1Object,)) assert asn1Object.asNumbers() == (31, 8, 2, 1, 1), ( 'Unexpected raw dump value %r' % (asn1Object,)) - assert rest == ints2octs((131, 3, 2, 1, 12)), ( + assert rest == bytes((131, 3, 2, 1, 12)), ( 'Unexpected rest of substrate after raw dump %r' % rest) -@unittest.skipIf(sys.version_info < (3,), "Unsupported on Python 2") class BinaryFileTestCase(BaseTestCase): """Assure that decode works on open binary files.""" def testOneObject(self): _, path = tempfile.mkstemp() try: with open(path, "wb") as out: - out.write(ints2octs((2, 1, 12))) + out.write(bytes((2, 1, 12))) with open(path, "rb") as source: values = list(decoder.StreamingDecoder(source)) @@ -1799,7 +1795,7 @@ class BinaryFileTestCase(BaseTestCase): _, path = tempfile.mkstemp() try: with open(path, "wb") as out: - out.write(ints2octs((2, 1, 12, 35, 128, 3, 2, 0, 169, 3, 2, 1, 138, 0, 0))) + out.write(bytes((2, 1, 12, 35, 128, 3, 2, 0, 169, 3, 2, 1, 138, 0, 0))) with open(path, "rb") as source: values = list(decoder.StreamingDecoder(source)) @@ -1813,7 +1809,7 @@ class BinaryFileTestCase(BaseTestCase): _, path = tempfile.mkstemp() try: with open(path, "wb") as out: - out.write(ints2octs((2, 1, 12, 35, 128, 3, 2, 0, 169, 3, 2, 1, 138, 0, 0, 7))) + out.write(bytes((2, 1, 12, 35, 128, 3, 2, 0, 169, 3, 2, 1, 138, 0, 0, 7))) with open(path, "rb") as source: list(decoder.StreamingDecoder(source)) @@ -1827,7 +1823,7 @@ class BinaryFileTestCase(BaseTestCase): class BytesIOTestCase(BaseTestCase): def testRead(self): - source = ints2octs((2, 1, 12, 35, 128, 3, 2, 0, 169, 3, 2, 1, 138, 0, 0)) + source = bytes((2, 1, 12, 35, 128, 3, 2, 0, 169, 3, 2, 1, 138, 0, 0)) stream = io.BytesIO(source) values = list(decoder.StreamingDecoder(stream)) assert values == [12, (1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1)] @@ -1835,8 +1831,8 @@ class BytesIOTestCase(BaseTestCase): class UnicodeTestCase(BaseTestCase): def testFail(self): - # This ensures that str objects in Python 3.7 cannot be parsed. - source = ints2octs((2, 1, 12, 35, 128, 3, 2, 0, 169, 3, 2, 1, 138, 0, 0)).decode("latin-1") + # This ensures that str objects cannot be parsed. + source = bytes((2, 1, 12, 35, 128, 3, 2, 0, 169, 3, 2, 1, 138, 0, 0)).decode("latin-1") try: next(decoder.StreamingDecoder(source)) @@ -1864,7 +1860,7 @@ class RestartableDecoderTestCase(BaseTestCase): self.s = univ.SequenceOf(componentType=univ.OctetString()) self.s.setComponentByPosition(0, univ.OctetString('quick brown')) - source = ints2octs( + source = bytes( (48, 26, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) @@ -1952,7 +1948,7 @@ class CompressedFilesTestCase(BaseTestCase): _, path = tempfile.mkstemp(suffix=".gz") try: with gzip.open(path, "wb") as out: - out.write(ints2octs((2, 1, 12, 35, 128, 3, 2, 0, 169, 3, 2, 1, 138, 0, 0))) + out.write(bytes((2, 1, 12, 35, 128, 3, 2, 0, 169, 3, 2, 1, 138, 0, 0))) with gzip.open(path, "rb") as source: values = list(decoder.StreamingDecoder(source)) @@ -1967,7 +1963,7 @@ class CompressedFilesTestCase(BaseTestCase): _, path = tempfile.mkstemp(suffix=".zip") try: with zipfile.ZipFile(path, "w") as myzip: - myzip.writestr("data", ints2octs((2, 1, 12, 35, 128, 3, 2, 0, 169, 3, 2, 1, 138, 0, 0))) + myzip.writestr("data", bytes((2, 1, 12, 35, 128, 3, 2, 0, 169, 3, 2, 1, 138, 0, 0))) with zipfile.ZipFile(path, "r") as myzip: with myzip.open("data", "r") as source: @@ -1981,7 +1977,7 @@ class CompressedFilesTestCase(BaseTestCase): try: with zipfile.ZipFile(path, "w") as myzip: #for i in range(100): - myzip.writestr("data", ints2octs((2, 1, 12, 35, 128, 3, 2, 0, 169, 3, 2, 1, 138, 0, 0)) * 1000) + myzip.writestr("data", bytes((2, 1, 12, 35, 128, 3, 2, 0, 169, 3, 2, 1, 138, 0, 0)) * 1000) with zipfile.ZipFile(path, "r") as myzip: with myzip.open("data", "r") as source: @@ -1998,7 +1994,7 @@ class NonStreamingCompatibilityTestCase(BaseTestCase): debug.setLogger(None) # undo logger setup from BaseTestCase to work around unrelated issue def testPartialDecodeWithCustomSubstrateFun(self): - snmp_req_substrate = ints2octs(( + snmp_req_substrate = bytes(( 0x30, 0x22, 0x02, 0x01, 0x01, 0x04, 0x06, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0xa0, 0x15, 0x02, 0x04, 0x69, 0x30, 0xdb, 0xeb, 0x02, 0x01, 0x00, 0x02, 0x01, 0x00, 0x30, 0x07, 0x30, 0x05, 0x06, 0x01, 0x01, 0x05, 0x00)) seq, next_substrate = decoder.decode( @@ -2014,7 +2010,7 @@ class NonStreamingCompatibilityTestCase(BaseTestCase): assert version == 1 def testPartialDecodeWithDefaultSubstrateFun(self): - substrate = ints2octs(( + substrate = bytes(( 0x04, 0x0e, 0x30, 0x0c, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x3c, 0x03, 0x02 )) result, rest = decoder.decode(substrate, recursiveFlag=False) @@ -2022,7 +2018,7 @@ class NonStreamingCompatibilityTestCase(BaseTestCase): assert rest == substrate[2:] def testPropagateUserException(self): - substrate = io.BytesIO(ints2octs((0x04, 0x00))) + substrate = io.BytesIO(bytes((0x04, 0x00))) def userSubstrateFun(_asn1Object, _substrate, _length, _options): raise TypeError("error inside user function") diff --git a/contrib/python/pyasn1/py3/tests/codec/ber/test_encoder.py b/contrib/python/pyasn1/py3/tests/codec/ber/test_encoder.py index 4cce526be9..4f5d53b623 100644 --- a/contrib/python/pyasn1/py3/tests/codec/ber/test_encoder.py +++ b/contrib/python/pyasn1/py3/tests/codec/ber/test_encoder.py @@ -15,7 +15,6 @@ from pyasn1.type import opentype from pyasn1.type import univ from pyasn1.type import char from pyasn1.codec.ber import encoder -from pyasn1.compat.octets import ints2octs from pyasn1.error import PyAsn1Error @@ -28,69 +27,69 @@ class LargeTagEncoderTestCase(BaseTestCase): ) def testEncoder(self): - assert encoder.encode(self.o) == ints2octs((127, 141, 245, 182, 253, 47, 3, 2, 1, 1)) + assert encoder.encode(self.o) == bytes((127, 141, 245, 182, 253, 47, 3, 2, 1, 1)) class IntegerEncoderTestCase(BaseTestCase): def testPosInt(self): - assert encoder.encode(univ.Integer(12)) == ints2octs((2, 1, 12)) + assert encoder.encode(univ.Integer(12)) == bytes((2, 1, 12)) def testNegInt(self): - assert encoder.encode(univ.Integer(-12)) == ints2octs((2, 1, 244)) + assert encoder.encode(univ.Integer(-12)) == bytes((2, 1, 244)) def testZero(self): - assert encoder.encode(univ.Integer(0)) == ints2octs((2, 1, 0)) + assert encoder.encode(univ.Integer(0)) == bytes((2, 1, 0)) def testCompactZero(self): encoder.IntegerEncoder.supportCompactZero = True substrate = encoder.encode(univ.Integer(0)) encoder.IntegerEncoder.supportCompactZero = False - assert substrate == ints2octs((2, 0)) + assert substrate == bytes((2, 0)) def testMinusOne(self): - assert encoder.encode(univ.Integer(-1)) == ints2octs((2, 1, 255)) + assert encoder.encode(univ.Integer(-1)) == bytes((2, 1, 255)) def testPosLong(self): assert encoder.encode( univ.Integer(0xffffffffffffffff) - ) == ints2octs((2, 9, 0, 255, 255, 255, 255, 255, 255, 255, 255)) + ) == bytes((2, 9, 0, 255, 255, 255, 255, 255, 255, 255, 255)) def testNegLong(self): assert encoder.encode( univ.Integer(-0xffffffffffffffff) - ) == ints2octs((2, 9, 255, 0, 0, 0, 0, 0, 0, 0, 1)) + ) == bytes((2, 9, 255, 0, 0, 0, 0, 0, 0, 0, 1)) class IntegerEncoderWithSchemaTestCase(BaseTestCase): def testPosInt(self): - assert encoder.encode(12, asn1Spec=univ.Integer()) == ints2octs((2, 1, 12)) + assert encoder.encode(12, asn1Spec=univ.Integer()) == bytes((2, 1, 12)) def testNegInt(self): - assert encoder.encode(-12, asn1Spec=univ.Integer()) == ints2octs((2, 1, 244)) + assert encoder.encode(-12, asn1Spec=univ.Integer()) == bytes((2, 1, 244)) def testZero(self): - assert encoder.encode(0, asn1Spec=univ.Integer()) == ints2octs((2, 1, 0)) + assert encoder.encode(0, asn1Spec=univ.Integer()) == bytes((2, 1, 0)) def testPosLong(self): assert encoder.encode( 0xffffffffffffffff, asn1Spec=univ.Integer() - ) == ints2octs((2, 9, 0, 255, 255, 255, 255, 255, 255, 255, 255)) + ) == bytes((2, 9, 0, 255, 255, 255, 255, 255, 255, 255, 255)) class BooleanEncoderTestCase(BaseTestCase): def testTrue(self): - assert encoder.encode(univ.Boolean(1)) == ints2octs((1, 1, 1)) + assert encoder.encode(univ.Boolean(1)) == bytes((1, 1, 1)) def testFalse(self): - assert encoder.encode(univ.Boolean(0)) == ints2octs((1, 1, 0)) + assert encoder.encode(univ.Boolean(0)) == bytes((1, 1, 0)) class BooleanEncoderWithSchemaTestCase(BaseTestCase): def testTrue(self): - assert encoder.encode(True, asn1Spec=univ.Boolean()) == ints2octs((1, 1, 1)) + assert encoder.encode(True, asn1Spec=univ.Boolean()) == bytes((1, 1, 1)) def testFalse(self): - assert encoder.encode(False, asn1Spec=univ.Boolean()) == ints2octs((1, 1, 0)) + assert encoder.encode(False, asn1Spec=univ.Boolean()) == bytes((1, 1, 0)) class BitStringEncoderTestCase(BaseTestCase): @@ -99,25 +98,25 @@ class BitStringEncoderTestCase(BaseTestCase): self.b = univ.BitString((1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1)) def testDefMode(self): - assert encoder.encode(self.b) == ints2octs((3, 3, 1, 169, 138)) + assert encoder.encode(self.b) == bytes((3, 3, 1, 169, 138)) def testIndefMode(self): assert encoder.encode( self.b, defMode=False - ) == ints2octs((3, 3, 1, 169, 138)) + ) == bytes((3, 3, 1, 169, 138)) def testDefModeChunked(self): assert encoder.encode( self.b, maxChunkSize=1 - ) == ints2octs((35, 8, 3, 2, 0, 169, 3, 2, 1, 138)) + ) == bytes((35, 8, 3, 2, 0, 169, 3, 2, 1, 138)) def testIndefModeChunked(self): assert encoder.encode( self.b, defMode=False, maxChunkSize=1 - ) == ints2octs((35, 128, 3, 2, 0, 169, 3, 2, 1, 138, 0, 0)) + ) == bytes((35, 128, 3, 2, 0, 169, 3, 2, 1, 138, 0, 0)) def testEmptyValue(self): - assert encoder.encode(univ.BitString([])) == ints2octs((3, 1, 0)) + assert encoder.encode(univ.BitString([])) == bytes((3, 1, 0)) class BitStringEncoderWithSchemaTestCase(BaseTestCase): @@ -127,25 +126,25 @@ class BitStringEncoderWithSchemaTestCase(BaseTestCase): self.s = univ.BitString() def testDefMode(self): - assert encoder.encode(self.b, asn1Spec=self.s) == ints2octs((3, 3, 1, 169, 138)) + assert encoder.encode(self.b, asn1Spec=self.s) == bytes((3, 3, 1, 169, 138)) def testIndefMode(self): assert encoder.encode( self.b, asn1Spec=self.s, defMode=False - ) == ints2octs((3, 3, 1, 169, 138)) + ) == bytes((3, 3, 1, 169, 138)) def testDefModeChunked(self): assert encoder.encode( self.b, asn1Spec=self.s, maxChunkSize=1 - ) == ints2octs((35, 8, 3, 2, 0, 169, 3, 2, 1, 138)) + ) == bytes((35, 8, 3, 2, 0, 169, 3, 2, 1, 138)) def testIndefModeChunked(self): assert encoder.encode( self.b, asn1Spec=self.s, defMode=False, maxChunkSize=1 - ) == ints2octs((35, 128, 3, 2, 0, 169, 3, 2, 1, 138, 0, 0)) + ) == bytes((35, 128, 3, 2, 0, 169, 3, 2, 1, 138, 0, 0)) def testEmptyValue(self): - assert encoder.encode([], asn1Spec=self.s) == ints2octs((3, 1, 0)) + assert encoder.encode([], asn1Spec=self.s) == bytes((3, 1, 0)) class OctetStringEncoderTestCase(BaseTestCase): @@ -154,24 +153,24 @@ class OctetStringEncoderTestCase(BaseTestCase): self.o = univ.OctetString('Quick brown fox') def testDefMode(self): - assert encoder.encode(self.o) == ints2octs( + assert encoder.encode(self.o) == bytes( (4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120)) def testIndefMode(self): assert encoder.encode( self.o, defMode=False - ) == ints2octs((4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120)) + ) == bytes((4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120)) def testDefModeChunked(self): assert encoder.encode( self.o, maxChunkSize=4 - ) == ints2octs((36, 23, 4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, + ) == bytes((36, 23, 4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111, 120)) def testIndefModeChunked(self): assert encoder.encode( self.o, defMode=False, maxChunkSize=4 - ) == ints2octs((36, 128, 4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, + ) == bytes((36, 128, 4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111, 120, 0, 0)) @@ -182,24 +181,24 @@ class OctetStringEncoderWithSchemaTestCase(BaseTestCase): self.o = 'Quick brown fox' def testDefMode(self): - assert encoder.encode(self.o, asn1Spec=self.s) == ints2octs( + assert encoder.encode(self.o, asn1Spec=self.s) == bytes( (4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120)) def testIndefMode(self): assert encoder.encode( self.o, asn1Spec=self.s, defMode=False - ) == ints2octs((4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120)) + ) == bytes((4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120)) def testDefModeChunked(self): assert encoder.encode( self.o, asn1Spec=self.s, maxChunkSize=4 - ) == ints2octs((36, 23, 4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, + ) == bytes((36, 23, 4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111, 120)) def testIndefModeChunked(self): assert encoder.encode( self.o, asn1Spec=self.s, defMode=False, maxChunkSize=4 - ) == ints2octs((36, 128, 4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, + ) == bytes((36, 128, 4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111, 120, 0, 0)) @@ -212,98 +211,98 @@ class ExpTaggedOctetStringEncoderTestCase(BaseTestCase): ) def testDefMode(self): - assert encoder.encode(self.o) == ints2octs( + assert encoder.encode(self.o) == bytes( (101, 17, 4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120)) def testIndefMode(self): assert encoder.encode( self.o, defMode=False - ) == ints2octs((101, 128, 4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 0, 0)) + ) == bytes((101, 128, 4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 0, 0)) def testDefModeChunked(self): assert encoder.encode( self.o, defMode=True, maxChunkSize=4 - ) == ints2octs((101, 25, 36, 23, 4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, + ) == bytes((101, 25, 36, 23, 4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111, 120)) def testIndefModeChunked(self): assert encoder.encode( self.o, defMode=False, maxChunkSize=4 - ) == ints2octs((101, 128, 36, 128, 4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111, 120, 0, 0, 0, 0)) + ) == bytes((101, 128, 36, 128, 4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111, 120, 0, 0, 0, 0)) class NullEncoderTestCase(BaseTestCase): def testNull(self): - assert encoder.encode(univ.Null('')) == ints2octs((5, 0)) + assert encoder.encode(univ.Null('')) == bytes((5, 0)) class NullEncoderWithSchemaTestCase(BaseTestCase): def testNull(self): - assert encoder.encode(None, univ.Null()) == ints2octs((5, 0)) + assert encoder.encode(None, univ.Null()) == bytes((5, 0)) class ObjectIdentifierEncoderTestCase(BaseTestCase): def testOne(self): assert encoder.encode( univ.ObjectIdentifier((1, 3, 6, 0, 0xffffe)) - ) == ints2octs((6, 6, 43, 6, 0, 191, 255, 126)) + ) == bytes((6, 6, 43, 6, 0, 191, 255, 126)) def testEdge1(self): assert encoder.encode( univ.ObjectIdentifier((0, 39)) - ) == ints2octs((6, 1, 39)) + ) == bytes((6, 1, 39)) def testEdge2(self): assert encoder.encode( univ.ObjectIdentifier((1, 39)) - ) == ints2octs((6, 1, 79)) + ) == bytes((6, 1, 79)) def testEdge3(self): # 01111111 assert encoder.encode( univ.ObjectIdentifier((2, 40)) - ) == ints2octs((6, 1, 120)) + ) == bytes((6, 1, 120)) def testEdge4(self): # 10010000|10000000|10000000|10000000|01001111 assert encoder.encode( univ.ObjectIdentifier((2, 0xffffffff)) - ) == ints2octs((6, 5, 0x90, 0x80, 0x80, 0x80, 0x4F)) + ) == bytes((6, 5, 0x90, 0x80, 0x80, 0x80, 0x4F)) def testEdge5(self): # 01111111 assert encoder.encode( univ.ObjectIdentifier((2, 47)) - ) == ints2octs((6, 1, 0x7F)) + ) == bytes((6, 1, 0x7F)) def testEdge6(self): # 10000001|00000000 assert encoder.encode( univ.ObjectIdentifier((2, 48)) - ) == ints2octs((6, 2, 0x81, 0x00)) + ) == bytes((6, 2, 0x81, 0x00)) def testEdge7(self): # 10000001|00110100|00000003 assert encoder.encode( univ.ObjectIdentifier((2, 100, 3)) - ) == ints2octs((6, 3, 0x81, 0x34, 0x03)) + ) == bytes((6, 3, 0x81, 0x34, 0x03)) def testEdge8(self): # 10000101|00000000 assert encoder.encode( univ.ObjectIdentifier((2, 560)) - ) == ints2octs((6, 2, 133, 0)) + ) == bytes((6, 2, 133, 0)) def testEdge9(self): # 10001000|10000100|10000111|0000010 assert encoder.encode( univ.ObjectIdentifier((2, 16843570)) - ) == ints2octs((6, 4, 0x88, 0x84, 0x87, 0x02)) + ) == bytes((6, 4, 0x88, 0x84, 0x87, 0x02)) def testEdgeA(self): assert encoder.encode( univ.ObjectIdentifier((2, 5)) - ) == ints2octs((6, 1, 85)) + ) == bytes((6, 1, 85)) def testImpossible1(self): try: @@ -340,13 +339,13 @@ class ObjectIdentifierEncoderTestCase(BaseTestCase): def testLarge1(self): assert encoder.encode( univ.ObjectIdentifier((2, 18446744073709551535184467440737095)) - ) == ints2octs((0x06, 0x11, 0x83, 0xC6, 0xDF, 0xD4, 0xCC, 0xB3, 0xFF, 0xFF, 0xFE, 0xF0, 0xB8, 0xD6, 0xB8, 0xCB, + ) == bytes((0x06, 0x11, 0x83, 0xC6, 0xDF, 0xD4, 0xCC, 0xB3, 0xFF, 0xFF, 0xFE, 0xF0, 0xB8, 0xD6, 0xB8, 0xCB, 0xE2, 0xB7, 0x17)) def testLarge2(self): assert encoder.encode( univ.ObjectIdentifier((2, 999, 18446744073709551535184467440737095)) - ) == ints2octs((0x06, 0x13, 0x88, 0x37, 0x83, 0xC6, 0xDF, 0xD4, 0xCC, 0xB3, 0xFF, 0xFF, 0xFE, 0xF0, 0xB8, 0xD6, + ) == bytes((0x06, 0x13, 0x88, 0x37, 0x83, 0xC6, 0xDF, 0xD4, 0xCC, 0xB3, 0xFF, 0xFF, 0xFE, 0xF0, 0xB8, 0xD6, 0xB8, 0xCB, 0xE2, 0xB6, 0x47)) @@ -354,29 +353,29 @@ class ObjectIdentifierWithSchemaEncoderTestCase(BaseTestCase): def testOne(self): assert encoder.encode( (1, 3, 6, 0, 0xffffe), asn1Spec=univ.ObjectIdentifier() - ) == ints2octs((6, 6, 43, 6, 0, 191, 255, 126)) + ) == bytes((6, 6, 43, 6, 0, 191, 255, 126)) class RelativeOIDEncoderTestCase(BaseTestCase): def testOne(self): assert encoder.encode( univ.RelativeOID((39,)) - ) == ints2octs((13, 1, 39)) + ) == bytes((13, 1, 39)) def testTwo(self): assert encoder.encode( univ.RelativeOID((5, 6)) - ) == ints2octs((13, 2, 5, 6)) + ) == bytes((13, 2, 5, 6)) def testThree(self): assert encoder.encode( univ.RelativeOID((5, 6, 7)) - ) == ints2octs((13, 3, 5, 6, 7)) + ) == bytes((13, 3, 5, 6, 7)) def testLarge(self): assert encoder.encode( univ.RelativeOID((1079, 18446744073709551535184467440737095)) - ) == ints2octs((0x0D, 0x13, 0x88, 0x37, 0x83, 0xC6, 0xDF, 0xD4, 0xCC, + ) == bytes((0x0D, 0x13, 0x88, 0x37, 0x83, 0xC6, 0xDF, 0xD4, 0xCC, 0xB3, 0xFF, 0xFF, 0xFE, 0xF0, 0xB8, 0xD6, 0xB8, 0xCB, 0xE2, 0xB6, 0x47)) @@ -385,33 +384,33 @@ class RelativeOIDWithSchemaEncoderTestCase(BaseTestCase): def testOne(self): assert encoder.encode( (5, 6, 7), asn1Spec=univ.RelativeOID() - ) == ints2octs((13, 3, 5, 6, 7)) + ) == bytes((13, 3, 5, 6, 7)) class RealEncoderTestCase(BaseTestCase): def testChar(self): assert encoder.encode( univ.Real((123, 10, 11)) - ) == ints2octs((9, 7, 3, 49, 50, 51, 69, 49, 49)) + ) == bytes((9, 7, 3, 49, 50, 51, 69, 49, 49)) def testBin1(self): assert encoder.encode( # default binEncBase = 2 univ.Real((0.5, 2, 0)) # check encbase = 2 and exponent = -1 - ) == ints2octs((9, 3, 128, 255, 1)) + ) == bytes((9, 3, 128, 255, 1)) def testBin2(self): r = univ.Real((3.25, 2, 0)) r.binEncBase = 8 # change binEncBase only for this instance of Real assert encoder.encode( r # check encbase = 8 - ) == ints2octs((9, 3, 148, 255, 13)) + ) == bytes((9, 3, 148, 255, 13)) def testBin3(self): # change binEncBase in the RealEncoder instance => for all further Real binEncBase, encoder.TYPE_MAP[univ.Real.typeId].binEncBase = encoder.TYPE_MAP[univ.Real.typeId].binEncBase, 16 assert encoder.encode( univ.Real((0.00390625, 2, 0)) # check encbase = 16 - ) == ints2octs((9, 3, 160, 254, 1)) + ) == bytes((9, 3, 160, 254, 1)) encoder.TYPE_MAP[univ.Real.typeId].binEncBase = binEncBase def testBin4(self): @@ -419,7 +418,7 @@ class RealEncoderTestCase(BaseTestCase): binEncBase, encoder.TYPE_MAP[univ.Real.typeId].binEncBase = encoder.TYPE_MAP[univ.Real.typeId].binEncBase, None assert encoder.encode( univ.Real((1, 2, 0)) # check exponent = 0 - ) == ints2octs((9, 3, 128, 0, 1)) + ) == bytes((9, 3, 128, 0, 1)) encoder.TYPE_MAP[univ.Real.typeId].binEncBase = binEncBase def testBin5(self): @@ -427,108 +426,108 @@ class RealEncoderTestCase(BaseTestCase): univ.Real((3, 2, -1020)) # case of 2 octs for exponent and # negative exponent and abs(exponent) is # all 1's and fills the whole octet(s) - ) == ints2octs((9, 4, 129, 252, 4, 3)) + ) == bytes((9, 4, 129, 252, 4, 3)) def testBin6(self): assert encoder.encode( univ.Real((1, 2, 262140)) # case of 3 octs for exponent and # check that first 9 bits for exponent # are not all 1's - ) == ints2octs((9, 5, 130, 3, 255, 252, 1)) + ) == bytes((9, 5, 130, 3, 255, 252, 1)) def testBin7(self): assert encoder.encode( univ.Real((-1, 2, 76354972)) # case of >3 octs for exponent and # mantissa < 0 - ) == ints2octs((9, 7, 195, 4, 4, 141, 21, 156, 1)) + ) == bytes((9, 7, 195, 4, 4, 141, 21, 156, 1)) def testPlusInf(self): - assert encoder.encode(univ.Real('inf')) == ints2octs((9, 1, 64)) + assert encoder.encode(univ.Real('inf')) == bytes((9, 1, 64)) def testMinusInf(self): - assert encoder.encode(univ.Real('-inf')) == ints2octs((9, 1, 65)) + assert encoder.encode(univ.Real('-inf')) == bytes((9, 1, 65)) def testZero(self): - assert encoder.encode(univ.Real(0)) == ints2octs((9, 0)) + assert encoder.encode(univ.Real(0)) == bytes((9, 0)) class RealEncoderWithSchemaTestCase(BaseTestCase): def testChar(self): assert encoder.encode( (123, 10, 11), asn1Spec=univ.Real() - ) == ints2octs((9, 7, 3, 49, 50, 51, 69, 49, 49)) + ) == bytes((9, 7, 3, 49, 50, 51, 69, 49, 49)) class UniversalStringEncoderTestCase(BaseTestCase): def testEncoding(self): - assert encoder.encode(char.UniversalString(sys.version_info[0] >= 3 and 'abc' or unicode('abc'))) == ints2octs( + assert encoder.encode(char.UniversalString('abc')) == bytes( (28, 12, 0, 0, 0, 97, 0, 0, 0, 98, 0, 0, 0, 99)), 'Incorrect encoding' class UniversalStringEncoderWithSchemaTestCase(BaseTestCase): def testEncoding(self): assert encoder.encode( - sys.version_info[0] >= 3 and 'abc' or unicode('abc'), asn1Spec=char.UniversalString() - ) == ints2octs((28, 12, 0, 0, 0, 97, 0, 0, 0, 98, 0, 0, 0, 99)), 'Incorrect encoding' + 'abc', asn1Spec=char.UniversalString() + ) == bytes((28, 12, 0, 0, 0, 97, 0, 0, 0, 98, 0, 0, 0, 99)), 'Incorrect encoding' class BMPStringEncoderTestCase(BaseTestCase): def testEncoding(self): - assert encoder.encode(char.BMPString(sys.version_info[0] >= 3 and 'abc' or unicode('abc'))) == ints2octs( + assert encoder.encode(char.BMPString('abc')) == bytes( (30, 6, 0, 97, 0, 98, 0, 99)), 'Incorrect encoding' class BMPStringEncoderWithSchemaTestCase(BaseTestCase): def testEncoding(self): assert encoder.encode( - sys.version_info[0] >= 3 and 'abc' or unicode('abc'), asn1Spec=char.BMPString() - ) == ints2octs((30, 6, 0, 97, 0, 98, 0, 99)), 'Incorrect encoding' + 'abc', asn1Spec=char.BMPString() + ) == bytes((30, 6, 0, 97, 0, 98, 0, 99)), 'Incorrect encoding' class UTF8StringEncoderTestCase(BaseTestCase): def testEncoding(self): - assert encoder.encode(char.UTF8String(sys.version_info[0] >= 3 and 'abc' or unicode('abc'))) == ints2octs( + assert encoder.encode(char.UTF8String('abc')) == bytes( (12, 3, 97, 98, 99)), 'Incorrect encoding' class UTF8StringEncoderWithSchemaTestCase(BaseTestCase): def testEncoding(self): assert encoder.encode( - sys.version_info[0] >= 3 and 'abc' or unicode('abc'), asn1Spec=char.UTF8String() - ) == ints2octs((12, 3, 97, 98, 99)), 'Incorrect encoding' + 'abc', asn1Spec=char.UTF8String() + ) == bytes((12, 3, 97, 98, 99)), 'Incorrect encoding' class SequenceOfEncoderTestCase(BaseTestCase): def testEmpty(self): s = univ.SequenceOf() s.clear() - assert encoder.encode(s) == ints2octs((48, 0)) + assert encoder.encode(s) == bytes((48, 0)) def testDefMode(self): s = univ.SequenceOf() s.setComponentByPosition(0, univ.OctetString('quick brown')) - assert encoder.encode(s) == ints2octs((48, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) + assert encoder.encode(s) == bytes((48, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) def testIndefMode(self): s = univ.SequenceOf() s.setComponentByPosition(0, univ.OctetString('quick brown')) assert encoder.encode( s, defMode=False - ) == ints2octs((48, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0)) + ) == bytes((48, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0)) def testDefModeChunked(self): s = univ.SequenceOf() s.setComponentByPosition(0, univ.OctetString('quick brown')) assert encoder.encode( s, defMode=True, maxChunkSize=4 - ) == ints2octs((48, 19, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110)) + ) == bytes((48, 19, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110)) def testIndefModeChunked(self): s = univ.SequenceOf() s.setComponentByPosition(0, univ.OctetString('quick brown')) assert encoder.encode( s, defMode=False, maxChunkSize=4 - ) == ints2octs((48, 128, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 0, 0)) + ) == bytes((48, 128, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 0, 0)) class SequenceOfEncoderWithSchemaTestCase(BaseTestCase): @@ -538,27 +537,27 @@ class SequenceOfEncoderWithSchemaTestCase(BaseTestCase): self.v = ['quick brown'] def testEmpty(self): - assert encoder.encode([], asn1Spec=self.s) == ints2octs((48, 0)) + assert encoder.encode([], asn1Spec=self.s) == bytes((48, 0)) def testDefMode(self): assert encoder.encode( self.v, asn1Spec=self.s - ) == ints2octs((48, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) + ) == bytes((48, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) def testIndefMode(self): assert encoder.encode( self.v, asn1Spec=self.s, defMode=False - ) == ints2octs((48, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0)) + ) == bytes((48, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0)) def testDefModeChunked(self): assert encoder.encode( self.v, asn1Spec=self.s, defMode=True, maxChunkSize=4 - ) == ints2octs((48, 19, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110)) + ) == bytes((48, 19, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110)) def testIndefModeChunked(self): assert encoder.encode( self.v, asn1Spec=self.s, defMode=False, maxChunkSize=4 - ) == ints2octs((48, 128, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 0, 0)) + ) == bytes((48, 128, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 0, 0)) class SequenceOfEncoderWithComponentsSchemaTestCase(BaseTestCase): @@ -572,58 +571,58 @@ class SequenceOfEncoderWithComponentsSchemaTestCase(BaseTestCase): def testDefMode(self): self.__init() - assert encoder.encode(self.s) == ints2octs((48, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) + assert encoder.encode(self.s) == bytes((48, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) def testIndefMode(self): self.__init() assert encoder.encode( self.s, defMode=False - ) == ints2octs((48, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0)) + ) == bytes((48, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0)) def testDefModeChunked(self): self.__init() assert encoder.encode( self.s, defMode=True, maxChunkSize=4 - ) == ints2octs((48, 19, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110)) + ) == bytes((48, 19, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110)) def testIndefModeChunked(self): self.__init() assert encoder.encode( self.s, defMode=False, maxChunkSize=4 - ) == ints2octs((48, 128, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 0, 0)) + ) == bytes((48, 128, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 0, 0)) class SetOfEncoderTestCase(BaseTestCase): def testEmpty(self): s = univ.SetOf() s.clear() - assert encoder.encode(s) == ints2octs((49, 0)) + assert encoder.encode(s) == bytes((49, 0)) def testDefMode(self): s = univ.SetOf() s.setComponentByPosition(0, univ.OctetString('quick brown')) - assert encoder.encode(s) == ints2octs((49, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) + assert encoder.encode(s) == bytes((49, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) def testIndefMode(self): s = univ.SetOf() s.setComponentByPosition(0, univ.OctetString('quick brown')) assert encoder.encode( s, defMode=False - ) == ints2octs((49, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0)) + ) == bytes((49, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0)) def testDefModeChunked(self): s = univ.SetOf() s.setComponentByPosition(0, univ.OctetString('quick brown')) assert encoder.encode( s, defMode=True, maxChunkSize=4 - ) == ints2octs((49, 19, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110)) + ) == bytes((49, 19, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110)) def testIndefModeChunked(self): s = univ.SetOf() s.setComponentByPosition(0, univ.OctetString('quick brown')) assert encoder.encode( s, defMode=False, maxChunkSize=4 - ) == ints2octs((49, 128, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 0, 0)) + ) == bytes((49, 128, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 0, 0)) class SetOfEncoderWithSchemaTestCase(BaseTestCase): @@ -634,27 +633,27 @@ class SetOfEncoderWithSchemaTestCase(BaseTestCase): def testEmpty(self): s = univ.SetOf() - assert encoder.encode([], asn1Spec=self.s) == ints2octs((49, 0)) + assert encoder.encode([], asn1Spec=self.s) == bytes((49, 0)) def testDefMode(self): assert encoder.encode( self.v, asn1Spec=self.s - ) == ints2octs((49, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) + ) == bytes((49, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) def testIndefMode(self): assert encoder.encode( self.v, asn1Spec=self.s, defMode=False - ) == ints2octs((49, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0)) + ) == bytes((49, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0)) def testDefModeChunked(self): assert encoder.encode( self.v, asn1Spec=self.s, defMode=True, maxChunkSize=4 - ) == ints2octs((49, 19, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110)) + ) == bytes((49, 19, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110)) def testIndefModeChunked(self): assert encoder.encode( self.v, asn1Spec=self.s, defMode=False, maxChunkSize=4 - ) == ints2octs( + ) == bytes( (49, 128, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 0, 0)) @@ -669,25 +668,25 @@ class SetOfEncoderWithComponentsSchemaTestCase(BaseTestCase): def testDefMode(self): self.__init() - assert encoder.encode(self.s) == ints2octs((49, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) + assert encoder.encode(self.s) == bytes((49, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) def testIndefMode(self): self.__init() assert encoder.encode( self.s, defMode=False - ) == ints2octs((49, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0)) + ) == bytes((49, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0)) def testDefModeChunked(self): self.__init() assert encoder.encode( self.s, defMode=True, maxChunkSize=4 - ) == ints2octs((49, 19, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110)) + ) == bytes((49, 19, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110)) def testIndefModeChunked(self): self.__init() assert encoder.encode( self.s, defMode=False, maxChunkSize=4 - ) == ints2octs((49, 128, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 0, 0)) + ) == bytes((49, 128, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 0, 0)) class SequenceEncoderTestCase(BaseTestCase): @@ -699,22 +698,22 @@ class SequenceEncoderTestCase(BaseTestCase): self.s.setComponentByPosition(2, univ.Integer(1)) def testDefMode(self): - assert encoder.encode(self.s) == ints2octs((48, 18, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)) + assert encoder.encode(self.s) == bytes((48, 18, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)) def testIndefMode(self): assert encoder.encode( self.s, defMode=False - ) == ints2octs((48, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1, 0, 0)) + ) == bytes((48, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1, 0, 0)) def testDefModeChunked(self): assert encoder.encode( self.s, defMode=True, maxChunkSize=4 - ) == ints2octs((48, 24, 5, 0, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 2, 1, 1)) + ) == bytes((48, 24, 5, 0, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 2, 1, 1)) def testIndefModeChunked(self): assert encoder.encode( self.s, defMode=False, maxChunkSize=4 - ) == ints2octs((48, 128, 5, 0, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)) + ) == bytes((48, 128, 5, 0, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)) class SequenceEncoderWithSchemaTestCase(BaseTestCase): @@ -746,22 +745,22 @@ class SequenceEncoderWithSchemaTestCase(BaseTestCase): def testDefMode(self): assert encoder.encode( self.v, asn1Spec=self.s - ) == ints2octs((48, 18, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)) + ) == bytes((48, 18, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)) def testIndefMode(self): assert encoder.encode( self.v, asn1Spec=self.s, defMode=False - ) == ints2octs((48, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1, 0, 0)) + ) == bytes((48, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1, 0, 0)) def testDefModeChunked(self): assert encoder.encode( self.v, asn1Spec=self.s, defMode=True, maxChunkSize=4 - ) == ints2octs((48, 24, 5, 0, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 2, 1, 1)) + ) == bytes((48, 24, 5, 0, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 2, 1, 1)) def testIndefModeChunked(self): assert encoder.encode( self.v, asn1Spec=self.s, defMode=False, maxChunkSize=4 - ) == ints2octs((48, 128, 5, 0, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)) + ) == bytes((48, 128, 5, 0, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)) class SequenceEncoderWithUntaggedOpenTypesTestCase(BaseTestCase): @@ -786,7 +785,7 @@ class SequenceEncoderWithUntaggedOpenTypesTestCase(BaseTestCase): self.s[0] = 1 self.s[1] = univ.Integer(12) - assert encoder.encode(self.s, asn1Spec=self.s) == ints2octs( + assert encoder.encode(self.s, asn1Spec=self.s) == bytes( (48, 5, 2, 1, 1, 49, 50) ) @@ -796,7 +795,7 @@ class SequenceEncoderWithUntaggedOpenTypesTestCase(BaseTestCase): self.s[0] = 2 self.s[1] = univ.OctetString('quick brown') - assert encoder.encode(self.s, asn1Spec=self.s) == ints2octs( + assert encoder.encode(self.s, asn1Spec=self.s) == bytes( (48, 14, 2, 1, 2, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110) ) @@ -847,7 +846,7 @@ class SequenceEncoderWithImplicitlyTaggedOpenTypesTestCase(BaseTestCase): self.s[0] = 1 self.s[1] = univ.Integer(12) - assert encoder.encode(self.s, asn1Spec=self.s) == ints2octs( + assert encoder.encode(self.s, asn1Spec=self.s) == bytes( (48, 9, 2, 1, 1, 131, 4, 131, 2, 49, 50) ) @@ -874,7 +873,7 @@ class SequenceEncoderWithExplicitlyTaggedOpenTypesTestCase(BaseTestCase): self.s[0] = 1 self.s[1] = univ.Integer(12) - assert encoder.encode(self.s, asn1Spec=self.s) == ints2octs( + assert encoder.encode(self.s, asn1Spec=self.s) == bytes( (48, 9, 2, 1, 1, 163, 4, 163, 2, 49, 50) ) @@ -902,7 +901,7 @@ class SequenceEncoderWithUntaggedSetOfOpenTypesTestCase(BaseTestCase): self.s[0] = 1 self.s[1].append(univ.Integer(12)) - assert encoder.encode(self.s, asn1Spec=self.s) == ints2octs( + assert encoder.encode(self.s, asn1Spec=self.s) == bytes( (48, 7, 2, 1, 1, 49, 2, 49, 50) ) @@ -912,7 +911,7 @@ class SequenceEncoderWithUntaggedSetOfOpenTypesTestCase(BaseTestCase): self.s[0] = 2 self.s[1].append(univ.OctetString('quick brown')) - assert encoder.encode(self.s, asn1Spec=self.s) == ints2octs( + assert encoder.encode(self.s, asn1Spec=self.s) == bytes( (48, 16, 2, 1, 2, 49, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110) ) @@ -968,7 +967,7 @@ class SequenceEncoderWithImplicitlyTaggedSetOfOpenTypesTestCase(BaseTestCase): self.s[0] = 1 self.s[1].append(univ.Integer(12)) - assert encoder.encode(self.s, asn1Spec=self.s) == ints2octs( + assert encoder.encode(self.s, asn1Spec=self.s) == bytes( (48, 11, 2, 1, 1, 49, 6, 131, 4, 131, 2, 49, 50) ) @@ -998,7 +997,7 @@ class SequenceEncoderWithExplicitlyTaggedSetOfOpenTypesTestCase(BaseTestCase): self.s[0] = 1 self.s[1].append(univ.Integer(12)) - assert encoder.encode(self.s, asn1Spec=self.s) == ints2octs( + assert encoder.encode(self.s, asn1Spec=self.s) == bytes( (48, 11, 2, 1, 1, 49, 6, 163, 4, 163, 2, 49, 50) ) @@ -1036,95 +1035,95 @@ class SequenceEncoderWithComponentsSchemaTestCase(BaseTestCase): def testDefMode(self): self.__init() - assert encoder.encode(self.s) == ints2octs((48, 2, 5, 0)) + assert encoder.encode(self.s) == bytes((48, 2, 5, 0)) def testIndefMode(self): self.__init() assert encoder.encode( self.s, defMode=False - ) == ints2octs((48, 128, 5, 0, 0, 0)) + ) == bytes((48, 128, 5, 0, 0, 0)) def testDefModeChunked(self): self.__init() assert encoder.encode( self.s, defMode=True, maxChunkSize=4 - ) == ints2octs((48, 2, 5, 0)) + ) == bytes((48, 2, 5, 0)) def testIndefModeChunked(self): self.__init() assert encoder.encode( self.s, defMode=False, maxChunkSize=4 - ) == ints2octs((48, 128, 5, 0, 0, 0)) + ) == bytes((48, 128, 5, 0, 0, 0)) def testWithOptionalDefMode(self): self.__initWithOptional() - assert encoder.encode(self.s) == ints2octs( + assert encoder.encode(self.s) == bytes( (48, 15, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) def testWithOptionalIndefMode(self): self.__initWithOptional() assert encoder.encode( self.s, defMode=False - ) == ints2octs((48, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0)) + ) == bytes((48, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0)) def testWithOptionalDefModeChunked(self): self.__initWithOptional() assert encoder.encode( self.s, defMode=True, maxChunkSize=4 - ) == ints2octs((48, 21, 5, 0, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110)) + ) == bytes((48, 21, 5, 0, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110)) def testWithOptionalIndefModeChunked(self): self.__initWithOptional() assert encoder.encode( self.s, defMode=False, maxChunkSize=4 - ) == ints2octs( + ) == bytes( (48, 128, 5, 0, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 0, 0)) def testWithDefaultedDefMode(self): self.__initWithDefaulted() - assert encoder.encode(self.s) == ints2octs((48, 5, 5, 0, 2, 1, 1)) + assert encoder.encode(self.s) == bytes((48, 5, 5, 0, 2, 1, 1)) def testWithDefaultedIndefMode(self): self.__initWithDefaulted() assert encoder.encode( self.s, defMode=False - ) == ints2octs((48, 128, 5, 0, 2, 1, 1, 0, 0)) + ) == bytes((48, 128, 5, 0, 2, 1, 1, 0, 0)) def testWithDefaultedDefModeChunked(self): self.__initWithDefaulted() assert encoder.encode( self.s, defMode=True, maxChunkSize=4 - ) == ints2octs((48, 5, 5, 0, 2, 1, 1)) + ) == bytes((48, 5, 5, 0, 2, 1, 1)) def testWithDefaultedIndefModeChunked(self): self.__initWithDefaulted() assert encoder.encode( self.s, defMode=False, maxChunkSize=4 - ) == ints2octs((48, 128, 5, 0, 2, 1, 1, 0, 0)) + ) == bytes((48, 128, 5, 0, 2, 1, 1, 0, 0)) def testWithOptionalAndDefaultedDefMode(self): self.__initWithOptionalAndDefaulted() - assert encoder.encode(self.s) == ints2octs( + assert encoder.encode(self.s) == bytes( (48, 18, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)) def testWithOptionalAndDefaultedIndefMode(self): self.__initWithOptionalAndDefaulted() assert encoder.encode( self.s, defMode=False - ) == ints2octs((48, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1, 0, 0)) + ) == bytes((48, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1, 0, 0)) def testWithOptionalAndDefaultedDefModeChunked(self): self.__initWithOptionalAndDefaulted() assert encoder.encode( self.s, defMode=True, maxChunkSize=4 - ) == ints2octs( + ) == bytes( (48, 24, 5, 0, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 2, 1, 1)) def testWithOptionalAndDefaultedIndefModeChunked(self): self.__initWithOptionalAndDefaulted() assert encoder.encode( self.s, defMode=False, maxChunkSize=4 - ) == ints2octs((48, 128, 5, 0, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, + ) == bytes((48, 128, 5, 0, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)) @@ -1146,12 +1145,12 @@ class ExpTaggedSequenceEncoderTestCase(BaseTestCase): self.s = s def testDefMode(self): - assert encoder.encode(self.s) == ints2octs((101, 5, 48, 3, 2, 1, 12)) + assert encoder.encode(self.s) == bytes((101, 5, 48, 3, 2, 1, 12)) def testIndefMode(self): assert encoder.encode( self.s, defMode=False - ) == ints2octs((101, 128, 48, 128, 2, 1, 12, 0, 0, 0, 0)) + ) == bytes((101, 128, 48, 128, 2, 1, 12, 0, 0, 0, 0)) class ExpTaggedSequenceComponentEncoderTestCase(BaseTestCase): @@ -1166,12 +1165,12 @@ class ExpTaggedSequenceComponentEncoderTestCase(BaseTestCase): self.s[0] = True def testDefMode(self): - assert encoder.encode(self.s) == ints2octs((48, 5, 160, 3, 1, 1, 1)) + assert encoder.encode(self.s) == bytes((48, 5, 160, 3, 1, 1, 1)) def testIndefMode(self): assert encoder.encode( self.s, defMode=False - ) == ints2octs((48, 128, 160, 3, 1, 1, 1, 0, 0, 0, 0)) + ) == bytes((48, 128, 160, 3, 1, 1, 1, 0, 0, 0, 0)) class SetEncoderTestCase(BaseTestCase): @@ -1183,22 +1182,22 @@ class SetEncoderTestCase(BaseTestCase): self.s.setComponentByPosition(2, univ.Integer(1)) def testDefMode(self): - assert encoder.encode(self.s) == ints2octs((49, 18, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)) + assert encoder.encode(self.s) == bytes((49, 18, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)) def testIndefMode(self): assert encoder.encode( self.s, defMode=False - ) == ints2octs((49, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1, 0, 0)) + ) == bytes((49, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1, 0, 0)) def testDefModeChunked(self): assert encoder.encode( self.s, defMode=True, maxChunkSize=4 - ) == ints2octs((49, 24, 5, 0, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 2, 1, 1)) + ) == bytes((49, 24, 5, 0, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 2, 1, 1)) def testIndefModeChunked(self): assert encoder.encode( self.s, defMode=False, maxChunkSize=4 - ) == ints2octs((49, 128, 5, 0, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)) + ) == bytes((49, 128, 5, 0, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)) class SetEncoderWithSchemaTestCase(BaseTestCase): @@ -1230,22 +1229,22 @@ class SetEncoderWithSchemaTestCase(BaseTestCase): def testDefMode(self): assert encoder.encode( self.v, asn1Spec=self.s - ) == ints2octs((49, 18, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)) + ) == bytes((49, 18, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)) def testIndefMode(self): assert encoder.encode( self.v, asn1Spec=self.s, defMode=False - ) == ints2octs((49, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1, 0, 0)) + ) == bytes((49, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1, 0, 0)) def testDefModeChunked(self): assert encoder.encode( self.v, asn1Spec=self.s, defMode=True, maxChunkSize=4 - ) == ints2octs((49, 24, 5, 0, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 2, 1, 1)) + ) == bytes((49, 24, 5, 0, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 2, 1, 1)) def testIndefModeChunked(self): assert encoder.encode( self.v, asn1Spec=self.s, defMode=False, maxChunkSize=4 - ) == ints2octs((49, 128, 5, 0, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)) + ) == bytes((49, 128, 5, 0, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)) class SetEncoderWithComponentsSchemaTestCase(BaseTestCase): @@ -1281,95 +1280,95 @@ class SetEncoderWithComponentsSchemaTestCase(BaseTestCase): def testDefMode(self): self.__init() - assert encoder.encode(self.s) == ints2octs((49, 2, 5, 0)) + assert encoder.encode(self.s) == bytes((49, 2, 5, 0)) def testIndefMode(self): self.__init() assert encoder.encode( self.s, defMode=False - ) == ints2octs((49, 128, 5, 0, 0, 0)) + ) == bytes((49, 128, 5, 0, 0, 0)) def testDefModeChunked(self): self.__init() assert encoder.encode( self.s, defMode=True, maxChunkSize=4 - ) == ints2octs((49, 2, 5, 0)) + ) == bytes((49, 2, 5, 0)) def testIndefModeChunked(self): self.__init() assert encoder.encode( self.s, defMode=False, maxChunkSize=4 - ) == ints2octs((49, 128, 5, 0, 0, 0)) + ) == bytes((49, 128, 5, 0, 0, 0)) def testWithOptionalDefMode(self): self.__initWithOptional() - assert encoder.encode(self.s) == ints2octs( + assert encoder.encode(self.s) == bytes( (49, 15, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) def testWithOptionalIndefMode(self): self.__initWithOptional() assert encoder.encode( self.s, defMode=False - ) == ints2octs((49, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0)) + ) == bytes((49, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0)) def testWithOptionalDefModeChunked(self): self.__initWithOptional() assert encoder.encode( self.s, defMode=True, maxChunkSize=4 - ) == ints2octs((49, 21, 5, 0, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110)) + ) == bytes((49, 21, 5, 0, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110)) def testWithOptionalIndefModeChunked(self): self.__initWithOptional() assert encoder.encode( self.s, defMode=False, maxChunkSize=4 - ) == ints2octs( + ) == bytes( (49, 128, 5, 0, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 0, 0)) def testWithDefaultedDefMode(self): self.__initWithDefaulted() - assert encoder.encode(self.s) == ints2octs((49, 5, 5, 0, 2, 1, 1)) + assert encoder.encode(self.s) == bytes((49, 5, 5, 0, 2, 1, 1)) def testWithDefaultedIndefMode(self): self.__initWithDefaulted() assert encoder.encode( self.s, defMode=False - ) == ints2octs((49, 128, 5, 0, 2, 1, 1, 0, 0)) + ) == bytes((49, 128, 5, 0, 2, 1, 1, 0, 0)) def testWithDefaultedDefModeChunked(self): self.__initWithDefaulted() assert encoder.encode( self.s, defMode=True, maxChunkSize=4 - ) == ints2octs((49, 5, 5, 0, 2, 1, 1)) + ) == bytes((49, 5, 5, 0, 2, 1, 1)) def testWithDefaultedIndefModeChunked(self): self.__initWithDefaulted() assert encoder.encode( self.s, defMode=False, maxChunkSize=4 - ) == ints2octs((49, 128, 5, 0, 2, 1, 1, 0, 0)) + ) == bytes((49, 128, 5, 0, 2, 1, 1, 0, 0)) def testWithOptionalAndDefaultedDefMode(self): self.__initWithOptionalAndDefaulted() - assert encoder.encode(self.s) == ints2octs( + assert encoder.encode(self.s) == bytes( (49, 18, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)) def testWithOptionalAndDefaultedIndefMode(self): self.__initWithOptionalAndDefaulted() assert encoder.encode( self.s, defMode=False - ) == ints2octs((49, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1, 0, 0)) + ) == bytes((49, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1, 0, 0)) def testWithOptionalAndDefaultedDefModeChunked(self): self.__initWithOptionalAndDefaulted() assert encoder.encode( self.s, defMode=True, maxChunkSize=4 - ) == ints2octs( + ) == bytes( (49, 24, 5, 0, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 2, 1, 1)) def testWithOptionalAndDefaultedIndefModeChunked(self): self.__initWithOptionalAndDefaulted() assert encoder.encode( self.s, defMode=False, maxChunkSize=4 - ) == ints2octs((49, 128, 5, 0, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)) + ) == bytes((49, 128, 5, 0, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)) class ChoiceEncoderTestCase(BaseTestCase): @@ -1386,33 +1385,33 @@ class ChoiceEncoderTestCase(BaseTestCase): def testDefModeOptionOne(self): s = univ.Choice() s.setComponentByPosition(0, univ.Null('')) - assert encoder.encode(s) == ints2octs((5, 0)) + assert encoder.encode(s) == bytes((5, 0)) def testDefModeOptionTwo(self): s = univ.Choice() s.setComponentByPosition(0, univ.OctetString('quick brown')) - assert encoder.encode(s) == ints2octs((4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) + assert encoder.encode(s) == bytes((4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) def testIndefMode(self): s = univ.Choice() s.setComponentByPosition(0, univ.OctetString('quick brown')) assert encoder.encode( s, defMode=False - ) == ints2octs((4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) + ) == bytes((4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) def testDefModeChunked(self): s = univ.Choice() s.setComponentByPosition(0, univ.OctetString('quick brown')) assert encoder.encode( s, defMode=True, maxChunkSize=4 - ) == ints2octs((36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110)) + ) == bytes((36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110)) def testIndefModeChunked(self): s = univ.Choice() s.setComponentByPosition(0, univ.OctetString('quick brown')) assert encoder.encode( s, defMode=False, maxChunkSize=4 - ) == ints2octs((36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0)) + ) == bytes((36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0)) class ChoiceEncoderWithSchemaTestCase(BaseTestCase): @@ -1432,7 +1431,7 @@ class ChoiceEncoderWithSchemaTestCase(BaseTestCase): def testFilled(self): assert encoder.encode( self.v, asn1Spec=self.s - ) == ints2octs((5, 0)) + ) == bytes((5, 0)) class ChoiceEncoderWithComponentsSchemaTestCase(BaseTestCase): @@ -1456,18 +1455,18 @@ class ChoiceEncoderWithComponentsSchemaTestCase(BaseTestCase): def testFilled(self): self.s.setComponentByPosition(0, univ.Null('')) - assert encoder.encode(self.s) == ints2octs((5, 0)) + assert encoder.encode(self.s) == bytes((5, 0)) def testTagged(self): s = self.s.subtype( explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 4) ) s.setComponentByPosition(0, univ.Null('')) - assert encoder.encode(s) == ints2octs((164, 2, 5, 0)) + assert encoder.encode(s) == bytes((164, 2, 5, 0)) def testUndefLength(self): self.s.setComponentByPosition(2, univ.OctetString('abcdefgh')) - assert encoder.encode(self.s, defMode=False, maxChunkSize=3) == ints2octs( + assert encoder.encode(self.s, defMode=False, maxChunkSize=3) == bytes( (36, 128, 4, 3, 97, 98, 99, 4, 3, 100, 101, 102, 4, 2, 103, 104, 0, 0)) def testTaggedUndefLength(self): @@ -1475,7 +1474,7 @@ class ChoiceEncoderWithComponentsSchemaTestCase(BaseTestCase): explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 4) ) s.setComponentByPosition(2, univ.OctetString('abcdefgh')) - assert encoder.encode(s, defMode=False, maxChunkSize=3) == ints2octs( + assert encoder.encode(s, defMode=False, maxChunkSize=3) == bytes( (164, 128, 36, 128, 4, 3, 97, 98, 99, 4, 3, 100, 101, 102, 4, 2, 103, 104, 0, 0, 0, 0)) @@ -1485,19 +1484,19 @@ class AnyEncoderTestCase(BaseTestCase): self.s = univ.Any(encoder.encode(univ.OctetString('fox'))) def testUntagged(self): - assert encoder.encode(self.s) == ints2octs((4, 3, 102, 111, 120)) + assert encoder.encode(self.s) == bytes((4, 3, 102, 111, 120)) def testTaggedEx(self): s = self.s.subtype( explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 4) ) - assert encoder.encode(s) == ints2octs((164, 5, 4, 3, 102, 111, 120)) + assert encoder.encode(s) == bytes((164, 5, 4, 3, 102, 111, 120)) def testTaggedIm(self): s = self.s.subtype( implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 4) ) - assert encoder.encode(s) == ints2octs((132, 5, 4, 3, 102, 111, 120)) + assert encoder.encode(s) == bytes((132, 5, 4, 3, 102, 111, 120)) class AnyEncoderWithSchemaTestCase(BaseTestCase): @@ -1507,19 +1506,19 @@ class AnyEncoderWithSchemaTestCase(BaseTestCase): self.v = encoder.encode(univ.OctetString('fox')) def testUntagged(self): - assert encoder.encode(self.v, asn1Spec=self.s) == ints2octs((4, 3, 102, 111, 120)) + assert encoder.encode(self.v, asn1Spec=self.s) == bytes((4, 3, 102, 111, 120)) def testTaggedEx(self): s = self.s.subtype( explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 4) ) - assert encoder.encode(self.v, asn1Spec=s) == ints2octs((164, 5, 4, 3, 102, 111, 120)) + assert encoder.encode(self.v, asn1Spec=s) == bytes((164, 5, 4, 3, 102, 111, 120)) def testTaggedIm(self): s = self.s.subtype( implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 4) ) - assert encoder.encode(self.v, asn1Spec=s) == ints2octs((132, 5, 4, 3, 102, 111, 120)) + assert encoder.encode(self.v, asn1Spec=s) == bytes((132, 5, 4, 3, 102, 111, 120)) suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__]) diff --git a/contrib/python/pyasn1/py3/tests/codec/cer/test_decoder.py b/contrib/python/pyasn1/py3/tests/codec/cer/test_decoder.py index fddd36bb57..223d304e83 100644 --- a/contrib/python/pyasn1/py3/tests/codec/cer/test_decoder.py +++ b/contrib/python/pyasn1/py3/tests/codec/cer/test_decoder.py @@ -14,26 +14,25 @@ from pyasn1.type import namedtype from pyasn1.type import opentype from pyasn1.type import univ from pyasn1.codec.cer import decoder -from pyasn1.compat.octets import ints2octs, str2octs, null from pyasn1.error import PyAsn1Error class BooleanDecoderTestCase(BaseTestCase): def testTrue(self): - assert decoder.decode(ints2octs((1, 1, 255))) == (1, null) + assert decoder.decode(bytes((1, 1, 255))) == (1, b'') def testFalse(self): - assert decoder.decode(ints2octs((1, 1, 0))) == (0, null) + assert decoder.decode(bytes((1, 1, 0))) == (0, b'') def testEmpty(self): try: - decoder.decode(ints2octs((1, 0))) + decoder.decode(bytes((1, 0))) except PyAsn1Error: pass def testOverflow(self): try: - decoder.decode(ints2octs((1, 2, 0, 0))) + decoder.decode(bytes((1, 2, 0, 0))) except PyAsn1Error: pass @@ -41,13 +40,13 @@ class BooleanDecoderTestCase(BaseTestCase): class BitStringDecoderTestCase(BaseTestCase): def testShortMode(self): assert decoder.decode( - ints2octs((3, 3, 6, 170, 128)) - ) == (((1, 0) * 5), null) + bytes((3, 3, 6, 170, 128)) + ) == (((1, 0) * 5), b'') def testLongMode(self): assert decoder.decode( - ints2octs((3, 127, 6) + (170,) * 125 + (128,)) - ) == (((1, 0) * 501), null) + bytes((3, 127, 6) + (170,) * 125 + (128,)) + ) == (((1, 0) * 501), b'') # TODO: test failures on short chunked and long unchunked substrate samples @@ -55,13 +54,13 @@ class BitStringDecoderTestCase(BaseTestCase): class OctetStringDecoderTestCase(BaseTestCase): def testShortMode(self): assert decoder.decode( - ints2octs((4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120)), - ) == (str2octs('Quick brown fox'), null) + bytes((4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120)), + ) == (b'Quick brown fox', b'') def testLongMode(self): assert decoder.decode( - ints2octs((36, 128, 4, 130, 3, 232) + (81,) * 1000 + (4, 1, 81, 0, 0)) - ) == (str2octs('Q' * 1001), null) + bytes((36, 128, 4, 130, 3, 232) + (81,) * 1000 + (4, 1, 81, 0, 0)) + ) == (b'Q' * 1001, b'') # TODO: test failures on short chunked and long unchunked substrate samples @@ -82,7 +81,7 @@ class SequenceDecoderWithUntaggedOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesChoiceOne(self): s, r = decoder.decode( - ints2octs((48, 128, 2, 1, 1, 2, 1, 12, 0, 0)), + bytes((48, 128, 2, 1, 1, 2, 1, 12, 0, 0)), asn1Spec=self.s, decodeOpenTypes=True ) @@ -92,7 +91,7 @@ class SequenceDecoderWithUntaggedOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesChoiceTwo(self): s, r = decoder.decode( - ints2octs((48, 128, 2, 1, 2, 4, 11, 113, 117, 105, 99, 107, 32, 98, + bytes((48, 128, 2, 1, 2, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0)), asn1Spec=self.s, decodeOpenTypes=True ) @@ -103,7 +102,7 @@ class SequenceDecoderWithUntaggedOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesUnknownType(self): try: s, r = decoder.decode( - ints2octs((48, 128, 6, 1, 1, 2, 1, 12, 0, 0)), asn1Spec=self.s, + bytes((48, 128, 6, 1, 1, 2, 1, 12, 0, 0)), asn1Spec=self.s, decodeOpenTypes=True ) @@ -115,7 +114,7 @@ class SequenceDecoderWithUntaggedOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesUnknownId(self): s, r = decoder.decode( - ints2octs((48, 128, 2, 1, 3, 6, 1, 12, 0, 0)), asn1Spec=self.s, + bytes((48, 128, 2, 1, 3, 6, 1, 12, 0, 0)), asn1Spec=self.s, decodeOpenTypes=True ) assert not r @@ -124,20 +123,20 @@ class SequenceDecoderWithUntaggedOpenTypesTestCase(BaseTestCase): def testDontDecodeOpenTypesChoiceOne(self): s, r = decoder.decode( - ints2octs((48, 128, 2, 1, 1, 2, 1, 12, 0, 0)), asn1Spec=self.s + bytes((48, 128, 2, 1, 1, 2, 1, 12, 0, 0)), asn1Spec=self.s ) assert not r assert s[0] == 1 - assert s[1] == ints2octs((2, 1, 12)) + assert s[1] == bytes((2, 1, 12)) def testDontDecodeOpenTypesChoiceTwo(self): s, r = decoder.decode( - ints2octs((48, 128, 2, 1, 2, 4, 11, 113, 117, 105, 99, 107, 32, 98, + bytes((48, 128, 2, 1, 2, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0)), asn1Spec=self.s ) assert not r assert s[0] == 2 - assert s[1] == ints2octs((4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) + assert s[1] == bytes((4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) class SequenceDecoderWithImplicitlyTaggedOpenTypesTestCase(BaseTestCase): @@ -158,7 +157,7 @@ class SequenceDecoderWithImplicitlyTaggedOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesChoiceOne(self): s, r = decoder.decode( - ints2octs((48, 128, 2, 1, 1, 163, 128, 2, 1, 12, 0, 0, 0, 0)), + bytes((48, 128, 2, 1, 1, 163, 128, 2, 1, 12, 0, 0, 0, 0)), asn1Spec=self.s, decodeOpenTypes=True ) assert not r @@ -167,7 +166,7 @@ class SequenceDecoderWithImplicitlyTaggedOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesUnknownId(self): s, r = decoder.decode( - ints2octs((48, 128, 2, 1, 3, 163, 128, 2, 1, 12, 0, 0, 0, 0)), + bytes((48, 128, 2, 1, 3, 163, 128, 2, 1, 12, 0, 0, 0, 0)), asn1Spec=self.s, decodeOpenTypes=True ) assert not r @@ -193,7 +192,7 @@ class SequenceDecoderWithExplicitlyTaggedOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesChoiceOne(self): s, r = decoder.decode( - ints2octs((48, 128, 2, 1, 1, 163, 128, 2, 1, 12, 0, 0, 0, 0)), + bytes((48, 128, 2, 1, 1, 163, 128, 2, 1, 12, 0, 0, 0, 0)), asn1Spec=self.s, decodeOpenTypes=True ) assert not r @@ -202,7 +201,7 @@ class SequenceDecoderWithExplicitlyTaggedOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesUnknownId(self): s, r = decoder.decode( - ints2octs((48, 128, 2, 1, 3, 163, 128, 2, 1, 12, 0, 0, 0, 0)), + bytes((48, 128, 2, 1, 3, 163, 128, 2, 1, 12, 0, 0, 0, 0)), asn1Spec=self.s, decodeOpenTypes=True ) assert not r @@ -227,7 +226,7 @@ class SequenceDecoderWithUntaggedSetOfOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesChoiceOne(self): s, r = decoder.decode( - ints2octs((48, 128, 2, 1, 1, 49, 128, 2, 1, 12, 0, 0, 0, 0)), + bytes((48, 128, 2, 1, 1, 49, 128, 2, 1, 12, 0, 0, 0, 0)), asn1Spec=self.s, decodeOpenTypes=True ) assert not r @@ -236,7 +235,7 @@ class SequenceDecoderWithUntaggedSetOfOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesChoiceTwo(self): s, r = decoder.decode( - ints2octs((48, 128, 2, 1, 2, 49, 128, 4, 11, 113, 117, 105, 99, + bytes((48, 128, 2, 1, 2, 49, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 0, 0)), asn1Spec=self.s, decodeOpenTypes=True ) @@ -247,7 +246,7 @@ class SequenceDecoderWithUntaggedSetOfOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesUnknownType(self): try: s, r = decoder.decode( - ints2octs((48, 128, 6, 1, 1, 49, 128, 2, 1, 12, 0, 0, 0, 0)), + bytes((48, 128, 6, 1, 1, 49, 128, 2, 1, 12, 0, 0, 0, 0)), asn1Spec=self.s, decodeOpenTypes=True ) @@ -259,7 +258,7 @@ class SequenceDecoderWithUntaggedSetOfOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesUnknownId(self): s, r = decoder.decode( - ints2octs((48, 128, 2, 1, 3, 49, 128, 2, 1, 12, 0, 0, 0, 0)), + bytes((48, 128, 2, 1, 3, 49, 128, 2, 1, 12, 0, 0, 0, 0)), asn1Spec=self.s, decodeOpenTypes=True ) assert not r @@ -268,21 +267,21 @@ class SequenceDecoderWithUntaggedSetOfOpenTypesTestCase(BaseTestCase): def testDontDecodeOpenTypesChoiceOne(self): s, r = decoder.decode( - ints2octs((48, 128, 2, 1, 1, 49, 128, 2, 1, 12, 0, 0, 0, 0)), + bytes((48, 128, 2, 1, 1, 49, 128, 2, 1, 12, 0, 0, 0, 0)), asn1Spec=self.s ) assert not r assert s[0] == 1 - assert s[1][0] == ints2octs((2, 1, 12)) + assert s[1][0] == bytes((2, 1, 12)) def testDontDecodeOpenTypesChoiceTwo(self): s, r = decoder.decode( - ints2octs((48, 128, 2, 1, 2, 49, 128, 4, 11, 113, 117, 105, 99, 107, 32, + bytes((48, 128, 2, 1, 2, 49, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 0, 0)), asn1Spec=self.s ) assert not r assert s[0] == 2 - assert s[1][0] == ints2octs((4, 11, 113, 117, 105, 99, 107, 32, 98, 114, + assert s[1][0] == bytes((4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) @@ -308,7 +307,7 @@ class SequenceDecoderWithImplicitlyTaggedSetOfOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesChoiceOne(self): s, r = decoder.decode( - ints2octs((48, 10, 2, 1, 1, 49, 5, 131, 3, 2, 1, 12)), + bytes((48, 10, 2, 1, 1, 49, 5, 131, 3, 2, 1, 12)), asn1Spec=self.s, decodeOpenTypes=True ) assert not r @@ -317,7 +316,7 @@ class SequenceDecoderWithImplicitlyTaggedSetOfOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesUnknownId(self): s, r = decoder.decode( - ints2octs((48, 10, 2, 1, 3, 49, 5, 131, 3, 2, 1, 12)), + bytes((48, 10, 2, 1, 3, 49, 5, 131, 3, 2, 1, 12)), asn1Spec=self.s, decodeOpenTypes=True ) assert not r @@ -347,7 +346,7 @@ class SequenceDecoderWithExplicitlyTaggedSetOfOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesChoiceOne(self): s, r = decoder.decode( - ints2octs((48, 10, 2, 1, 1, 49, 5, 131, 3, 2, 1, 12)), + bytes((48, 10, 2, 1, 1, 49, 5, 131, 3, 2, 1, 12)), asn1Spec=self.s, decodeOpenTypes=True ) assert not r @@ -356,7 +355,7 @@ class SequenceDecoderWithExplicitlyTaggedSetOfOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesUnknownId(self): s, r = decoder.decode( - ints2octs( (48, 10, 2, 1, 3, 49, 5, 131, 3, 2, 1, 12)), + bytes( (48, 10, 2, 1, 3, 49, 5, 131, 3, 2, 1, 12)), asn1Spec=self.s, decodeOpenTypes=True ) assert not r diff --git a/contrib/python/pyasn1/py3/tests/codec/cer/test_encoder.py b/contrib/python/pyasn1/py3/tests/codec/cer/test_encoder.py index 680f720c3f..b704cd83f0 100644 --- a/contrib/python/pyasn1/py3/tests/codec/cer/test_encoder.py +++ b/contrib/python/pyasn1/py3/tests/codec/cer/test_encoder.py @@ -15,38 +15,37 @@ from pyasn1.type import opentype from pyasn1.type import univ from pyasn1.type import useful from pyasn1.codec.cer import encoder -from pyasn1.compat.octets import ints2octs from pyasn1.error import PyAsn1Error class BooleanEncoderTestCase(BaseTestCase): def testTrue(self): - assert encoder.encode(univ.Boolean(1)) == ints2octs((1, 1, 255)) + assert encoder.encode(univ.Boolean(1)) == bytes((1, 1, 255)) def testFalse(self): - assert encoder.encode(univ.Boolean(0)) == ints2octs((1, 1, 0)) + assert encoder.encode(univ.Boolean(0)) == bytes((1, 1, 0)) class BitStringEncoderTestCase(BaseTestCase): def testShortMode(self): assert encoder.encode( univ.BitString((1, 0) * 5) - ) == ints2octs((3, 3, 6, 170, 128)) + ) == bytes((3, 3, 6, 170, 128)) def testLongMode(self): - assert encoder.encode(univ.BitString((1, 0) * 501)) == ints2octs((3, 127, 6) + (170,) * 125 + (128,)) + assert encoder.encode(univ.BitString((1, 0) * 501)) == bytes((3, 127, 6) + (170,) * 125 + (128,)) class OctetStringEncoderTestCase(BaseTestCase): def testShortMode(self): assert encoder.encode( univ.OctetString('Quick brown fox') - ) == ints2octs((4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120)) + ) == bytes((4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120)) def testLongMode(self): assert encoder.encode( univ.OctetString('Q' * 1001) - ) == ints2octs((36, 128, 4, 130, 3, 232) + (81,) * 1000 + (4, 1, 81, 0, 0)) + ) == bytes((36, 128, 4, 130, 3, 232) + (81,) * 1000 + (4, 1, 81, 0, 0)) class GeneralizedTimeEncoderTestCase(BaseTestCase): @@ -93,37 +92,37 @@ class GeneralizedTimeEncoderTestCase(BaseTestCase): def testWithSubseconds(self): assert encoder.encode( useful.GeneralizedTime('20170801120112.59Z') - ) == ints2octs((24, 18, 50, 48, 49, 55, 48, 56, 48, 49, 49, 50, 48, 49, 49, 50, 46, 53, 57, 90)) + ) == bytes((24, 18, 50, 48, 49, 55, 48, 56, 48, 49, 49, 50, 48, 49, 49, 50, 46, 53, 57, 90)) def testWithSubsecondsWithZeros(self): assert encoder.encode( useful.GeneralizedTime('20170801120112.099Z') - ) == ints2octs((24, 18, 50, 48, 49, 55, 48, 56, 48, 49, 49, 50, 48, 49, 49, 50, 46, 57, 57, 90)) + ) == bytes((24, 18, 50, 48, 49, 55, 48, 56, 48, 49, 49, 50, 48, 49, 49, 50, 46, 57, 57, 90)) def testWithSubsecondsMax(self): assert encoder.encode( useful.GeneralizedTime('20170801120112.999Z') - ) == ints2octs((24, 19, 50, 48, 49, 55, 48, 56, 48, 49, 49, 50, 48, 49, 49, 50, 46, 57, 57, 57, 90)) + ) == bytes((24, 19, 50, 48, 49, 55, 48, 56, 48, 49, 49, 50, 48, 49, 49, 50, 46, 57, 57, 57, 90)) def testWithSubsecondsMin(self): assert encoder.encode( useful.GeneralizedTime('20170801120112.000Z') - ) == ints2octs((24, 15, 50, 48, 49, 55, 48, 56, 48, 49, 49, 50, 48, 49, 49, 50, 90)) + ) == bytes((24, 15, 50, 48, 49, 55, 48, 56, 48, 49, 49, 50, 48, 49, 49, 50, 90)) def testWithSubsecondsDanglingDot(self): assert encoder.encode( useful.GeneralizedTime('20170801120112.Z') - ) == ints2octs((24, 15, 50, 48, 49, 55, 48, 56, 48, 49, 49, 50, 48, 49, 49, 50, 90)) + ) == bytes((24, 15, 50, 48, 49, 55, 48, 56, 48, 49, 49, 50, 48, 49, 49, 50, 90)) def testWithSeconds(self): assert encoder.encode( useful.GeneralizedTime('20170801120112Z') - ) == ints2octs((24, 15, 50, 48, 49, 55, 48, 56, 48, 49, 49, 50, 48, 49, 49, 50, 90)) + ) == bytes((24, 15, 50, 48, 49, 55, 48, 56, 48, 49, 49, 50, 48, 49, 49, 50, 90)) def testWithMinutes(self): assert encoder.encode( useful.GeneralizedTime('201708011201Z') - ) == ints2octs((24, 13, 50, 48, 49, 55, 48, 56, 48, 49, 49, 50, 48, 49, 90)) + ) == bytes((24, 13, 50, 48, 49, 55, 48, 56, 48, 49, 49, 50, 48, 49, 90)) class UTCTimeEncoderTestCase(BaseTestCase): @@ -141,7 +140,7 @@ class UTCTimeEncoderTestCase(BaseTestCase): try: assert encoder.encode( useful.UTCTime('150501120112') - ) == ints2octs((23, 13, 49, 53, 48, 53, 48, 49, 49, 50, 48, 49, 49, 50, 90)) + ) == bytes((23, 13, 49, 53, 48, 53, 48, 49, 49, 50, 48, 49, 49, 50, 90)) except PyAsn1Error: pass else: @@ -160,43 +159,43 @@ class UTCTimeEncoderTestCase(BaseTestCase): def testWithSeconds(self): assert encoder.encode( useful.UTCTime('990801120112Z') - ) == ints2octs((23, 13, 57, 57, 48, 56, 48, 49, 49, 50, 48, 49, 49, 50, 90)) + ) == bytes((23, 13, 57, 57, 48, 56, 48, 49, 49, 50, 48, 49, 49, 50, 90)) def testWithMinutes(self): assert encoder.encode( useful.UTCTime('9908011201Z') - ) == ints2octs((23, 11, 57, 57, 48, 56, 48, 49, 49, 50, 48, 49, 90)) + ) == bytes((23, 11, 57, 57, 48, 56, 48, 49, 49, 50, 48, 49, 90)) class SequenceOfEncoderTestCase(BaseTestCase): def testEmpty(self): s = univ.SequenceOf() s.clear() - assert encoder.encode(s) == ints2octs((48, 128, 0, 0)) + assert encoder.encode(s) == bytes((48, 128, 0, 0)) def testDefMode1(self): s = univ.SequenceOf() s.append(univ.OctetString('a')) s.append(univ.OctetString('ab')) - assert encoder.encode(s) == ints2octs((48, 128, 4, 1, 97, 4, 2, 97, 98, 0, 0)) + assert encoder.encode(s) == bytes((48, 128, 4, 1, 97, 4, 2, 97, 98, 0, 0)) def testDefMode2(self): s = univ.SequenceOf() s.append(univ.OctetString('ab')) s.append(univ.OctetString('a')) - assert encoder.encode(s) == ints2octs((48, 128, 4, 2, 97, 98, 4, 1, 97, 0, 0)) + assert encoder.encode(s) == bytes((48, 128, 4, 2, 97, 98, 4, 1, 97, 0, 0)) def testDefMode3(self): s = univ.SequenceOf() s.append(univ.OctetString('b')) s.append(univ.OctetString('a')) - assert encoder.encode(s) == ints2octs((48, 128, 4, 1, 98, 4, 1, 97, 0, 0)) + assert encoder.encode(s) == bytes((48, 128, 4, 1, 98, 4, 1, 97, 0, 0)) def testDefMode4(self): s = univ.SequenceOf() s.append(univ.OctetString('a')) s.append(univ.OctetString('b')) - assert encoder.encode(s) == ints2octs((48, 128, 4, 1, 97, 4, 1, 98, 0, 0)) + assert encoder.encode(s) == bytes((48, 128, 4, 1, 97, 4, 1, 98, 0, 0)) class SequenceOfEncoderWithSchemaTestCase(BaseTestCase): @@ -206,62 +205,62 @@ class SequenceOfEncoderWithSchemaTestCase(BaseTestCase): def testEmpty(self): self.s.clear() - assert encoder.encode(self.s) == ints2octs((48, 128, 0, 0)) + assert encoder.encode(self.s) == bytes((48, 128, 0, 0)) def testIndefMode1(self): self.s.clear() self.s.append('a') self.s.append('ab') - assert encoder.encode(self.s) == ints2octs((48, 128, 4, 1, 97, 4, 2, 97, 98, 0, 0)) + assert encoder.encode(self.s) == bytes((48, 128, 4, 1, 97, 4, 2, 97, 98, 0, 0)) def testIndefMode2(self): self.s.clear() self.s.append('ab') self.s.append('a') - assert encoder.encode(self.s) == ints2octs((48, 128, 4, 2, 97, 98, 4, 1, 97, 0, 0)) + assert encoder.encode(self.s) == bytes((48, 128, 4, 2, 97, 98, 4, 1, 97, 0, 0)) def testIndefMode3(self): self.s.clear() self.s.append('b') self.s.append('a') - assert encoder.encode(self.s) == ints2octs((48, 128, 4, 1, 98, 4, 1, 97, 0, 0)) + assert encoder.encode(self.s) == bytes((48, 128, 4, 1, 98, 4, 1, 97, 0, 0)) def testIndefMode4(self): self.s.clear() self.s.append('a') self.s.append('b') - assert encoder.encode(self.s) == ints2octs((48, 128, 4, 1, 97, 4, 1, 98, 0, 0)) + assert encoder.encode(self.s) == bytes((48, 128, 4, 1, 97, 4, 1, 98, 0, 0)) class SetOfEncoderTestCase(BaseTestCase): def testEmpty(self): s = univ.SetOf() s.clear() - assert encoder.encode(s) == ints2octs((49, 128, 0, 0)) + assert encoder.encode(s) == bytes((49, 128, 0, 0)) def testDefMode1(self): s = univ.SetOf() s.append(univ.OctetString('a')) s.append(univ.OctetString('ab')) - assert encoder.encode(s) == ints2octs((49, 128, 4, 1, 97, 4, 2, 97, 98, 0, 0)) + assert encoder.encode(s) == bytes((49, 128, 4, 1, 97, 4, 2, 97, 98, 0, 0)) 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)) + assert encoder.encode(s) == bytes((49, 128, 4, 1, 97, 4, 2, 97, 98, 0, 0)) def testDefMode3(self): s = univ.SetOf() s.append(univ.OctetString('b')) s.append(univ.OctetString('a')) - assert encoder.encode(s) == ints2octs((49, 128, 4, 1, 97, 4, 1, 98, 0, 0)) + assert encoder.encode(s) == bytes((49, 128, 4, 1, 97, 4, 1, 98, 0, 0)) def testDefMode4(self): s = univ.SetOf() s.append(univ.OctetString('a')) s.append(univ.OctetString('b')) - assert encoder.encode(s) == ints2octs((49, 128, 4, 1, 97, 4, 1, 98, 0, 0)) + assert encoder.encode(s) == bytes((49, 128, 4, 1, 97, 4, 1, 98, 0, 0)) class SetOfEncoderWithSchemaTestCase(BaseTestCase): @@ -271,35 +270,35 @@ class SetOfEncoderWithSchemaTestCase(BaseTestCase): def testEmpty(self): self.s.clear() - assert encoder.encode(self.s) == ints2octs((49, 128, 0, 0)) + assert encoder.encode(self.s) == bytes((49, 128, 0, 0)) def testIndefMode1(self): self.s.clear() self.s.append('a') self.s.append('ab') - assert encoder.encode(self.s) == ints2octs((49, 128, 4, 1, 97, 4, 2, 97, 98, 0, 0)) + assert encoder.encode(self.s) == bytes((49, 128, 4, 1, 97, 4, 2, 97, 98, 0, 0)) def testIndefMode2(self): self.s.clear() self.s.append('ab') self.s.append('a') - assert encoder.encode(self.s) == ints2octs((49, 128, 4, 1, 97, 4, 2, 97, 98, 0, 0)) + assert encoder.encode(self.s) == bytes((49, 128, 4, 1, 97, 4, 2, 97, 98, 0, 0)) def testIndefMode3(self): self.s.clear() self.s.append('b') self.s.append('a') - assert encoder.encode(self.s) == ints2octs((49, 128, 4, 1, 97, 4, 1, 98, 0, 0)) + assert encoder.encode(self.s) == bytes((49, 128, 4, 1, 97, 4, 1, 98, 0, 0)) def testIndefMode4(self): self.s.clear() self.s.append('a') self.s.append('b') - assert encoder.encode(self.s) == ints2octs((49, 128, 4, 1, 97, 4, 1, 98, 0, 0)) + assert encoder.encode(self.s) == bytes((49, 128, 4, 1, 97, 4, 1, 98, 0, 0)) class SetEncoderTestCase(BaseTestCase): @@ -311,22 +310,22 @@ class SetEncoderTestCase(BaseTestCase): self.s.setComponentByPosition(2, univ.Integer(1)) def testIndefMode(self): - assert encoder.encode(self.s) == ints2octs((49, 128, 2, 1, 1, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 5, 0, 0, 0)) + assert encoder.encode(self.s) == bytes((49, 128, 2, 1, 1, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 5, 0, 0, 0)) def testWithOptionalIndefMode(self): assert encoder.encode( self.s - ) == ints2octs((49, 128, 2, 1, 1, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 5, 0, 0, 0)) + ) == bytes((49, 128, 2, 1, 1, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 5, 0, 0, 0)) def testWithDefaultedIndefMode(self): assert encoder.encode( self.s - ) == ints2octs((49, 128, 2, 1, 1, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 5, 0, 0, 0)) + ) == bytes((49, 128, 2, 1, 1, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 5, 0, 0, 0)) def testWithOptionalAndDefaultedIndefMode(self): assert encoder.encode( self.s - ) == ints2octs((49, 128, 2, 1, 1, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 5, 0, 0, 0)) + ) == bytes((49, 128, 2, 1, 1, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 5, 0, 0, 0)) class SetEncoderWithSchemaTestCase(BaseTestCase): @@ -360,25 +359,25 @@ class SetEncoderWithSchemaTestCase(BaseTestCase): def testIndefMode(self): self.__init() - assert encoder.encode(self.s) == ints2octs((49, 128, 5, 0, 0, 0)) + assert encoder.encode(self.s) == bytes((49, 128, 5, 0, 0, 0)) def testWithOptionalIndefMode(self): self.__initWithOptional() assert encoder.encode( self.s - ) == ints2octs((49, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 5, 0, 0, 0)) + ) == bytes((49, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 5, 0, 0, 0)) def testWithDefaultedIndefMode(self): self.__initWithDefaulted() assert encoder.encode( self.s - ) == ints2octs((49, 128, 2, 1, 1, 5, 0, 0, 0)) + ) == bytes((49, 128, 2, 1, 1, 5, 0, 0, 0)) def testWithOptionalAndDefaultedIndefMode(self): self.__initWithOptionalAndDefaulted() assert encoder.encode( self.s - ) == ints2octs((49, 128, 2, 1, 1, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 5, 0, 0, 0)) + ) == bytes((49, 128, 2, 1, 1, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 5, 0, 0, 0)) class SetEncoderWithChoiceWithSchemaEncoderTestCase(BaseTestCase): @@ -396,7 +395,7 @@ class SetEncoderWithChoiceWithSchemaEncoderTestCase(BaseTestCase): self.s.setComponentByPosition(0) self.s.setComponentByName('status') self.s.getComponentByName('status').setComponentByPosition(0, 1) - assert encoder.encode(self.s) == ints2octs((49, 128, 1, 1, 255, 5, 0, 0, 0)) + assert encoder.encode(self.s) == bytes((49, 128, 1, 1, 255, 5, 0, 0, 0)) class SetEncoderWithTaggedChoiceEncoderTestCase(BaseTestCase): @@ -419,7 +418,7 @@ class SetEncoderWithTaggedChoiceEncoderTestCase(BaseTestCase): s.setComponentByName('name', 'A') s.getComponentByName('customer').setComponentByName('premium', True) - assert encoder.encode(s) == ints2octs((49, 128, 1, 1, 255, 4, 1, 65, 0, 0)) + assert encoder.encode(s) == bytes((49, 128, 1, 1, 255, 4, 1, 65, 0, 0)) def testWithTaggedChoice(self): @@ -439,7 +438,7 @@ class SetEncoderWithTaggedChoiceEncoderTestCase(BaseTestCase): s.setComponentByName('name', 'A') s.getComponentByName('customer').setComponentByName('premium', True) - assert encoder.encode(s) == ints2octs((49, 128, 4, 1, 65, 167, 128, 1, 1, 255, 0, 0, 0, 0)) + assert encoder.encode(s) == bytes((49, 128, 4, 1, 65, 167, 128, 1, 1, 255, 0, 0, 0, 0)) class SequenceEncoderTestCase(BaseTestCase): @@ -451,22 +450,22 @@ class SequenceEncoderTestCase(BaseTestCase): self.s.setComponentByPosition(2, univ.Integer(1)) def testIndefMode(self): - assert encoder.encode(self.s) == ints2octs((48, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1, 0, 0)) + assert encoder.encode(self.s) == bytes((48, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1, 0, 0)) def testWithOptionalIndefMode(self): assert encoder.encode( self.s - ) == ints2octs((48, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1, 0, 0)) + ) == bytes((48, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1, 0, 0)) def testWithDefaultedIndefMode(self): assert encoder.encode( self.s - ) == ints2octs((48, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1, 0, 0)) + ) == bytes((48, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1, 0, 0)) def testWithOptionalAndDefaultedIndefMode(self): assert encoder.encode( self.s - ) == ints2octs((48, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1, 0, 0)) + ) == bytes((48, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1, 0, 0)) class SequenceEncoderWithSchemaTestCase(BaseTestCase): @@ -502,25 +501,25 @@ class SequenceEncoderWithSchemaTestCase(BaseTestCase): def testIndefMode(self): self.__init() - assert encoder.encode(self.s) == ints2octs((48, 128, 5, 0, 0, 0)) + assert encoder.encode(self.s) == bytes((48, 128, 5, 0, 0, 0)) def testWithOptionalIndefMode(self): self.__initWithOptional() assert encoder.encode( self.s - ) == ints2octs((48, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0)) + ) == bytes((48, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0)) def testWithDefaultedIndefMode(self): self.__initWithDefaulted() assert encoder.encode( self.s - ) == ints2octs((48, 128, 5, 0, 2, 1, 1, 0, 0)) + ) == bytes((48, 128, 5, 0, 2, 1, 1, 0, 0)) def testWithOptionalAndDefaultedIndefMode(self): self.__initWithOptionalAndDefaulted() assert encoder.encode( self.s - ) == ints2octs((48, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1, 0, 0)) + ) == bytes((48, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1, 0, 0)) class SequenceEncoderWithUntaggedOpenTypesTestCase(BaseTestCase): @@ -545,7 +544,7 @@ class SequenceEncoderWithUntaggedOpenTypesTestCase(BaseTestCase): self.s[0] = 1 self.s[1] = univ.Integer(12) - assert encoder.encode(self.s, asn1Spec=self.s) == ints2octs( + assert encoder.encode(self.s, asn1Spec=self.s) == bytes( (48, 128, 2, 1, 1, 49, 50, 0, 0) ) @@ -555,7 +554,7 @@ class SequenceEncoderWithUntaggedOpenTypesTestCase(BaseTestCase): self.s[0] = 2 self.s[1] = univ.OctetString('quick brown') - assert encoder.encode(self.s, asn1Spec=self.s) == ints2octs( + assert encoder.encode(self.s, asn1Spec=self.s) == bytes( (48, 128, 2, 1, 2, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0) ) @@ -607,7 +606,7 @@ class SequenceEncoderWithImplicitlyTaggedOpenTypesTestCase(BaseTestCase): self.s[0] = 1 self.s[1] = univ.Integer(12) - assert encoder.encode(self.s, asn1Spec=self.s) == ints2octs( + assert encoder.encode(self.s, asn1Spec=self.s) == bytes( (48, 128, 2, 1, 1, 163, 128, 163, 128, 49, 50, 0, 0, 0, 0, 0, 0) ) @@ -634,7 +633,7 @@ class SequenceEncoderWithExplicitlyTaggedOpenTypesTestCase(BaseTestCase): self.s[0] = 1 self.s[1] = univ.Integer(12) - assert encoder.encode(self.s, asn1Spec=self.s) == ints2octs( + assert encoder.encode(self.s, asn1Spec=self.s) == bytes( (48, 128, 2, 1, 1, 163, 128, 163, 128, 49, 50, 0, 0, 0, 0, 0, 0) ) @@ -662,7 +661,7 @@ class SequenceEncoderWithUntaggedSetOfOpenTypesTestCase(BaseTestCase): self.s[0] = 1 self.s[1].append(univ.Integer(12)) - assert encoder.encode(self.s, asn1Spec=self.s) == ints2octs( + assert encoder.encode(self.s, asn1Spec=self.s) == bytes( (48, 128, 2, 1, 1, 49, 128, 49, 50, 0, 0, 0, 0) ) @@ -672,7 +671,7 @@ class SequenceEncoderWithUntaggedSetOfOpenTypesTestCase(BaseTestCase): self.s[0] = 2 self.s[1].append(univ.OctetString('quick brown')) - assert encoder.encode(self.s, asn1Spec=self.s) == ints2octs( + assert encoder.encode(self.s, asn1Spec=self.s) == bytes( (48, 128, 2, 1, 2, 49, 128, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 0, 0) ) @@ -728,7 +727,7 @@ class SequenceEncoderWithImplicitlyTaggedSetOfOpenTypesTestCase(BaseTestCase): self.s[0] = 1 self.s[1].append(univ.Integer(12)) - assert encoder.encode(self.s, asn1Spec=self.s) == ints2octs( + assert encoder.encode(self.s, asn1Spec=self.s) == bytes( (48, 128, 2, 1, 1, 49, 128, 163, 128, 163, 128, 49, 50, 0, 0, 0, 0, 0, 0, 0, 0) ) @@ -759,7 +758,7 @@ class SequenceEncoderWithExplicitlyTaggedSetOfOpenTypesTestCase(BaseTestCase): self.s[0] = 1 self.s[1].append(univ.Integer(12)) - assert encoder.encode(self.s, asn1Spec=self.s) == ints2octs( + assert encoder.encode(self.s, asn1Spec=self.s) == bytes( (48, 128, 2, 1, 1, 49, 128, 163, 128, 163, 128, 49, 50, 0, 0, 0, 0, 0, 0, 0, 0) ) @@ -828,31 +827,31 @@ class NestedOptionalSequenceEncoderTestCase(BaseTestCase): def testOptionalWithDefaultAndOptional(self): s = self.__initOptionalWithDefaultAndOptional() - assert encoder.encode(s) == ints2octs((48, 128, 48, 128, 4, 4, 116, 101, 115, 116, 2, 1, 123, 0, 0, 0, 0)) + assert encoder.encode(s) == bytes((48, 128, 48, 128, 4, 4, 116, 101, 115, 116, 2, 1, 123, 0, 0, 0, 0)) def testOptionalWithDefault(self): s = self.__initOptionalWithDefault() - assert encoder.encode(s) == ints2octs((48, 128, 48, 128, 2, 1, 123, 0, 0, 0, 0)) + assert encoder.encode(s) == bytes((48, 128, 48, 128, 2, 1, 123, 0, 0, 0, 0)) def testOptionalWithOptional(self): s = self.__initOptionalWithOptional() - assert encoder.encode(s) == ints2octs((48, 128, 48, 128, 4, 4, 116, 101, 115, 116, 0, 0, 0, 0)) + assert encoder.encode(s) == bytes((48, 128, 48, 128, 4, 4, 116, 101, 115, 116, 0, 0, 0, 0)) def testOptional(self): s = self.__initOptional() - assert encoder.encode(s) == ints2octs((48, 128, 0, 0)) + assert encoder.encode(s) == bytes((48, 128, 0, 0)) def testDefaultWithDefaultAndOptional(self): s = self.__initDefaultWithDefaultAndOptional() - assert encoder.encode(s) == ints2octs((48, 128, 48, 128, 4, 4, 116, 101, 115, 116, 2, 1, 123, 0, 0, 0, 0)) + assert encoder.encode(s) == bytes((48, 128, 48, 128, 4, 4, 116, 101, 115, 116, 2, 1, 123, 0, 0, 0, 0)) def testDefaultWithDefault(self): s = self.__initDefaultWithDefault() - assert encoder.encode(s) == ints2octs((48, 128, 48, 128, 4, 4, 116, 101, 115, 116, 0, 0, 0, 0)) + assert encoder.encode(s) == bytes((48, 128, 48, 128, 4, 4, 116, 101, 115, 116, 0, 0, 0, 0)) def testDefaultWithOptional(self): s = self.__initDefaultWithOptional() - assert encoder.encode(s) == ints2octs((48, 128, 48, 128, 2, 1, 123, 0, 0, 0, 0)) + assert encoder.encode(s) == bytes((48, 128, 48, 128, 2, 1, 123, 0, 0, 0, 0)) class NestedOptionalChoiceEncoderTestCase(BaseTestCase): @@ -902,19 +901,19 @@ class NestedOptionalChoiceEncoderTestCase(BaseTestCase): def testOptionalWithDefaultAndOptional(self): s = self.__initOptionalWithDefaultAndOptional() - assert encoder.encode(s) == ints2octs((48, 128, 48, 128, 4, 4, 116, 101, 115, 116, 2, 1, 123, 0, 0, 0, 0)) + assert encoder.encode(s) == bytes((48, 128, 48, 128, 4, 4, 116, 101, 115, 116, 2, 1, 123, 0, 0, 0, 0)) def testOptionalWithDefault(self): s = self.__initOptionalWithDefault() - assert encoder.encode(s) == ints2octs((48, 128, 48, 128, 2, 1, 123, 0, 0, 0, 0)) + assert encoder.encode(s) == bytes((48, 128, 48, 128, 2, 1, 123, 0, 0, 0, 0)) def testOptionalWithOptional(self): s = self.__initOptionalWithOptional() - assert encoder.encode(s) == ints2octs((48, 128, 48, 128, 4, 4, 116, 101, 115, 116, 0, 0, 0, 0)) + assert encoder.encode(s) == bytes((48, 128, 48, 128, 4, 4, 116, 101, 115, 116, 0, 0, 0, 0)) def testOptional(self): s = self.__initOptional() - assert encoder.encode(s) == ints2octs((48, 128, 0, 0)) + assert encoder.encode(s) == bytes((48, 128, 0, 0)) class NestedOptionalSequenceOfEncoderTestCase(BaseTestCase): @@ -943,11 +942,11 @@ class NestedOptionalSequenceOfEncoderTestCase(BaseTestCase): def testOptionalWithValue(self): s = self.__initOptionalWithValue() - assert encoder.encode(s) == ints2octs((48, 128, 48, 128, 4, 4, 116, 101, 115, 116, 0, 0, 0, 0)) + assert encoder.encode(s) == bytes((48, 128, 48, 128, 4, 4, 116, 101, 115, 116, 0, 0, 0, 0)) def testOptional(self): s = self.__initOptional() - assert encoder.encode(s) == ints2octs((48, 128, 0, 0)) + assert encoder.encode(s) == bytes((48, 128, 0, 0)) suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__]) diff --git a/contrib/python/pyasn1/py3/tests/codec/der/test_decoder.py b/contrib/python/pyasn1/py3/tests/codec/der/test_decoder.py index 5f61408317..d44b8d1828 100644 --- a/contrib/python/pyasn1/py3/tests/codec/der/test_decoder.py +++ b/contrib/python/pyasn1/py3/tests/codec/der/test_decoder.py @@ -14,20 +14,19 @@ from pyasn1.type import namedtype from pyasn1.type import opentype from pyasn1.type import univ from pyasn1.codec.der import decoder -from pyasn1.compat.octets import ints2octs, null from pyasn1.error import PyAsn1Error class BitStringDecoderTestCase(BaseTestCase): def testShortMode(self): assert decoder.decode( - ints2octs((3, 127, 6) + (170,) * 125 + (128,)) - ) == (((1, 0) * 501), null) + bytes((3, 127, 6) + (170,) * 125 + (128,)) + ) == (((1, 0) * 501), b'') def testIndefMode(self): try: decoder.decode( - ints2octs((35, 128, 3, 2, 0, 169, 3, 2, 1, 138, 0, 0)) + bytes((35, 128, 3, 2, 0, 169, 3, 2, 1, 138, 0, 0)) ) except PyAsn1Error: pass @@ -37,7 +36,7 @@ class BitStringDecoderTestCase(BaseTestCase): def testDefModeChunked(self): try: assert decoder.decode( - ints2octs((35, 8, 3, 2, 0, 169, 3, 2, 1, 138)) + bytes((35, 8, 3, 2, 0, 169, 3, 2, 1, 138)) ) except PyAsn1Error: pass @@ -54,7 +53,7 @@ class OctetStringDecoderTestCase(BaseTestCase): def testIndefMode(self): try: decoder.decode( - ints2octs((36, 128, 4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 0, 0)) + bytes((36, 128, 4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 0, 0)) ) except PyAsn1Error: pass @@ -64,7 +63,7 @@ class OctetStringDecoderTestCase(BaseTestCase): def testChunkedMode(self): try: decoder.decode( - ints2octs((36, 23, 4, 2, 81, 117, 4, 2, 105, 99, 4, 2, 107, 32, 4, 2, 98, 114, 4, 2, 111, 119, 4, 1, 110)) + bytes((36, 23, 4, 2, 81, 117, 4, 2, 105, 99, 4, 2, 107, 32, 4, 2, 98, 114, 4, 2, 111, 119, 4, 1, 110)) ) except PyAsn1Error: pass @@ -88,7 +87,7 @@ class SequenceDecoderWithUntaggedOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesChoiceOne(self): s, r = decoder.decode( - ints2octs((48, 6, 2, 1, 1, 2, 1, 12)), asn1Spec=self.s, + bytes((48, 6, 2, 1, 1, 2, 1, 12)), asn1Spec=self.s, decodeOpenTypes=True ) assert not r @@ -97,7 +96,7 @@ class SequenceDecoderWithUntaggedOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesChoiceTwo(self): s, r = decoder.decode( - ints2octs((48, 16, 2, 1, 2, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)), asn1Spec=self.s, + bytes((48, 16, 2, 1, 2, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)), asn1Spec=self.s, decodeOpenTypes=True ) assert not r @@ -107,7 +106,7 @@ class SequenceDecoderWithUntaggedOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesUnknownType(self): try: s, r = decoder.decode( - ints2octs((48, 6, 2, 1, 2, 6, 1, 39)), asn1Spec=self.s, + bytes((48, 6, 2, 1, 2, 6, 1, 39)), asn1Spec=self.s, decodeOpenTypes=True ) @@ -119,7 +118,7 @@ class SequenceDecoderWithUntaggedOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesUnknownId(self): s, r = decoder.decode( - ints2octs((48, 6, 2, 1, 3, 6, 1, 39)), asn1Spec=self.s, + bytes((48, 6, 2, 1, 3, 6, 1, 39)), asn1Spec=self.s, decodeOpenTypes=True ) assert not r @@ -128,19 +127,19 @@ class SequenceDecoderWithUntaggedOpenTypesTestCase(BaseTestCase): def testDontDecodeOpenTypesChoiceOne(self): s, r = decoder.decode( - ints2octs((48, 6, 2, 1, 1, 2, 1, 12)), asn1Spec=self.s + bytes((48, 6, 2, 1, 1, 2, 1, 12)), asn1Spec=self.s ) assert not r assert s[0] == 1 - assert s[1] == ints2octs((2, 1, 12)) + assert s[1] == bytes((2, 1, 12)) def testDontDecodeOpenTypesChoiceTwo(self): s, r = decoder.decode( - ints2octs((48, 16, 2, 1, 2, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)), asn1Spec=self.s + bytes((48, 16, 2, 1, 2, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)), asn1Spec=self.s ) assert not r assert s[0] == 2 - assert s[1] == ints2octs((4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) + assert s[1] == bytes((4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) class SequenceDecoderWithImplicitlyTaggedOpenTypesTestCase(BaseTestCase): @@ -161,7 +160,7 @@ class SequenceDecoderWithImplicitlyTaggedOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesChoiceOne(self): s, r = decoder.decode( - ints2octs((48, 8, 2, 1, 1, 131, 3, 2, 1, 12)), asn1Spec=self.s, decodeOpenTypes=True + bytes((48, 8, 2, 1, 1, 131, 3, 2, 1, 12)), asn1Spec=self.s, decodeOpenTypes=True ) assert not r assert s[0] == 1 @@ -169,7 +168,7 @@ class SequenceDecoderWithImplicitlyTaggedOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesUnknownId(self): s, r = decoder.decode( - ints2octs((48, 8, 2, 1, 3, 131, 3, 2, 1, 12)), asn1Spec=self.s, decodeOpenTypes=True + bytes((48, 8, 2, 1, 3, 131, 3, 2, 1, 12)), asn1Spec=self.s, decodeOpenTypes=True ) assert not r assert s[0] == 3 @@ -194,7 +193,7 @@ class SequenceDecoderWithExplicitlyTaggedOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesChoiceOne(self): s, r = decoder.decode( - ints2octs((48, 8, 2, 1, 1, 163, 3, 2, 1, 12)), asn1Spec=self.s, decodeOpenTypes=True + bytes((48, 8, 2, 1, 1, 163, 3, 2, 1, 12)), asn1Spec=self.s, decodeOpenTypes=True ) assert not r assert s[0] == 1 @@ -202,7 +201,7 @@ class SequenceDecoderWithExplicitlyTaggedOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesUnknownId(self): s, r = decoder.decode( - ints2octs((48, 8, 2, 1, 3, 163, 3, 2, 1, 12)), asn1Spec=self.s, decodeOpenTypes=True + bytes((48, 8, 2, 1, 3, 163, 3, 2, 1, 12)), asn1Spec=self.s, decodeOpenTypes=True ) assert not r assert s[0] == 3 @@ -226,7 +225,7 @@ class SequenceDecoderWithUnaggedSetOfOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesChoiceOne(self): s, r = decoder.decode( - ints2octs((48, 8, 2, 1, 1, 49, 3, 2, 1, 12)), asn1Spec=self.s, + bytes((48, 8, 2, 1, 1, 49, 3, 2, 1, 12)), asn1Spec=self.s, decodeOpenTypes=True ) assert not r @@ -235,7 +234,7 @@ class SequenceDecoderWithUnaggedSetOfOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesChoiceTwo(self): s, r = decoder.decode( - ints2octs((48, 18, 2, 1, 2, 49, 13, 4, 11, 113, 117, 105, 99, + bytes((48, 18, 2, 1, 2, 49, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)), asn1Spec=self.s, decodeOpenTypes=True ) @@ -246,7 +245,7 @@ class SequenceDecoderWithUnaggedSetOfOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesUnknownType(self): try: s, r = decoder.decode( - ints2octs((48, 6, 2, 1, 2, 6, 1, 39)), asn1Spec=self.s, + bytes((48, 6, 2, 1, 2, 6, 1, 39)), asn1Spec=self.s, decodeOpenTypes=True ) @@ -258,7 +257,7 @@ class SequenceDecoderWithUnaggedSetOfOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesUnknownId(self): s, r = decoder.decode( - ints2octs((48, 8, 2, 1, 3, 49, 3, 2, 1, 12)), asn1Spec=self.s, + bytes((48, 8, 2, 1, 3, 49, 3, 2, 1, 12)), asn1Spec=self.s, decodeOpenTypes=True ) assert not r @@ -267,20 +266,20 @@ class SequenceDecoderWithUnaggedSetOfOpenTypesTestCase(BaseTestCase): def testDontDecodeOpenTypesChoiceOne(self): s, r = decoder.decode( - ints2octs((48, 8, 2, 1, 1, 49, 3, 2, 1, 12)), asn1Spec=self.s + bytes((48, 8, 2, 1, 1, 49, 3, 2, 1, 12)), asn1Spec=self.s ) assert not r assert s[0] == 1 - assert s[1][0] == ints2octs((2, 1, 12)) + assert s[1][0] == bytes((2, 1, 12)) def testDontDecodeOpenTypesChoiceTwo(self): s, r = decoder.decode( - ints2octs((48, 18, 2, 1, 2, 49, 13, 4, 11, 113, 117, 105, 99, + bytes((48, 18, 2, 1, 2, 49, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)), asn1Spec=self.s ) assert not r assert s[0] == 2 - assert s[1][0] == ints2octs((4, 11, 113, 117, 105, 99, 107, 32, 98, 114, + assert s[1][0] == bytes((4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) @@ -306,7 +305,7 @@ class SequenceDecoderWithImplicitlyTaggedSetOfOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesChoiceOne(self): s, r = decoder.decode( - ints2octs((48, 10, 2, 1, 1, 49, 5, 131, 3, 2, 1, 12)), + bytes((48, 10, 2, 1, 1, 49, 5, 131, 3, 2, 1, 12)), asn1Spec=self.s, decodeOpenTypes=True ) assert not r @@ -315,7 +314,7 @@ class SequenceDecoderWithImplicitlyTaggedSetOfOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesUnknownId(self): s, r = decoder.decode( - ints2octs((48, 10, 2, 1, 3, 49, 5, 131, 3, 2, 1, 12)), + bytes((48, 10, 2, 1, 3, 49, 5, 131, 3, 2, 1, 12)), asn1Spec=self.s, decodeOpenTypes=True ) assert not r @@ -345,7 +344,7 @@ class SequenceDecoderWithExplicitlyTaggedSetOfOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesChoiceOne(self): s, r = decoder.decode( - ints2octs((48, 10, 2, 1, 1, 49, 5, 131, 3, 2, 1, 12)), + bytes((48, 10, 2, 1, 1, 49, 5, 131, 3, 2, 1, 12)), asn1Spec=self.s, decodeOpenTypes=True ) assert not r @@ -354,7 +353,7 @@ class SequenceDecoderWithExplicitlyTaggedSetOfOpenTypesTestCase(BaseTestCase): def testDecodeOpenTypesUnknownId(self): s, r = decoder.decode( - ints2octs( (48, 10, 2, 1, 3, 49, 5, 131, 3, 2, 1, 12)), + bytes( (48, 10, 2, 1, 3, 49, 5, 131, 3, 2, 1, 12)), asn1Spec=self.s, decodeOpenTypes=True ) assert not r diff --git a/contrib/python/pyasn1/py3/tests/codec/der/test_encoder.py b/contrib/python/pyasn1/py3/tests/codec/der/test_encoder.py index 6500396115..90d7a7d8eb 100644 --- a/contrib/python/pyasn1/py3/tests/codec/der/test_encoder.py +++ b/contrib/python/pyasn1/py3/tests/codec/der/test_encoder.py @@ -9,36 +9,36 @@ import unittest from __tests__.base import BaseTestCase +from pyasn1.error import PyAsn1Error from pyasn1.type import tag from pyasn1.type import namedtype from pyasn1.type import opentype from pyasn1.type import univ from pyasn1.codec.der import encoder -from pyasn1.compat.octets import ints2octs class OctetStringEncoderTestCase(BaseTestCase): def testDefModeShort(self): assert encoder.encode( univ.OctetString('Quick brown fox') - ) == ints2octs((4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120)) + ) == bytes((4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120)) def testDefModeLong(self): assert encoder.encode( univ.OctetString('Q' * 10000) - ) == ints2octs((4, 130, 39, 16) + (81,) * 10000) + ) == bytes((4, 130, 39, 16) + (81,) * 10000) class BitStringEncoderTestCase(BaseTestCase): def testDefModeShort(self): assert encoder.encode( univ.BitString((1,)) - ) == ints2octs((3, 2, 7, 128)) + ) == bytes((3, 2, 7, 128)) def testDefModeLong(self): assert encoder.encode( univ.BitString((1,) * 80000) - ) == ints2octs((3, 130, 39, 17, 0) + (255,) * 10000) + ) == bytes((3, 130, 39, 17, 0) + (255,) * 10000) class SetOfEncoderTestCase(BaseTestCase): @@ -52,28 +52,28 @@ class SetOfEncoderTestCase(BaseTestCase): self.s.append('a') self.s.append('ab') - assert encoder.encode(self.s) == ints2octs((49, 7, 4, 1, 97, 4, 2, 97, 98)) + assert encoder.encode(self.s) == bytes((49, 7, 4, 1, 97, 4, 2, 97, 98)) def testDefMode2(self): self.s.clear() self.s.append('ab') self.s.append('a') - assert encoder.encode(self.s) == ints2octs((49, 7, 4, 1, 97, 4, 2, 97, 98)) + assert encoder.encode(self.s) == bytes((49, 7, 4, 1, 97, 4, 2, 97, 98)) def testDefMode3(self): self.s.clear() self.s.append('b') self.s.append('a') - assert encoder.encode(self.s) == ints2octs((49, 6, 4, 1, 97, 4, 1, 98)) + assert encoder.encode(self.s) == bytes((49, 6, 4, 1, 97, 4, 1, 98)) def testDefMode4(self): self.s.clear() self.s.append('a') self.s.append('b') - assert encoder.encode(self.s) == ints2octs((49, 6, 4, 1, 97, 4, 1, 98)) + assert encoder.encode(self.s) == bytes((49, 6, 4, 1, 97, 4, 1, 98)) class SetWithAlternatingChoiceEncoderTestCase(BaseTestCase): @@ -93,12 +93,12 @@ class SetWithAlternatingChoiceEncoderTestCase(BaseTestCase): def testComponentsOrdering1(self): self.s.setComponentByName('status') self.s.getComponentByName('status').setComponentByPosition(0, 'A') - assert encoder.encode(self.s) == ints2octs((49, 6, 2, 1, 5, 4, 1, 65)) + assert encoder.encode(self.s) == bytes((49, 6, 2, 1, 5, 4, 1, 65)) def testComponentsOrdering2(self): self.s.setComponentByName('status') self.s.getComponentByName('status').setComponentByPosition(1, True) - assert encoder.encode(self.s) == ints2octs((49, 6, 1, 1, 255, 2, 1, 5)) + assert encoder.encode(self.s) == bytes((49, 6, 1, 1, 255, 2, 1, 5)) class SetWithTaggedChoiceEncoderTestCase(BaseTestCase): @@ -121,7 +121,7 @@ class SetWithTaggedChoiceEncoderTestCase(BaseTestCase): s.setComponentByName('name', 'A') s.getComponentByName('customer').setComponentByName('premium', True) - assert encoder.encode(s) == ints2octs((49, 6, 1, 1, 255, 4, 1, 65)) + assert encoder.encode(s) == bytes((49, 6, 1, 1, 255, 4, 1, 65)) def testWithTaggedChoice(self): @@ -141,7 +141,7 @@ class SetWithTaggedChoiceEncoderTestCase(BaseTestCase): s.setComponentByName('name', 'A') s.getComponentByName('customer').setComponentByName('premium', True) - assert encoder.encode(s) == ints2octs((49, 8, 4, 1, 65, 167, 3, 1, 1, 255)) + assert encoder.encode(s) == bytes((49, 8, 4, 1, 65, 167, 3, 1, 1, 255)) class SequenceEncoderWithUntaggedOpenTypesTestCase(BaseTestCase): @@ -166,7 +166,7 @@ class SequenceEncoderWithUntaggedOpenTypesTestCase(BaseTestCase): self.s[0] = 1 self.s[1] = univ.Integer(12) - assert encoder.encode(self.s, asn1Spec=self.s) == ints2octs( + assert encoder.encode(self.s, asn1Spec=self.s) == bytes( (48, 5, 2, 1, 1, 49, 50) ) @@ -176,7 +176,7 @@ class SequenceEncoderWithUntaggedOpenTypesTestCase(BaseTestCase): self.s[0] = 2 self.s[1] = univ.OctetString('quick brown') - assert encoder.encode(self.s, asn1Spec=self.s) == ints2octs( + assert encoder.encode(self.s, asn1Spec=self.s) == bytes( (48, 14, 2, 1, 2, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110) ) @@ -228,7 +228,7 @@ class SequenceEncoderWithImplicitlyTaggedOpenTypesTestCase(BaseTestCase): self.s[0] = 1 self.s[1] = univ.Integer(12) - assert encoder.encode(self.s, asn1Spec=self.s) == ints2octs( + assert encoder.encode(self.s, asn1Spec=self.s) == bytes( (48, 9, 2, 1, 1, 131, 4, 131, 2, 49, 50) ) @@ -255,7 +255,7 @@ class SequenceEncoderWithExplicitlyTaggedOpenTypesTestCase(BaseTestCase): self.s[0] = 1 self.s[1] = univ.Integer(12) - assert encoder.encode(self.s, asn1Spec=self.s) == ints2octs( + assert encoder.encode(self.s, asn1Spec=self.s) == bytes( (48, 9, 2, 1, 1, 163, 4, 163, 2, 49, 50) ) @@ -283,7 +283,7 @@ class SequenceEncoderWithUntaggedSetOfOpenTypesTestCase(BaseTestCase): self.s[0] = 1 self.s[1].append(univ.Integer(12)) - assert encoder.encode(self.s, asn1Spec=self.s) == ints2octs( + assert encoder.encode(self.s, asn1Spec=self.s) == bytes( (48, 7, 2, 1, 1, 49, 2, 49, 50) ) @@ -293,7 +293,7 @@ class SequenceEncoderWithUntaggedSetOfOpenTypesTestCase(BaseTestCase): self.s[0] = 2 self.s[1].append(univ.OctetString('quick brown')) - assert encoder.encode(self.s, asn1Spec=self.s) == ints2octs( + assert encoder.encode(self.s, asn1Spec=self.s) == bytes( (48, 16, 2, 1, 2, 49, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110) ) @@ -349,7 +349,7 @@ class SequenceEncoderWithImplicitlyTaggedSetOfOpenTypesTestCase(BaseTestCase): self.s[0] = 1 self.s[1].append(univ.Integer(12)) - assert encoder.encode(self.s, asn1Spec=self.s) == ints2octs( + assert encoder.encode(self.s, asn1Spec=self.s) == bytes( (48, 11, 2, 1, 1, 49, 6, 131, 4, 131, 2, 49, 50) ) @@ -379,7 +379,7 @@ class SequenceEncoderWithExplicitlyTaggedSetOfOpenTypesTestCase(BaseTestCase): self.s[0] = 1 self.s[1].append(univ.Integer(12)) - assert encoder.encode(self.s, asn1Spec=self.s) == ints2octs( + assert encoder.encode(self.s, asn1Spec=self.s) == bytes( (48, 11, 2, 1, 1, 49, 6, 163, 4, 163, 2, 49, 50) ) @@ -448,31 +448,31 @@ class NestedOptionalSequenceEncoderTestCase(BaseTestCase): def testDefModeOptionalWithDefaultAndOptional(self): s = self.__initOptionalWithDefaultAndOptional() - assert encoder.encode(s) == ints2octs((48, 11, 48, 9, 4, 4, 116, 101, 115, 116, 2, 1, 123)) + assert encoder.encode(s) == bytes((48, 11, 48, 9, 4, 4, 116, 101, 115, 116, 2, 1, 123)) def testDefModeOptionalWithDefault(self): s = self.__initOptionalWithDefault() - assert encoder.encode(s) == ints2octs((48, 5, 48, 3, 2, 1, 123)) + assert encoder.encode(s) == bytes((48, 5, 48, 3, 2, 1, 123)) def testDefModeOptionalWithOptional(self): s = self.__initOptionalWithOptional() - assert encoder.encode(s) == ints2octs((48, 8, 48, 6, 4, 4, 116, 101, 115, 116)) + assert encoder.encode(s) == bytes((48, 8, 48, 6, 4, 4, 116, 101, 115, 116)) def testDefModeOptional(self): s = self.__initOptional() - assert encoder.encode(s) == ints2octs((48, 0)) + assert encoder.encode(s) == bytes((48, 0)) def testDefModeDefaultWithDefaultAndOptional(self): s = self.__initDefaultWithDefaultAndOptional() - assert encoder.encode(s) == ints2octs((48, 11, 48, 9, 4, 4, 116, 101, 115, 116, 2, 1, 123)) + assert encoder.encode(s) == bytes((48, 11, 48, 9, 4, 4, 116, 101, 115, 116, 2, 1, 123)) def testDefModeDefaultWithDefault(self): s = self.__initDefaultWithDefault() - assert encoder.encode(s) == ints2octs((48, 8, 48, 6, 4, 4, 116, 101, 115, 116)) + assert encoder.encode(s) == bytes((48, 8, 48, 6, 4, 4, 116, 101, 115, 116)) def testDefModeDefaultWithOptional(self): s = self.__initDefaultWithOptional() - assert encoder.encode(s) == ints2octs((48, 5, 48, 3, 2, 1, 123)) + assert encoder.encode(s) == bytes((48, 5, 48, 3, 2, 1, 123)) class NestedOptionalChoiceEncoderTestCase(BaseTestCase): @@ -523,19 +523,19 @@ class NestedOptionalChoiceEncoderTestCase(BaseTestCase): def testDefModeOptionalWithDefaultAndOptional(self): s = self.__initOptionalWithDefaultAndOptional() - assert encoder.encode(s) == ints2octs((48, 11, 48, 9, 4, 4, 116, 101, 115, 116, 2, 1, 123)) + assert encoder.encode(s) == bytes((48, 11, 48, 9, 4, 4, 116, 101, 115, 116, 2, 1, 123)) def testDefModeOptionalWithDefault(self): s = self.__initOptionalWithDefault() - assert encoder.encode(s) == ints2octs((48, 5, 48, 3, 2, 1, 123)) + assert encoder.encode(s) == bytes((48, 5, 48, 3, 2, 1, 123)) def testDefModeOptionalWithOptional(self): s = self.__initOptionalWithOptional() - assert encoder.encode(s) == ints2octs((48, 8, 48, 6, 4, 4, 116, 101, 115, 116)) + assert encoder.encode(s) == bytes((48, 8, 48, 6, 4, 4, 116, 101, 115, 116)) def testDefModeOptional(self): s = self.__initOptional() - assert encoder.encode(s) == ints2octs((48, 0)) + assert encoder.encode(s) == bytes((48, 0)) class NestedOptionalSequenceOfEncoderTestCase(BaseTestCase): @@ -565,11 +565,11 @@ class NestedOptionalSequenceOfEncoderTestCase(BaseTestCase): def testDefModeOptionalWithValue(self): s = self.__initOptionalWithValue() - assert encoder.encode(s) == ints2octs((48, 8, 48, 6, 4, 4, 116, 101, 115, 116)) + assert encoder.encode(s) == bytes((48, 8, 48, 6, 4, 4, 116, 101, 115, 116)) def testDefModeOptional(self): s = self.__initOptional() - assert encoder.encode(s) == ints2octs((48, 0)) + assert encoder.encode(s) == bytes((48, 0)) class EmptyInnerFieldOfSequenceEncoderTestCase(BaseTestCase): @@ -583,7 +583,7 @@ class EmptyInnerFieldOfSequenceEncoderTestCase(BaseTestCase): self.s.clear() self.s[0] = '' - assert encoder.encode(self.s) == ints2octs((48, 2, 5, 0)) + assert encoder.encode(self.s) == bytes((48, 2, 5, 0)) def testUninitializedOptionalNullIsNotEncoded(self): self.s = univ.Sequence( @@ -593,7 +593,7 @@ class EmptyInnerFieldOfSequenceEncoderTestCase(BaseTestCase): ) self.s.clear() - assert encoder.encode(self.s) == ints2octs((48, 0)) + assert encoder.encode(self.s) == bytes((48, 0)) def testInitializedDefaultNullIsNotEncoded(self): self.s = univ.Sequence( @@ -604,7 +604,7 @@ class EmptyInnerFieldOfSequenceEncoderTestCase(BaseTestCase): self.s.clear() self.s[0] = '' - assert encoder.encode(self.s) == ints2octs((48, 0)) + assert encoder.encode(self.s) == bytes((48, 0)) def testInitializedOptionalOctetStringIsEncoded(self): self.s = univ.Sequence( @@ -615,7 +615,7 @@ class EmptyInnerFieldOfSequenceEncoderTestCase(BaseTestCase): self.s.clear() self.s[0] = '' - assert encoder.encode(self.s) == ints2octs((48, 2, 4, 0)) + assert encoder.encode(self.s) == bytes((48, 2, 4, 0)) def testUninitializedOptionalOctetStringIsNotEncoded(self): self.s = univ.Sequence( @@ -625,7 +625,7 @@ class EmptyInnerFieldOfSequenceEncoderTestCase(BaseTestCase): ) self.s.clear() - assert encoder.encode(self.s) == ints2octs((48, 0)) + assert encoder.encode(self.s) == bytes((48, 0)) def testInitializedDefaultOctetStringIsNotEncoded(self): self.s = univ.Sequence( @@ -636,7 +636,7 @@ class EmptyInnerFieldOfSequenceEncoderTestCase(BaseTestCase): self.s.clear() self.s[0] = '' - assert encoder.encode(self.s) == ints2octs((48, 0)) + assert encoder.encode(self.s) == bytes((48, 0)) class ClassConstructorTestCase(BaseTestCase): diff --git a/contrib/python/pyasn1/py3/tests/codec/native/test_encoder.py b/contrib/python/pyasn1/py3/tests/codec/native/test_encoder.py index 662c284b3c..2ce082e667 100644 --- a/contrib/python/pyasn1/py3/tests/codec/native/test_encoder.py +++ b/contrib/python/pyasn1/py3/tests/codec/native/test_encoder.py @@ -12,7 +12,6 @@ from __tests__.base import BaseTestCase from pyasn1.type import namedtype from pyasn1.type import univ from pyasn1.codec.native import encoder -from pyasn1.compat.octets import str2octs from pyasn1.error import PyAsn1Error @@ -59,7 +58,7 @@ class OctetStringEncoderTestCase(BaseTestCase): self.o = univ.OctetString('Quick brown fox') def testValue(self): - assert encoder.encode(self.o) == str2octs('Quick brown fox') + assert encoder.encode(self.o) == b'Quick brown fox' class NullEncoderTestCase(BaseTestCase): @@ -98,7 +97,7 @@ class SequenceEncoderTestCase(BaseTestCase): s[0] = univ.Null('') s[1] = 'abc' s[2] = 123 - assert encoder.encode(s) == {'place-holder': None, 'first-name': str2octs('abc'), 'age': 123} + assert encoder.encode(s) == {'place-holder': None, 'first-name': b'abc', 'age': 123} class ChoiceEncoderTestCase(BaseTestCase): @@ -132,7 +131,7 @@ class AnyEncoderTestCase(BaseTestCase): self.s = univ.Any(encoder.encode(univ.OctetString('fox'))) def testSimple(self): - assert encoder.encode(self.s) == str2octs('fox') + assert encoder.encode(self.s) == b'fox' suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__]) diff --git a/contrib/python/pyasn1/py3/tests/codec/test_streaming.py b/contrib/python/pyasn1/py3/tests/codec/test_streaming.py index 7dc87257f2..7754e250f9 100644 --- a/contrib/python/pyasn1/py3/tests/codec/test_streaming.py +++ b/contrib/python/pyasn1/py3/tests/codec/test_streaming.py @@ -6,12 +6,7 @@ # import io import sys - -try: - import unittest2 as unittest - -except ImportError: - import unittest +import unittest from __tests__.base import BaseTestCase diff --git a/contrib/python/pyasn1/py3/tests/compat/test_integer.py b/contrib/python/pyasn1/py3/tests/compat/test_integer.py deleted file mode 100644 index 4026b75402..0000000000 --- a/contrib/python/pyasn1/py3/tests/compat/test_integer.py +++ /dev/null @@ -1,49 +0,0 @@ -# -# This file is part of pyasn1 software. -# -# Copyright (c) 2005-2020, Ilya Etingof <etingof@gmail.com> -# License: https://pyasn1.readthedocs.io/en/latest/license.html -# -import sys -import unittest - -from __tests__.base import BaseTestCase - -from pyasn1.compat import integer - - -class IntegerTestCase(BaseTestCase): - - if sys.version_info[0] > 2: - - def test_from_bytes_zero(self): - assert 0 == integer.from_bytes(bytes([0]), signed=False) - - def test_from_bytes_unsigned(self): - assert -66051 == integer.from_bytes(bytes([254, 253, 253]), signed=True) - - def test_from_bytes_signed(self): - assert 66051 == integer.from_bytes(bytes([0, 1, 2, 3]), signed=False) - - def test_from_bytes_empty(self): - assert 0 == integer.from_bytes(bytes([])) - - else: - - def test_from_bytes_zero(self): - assert 0 == integer.from_bytes('\x00', signed=False) - - def test_from_bytes_unsigned(self): - assert -66051 == integer.from_bytes('\xfe\xfd\xfd', signed=True) - - def test_from_bytes_signed(self): - assert 66051 == integer.from_bytes('\x01\x02\x03', signed=False) - - def test_from_bytes_empty(self): - assert 0 == integer.from_bytes('') - - -suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__]) - -if __name__ == '__main__': - unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/contrib/python/pyasn1/py3/tests/compat/test_octets.py b/contrib/python/pyasn1/py3/tests/compat/test_octets.py deleted file mode 100644 index 4133950704..0000000000 --- a/contrib/python/pyasn1/py3/tests/compat/test_octets.py +++ /dev/null @@ -1,113 +0,0 @@ -# -# This file is part of pyasn1 software. -# -# Copyright (c) 2005-2020, Ilya Etingof <etingof@gmail.com> -# License: https://pyasn1.readthedocs.io/en/latest/license.html -# -import sys -import unittest - -from __tests__.base import BaseTestCase - -from pyasn1.compat import octets - - -class OctetsTestCase(BaseTestCase): - - if sys.version_info[0] > 2: - - def test_ints2octs(self): - assert [1, 2, 3] == list(octets.ints2octs([1, 2, 3])) - - def test_ints2octs_empty(self): - assert not octets.ints2octs([]) - - def test_int2oct(self): - assert [12] == list(octets.int2oct(12)) - - def test_octs2ints(self): - assert [1, 2, 3] == list(octets.octs2ints(bytes([1, 2, 3]))) - - def test_octs2ints_empty(self): - assert not octets.octs2ints(bytes([])) - - def test_oct2int(self): - assert 12 == octets.oct2int(bytes([12]))[0] - - def test_str2octs(self): - assert bytes([1, 2, 3]) == octets.str2octs('\x01\x02\x03') - - def test_str2octs_empty(self): - assert not octets.str2octs('') - - def test_octs2str(self): - assert '\x01\x02\x03' == octets.octs2str(bytes([1, 2, 3])) - - def test_octs2str_empty(self): - assert not octets.octs2str(bytes([])) - - def test_isOctetsType(self): - assert octets.isOctetsType('abc') == False - assert octets.isOctetsType(123) == False - assert octets.isOctetsType(bytes()) == True - - def test_isStringType(self): - assert octets.isStringType('abc') == True - assert octets.isStringType(123) == False - assert octets.isStringType(bytes()) == False - - def test_ensureString(self): - assert 'abc'.encode() == octets.ensureString('abc'.encode()) - assert bytes([1, 2, 3]) == octets.ensureString([1, 2, 3]) - - else: - - def test_ints2octs(self): - assert '\x01\x02\x03' == octets.ints2octs([1, 2, 3]) - - def test_ints2octs_empty(self): - assert not octets.ints2octs([]) - - def test_int2oct(self): - assert '\x0c' == octets.int2oct(12) - - def test_octs2ints(self): - assert [1, 2, 3] == octets.octs2ints('\x01\x02\x03') - - def test_octs2ints_empty(self): - assert not octets.octs2ints('') - - def test_oct2int(self): - assert 12 == octets.oct2int('\x0c') - - def test_str2octs(self): - assert '\x01\x02\x03' == octets.str2octs('\x01\x02\x03') - - def test_str2octs_empty(self): - assert not octets.str2octs('') - - def test_octs2str(self): - assert '\x01\x02\x03' == octets.octs2str('\x01\x02\x03') - - def test_octs2str_empty(self): - assert not octets.octs2str('') - - def test_isOctetsType(self): - assert octets.isOctetsType('abc') == True - assert octets.isOctetsType(123) == False - assert octets.isOctetsType(unicode('abc')) == False - - def test_isStringType(self): - assert octets.isStringType('abc') == True - assert octets.isStringType(123) == False - assert octets.isStringType(unicode('abc')) == True - - def test_ensureString(self): - assert 'abc' == octets.ensureString('abc') - assert '123' == octets.ensureString(123) - - -suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__]) - -if __name__ == '__main__': - unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/contrib/python/pyasn1/py3/tests/type/test_char.py b/contrib/python/pyasn1/py3/tests/type/test_char.py index efa179eb0e..02918b8dc3 100644 --- a/contrib/python/pyasn1/py3/tests/type/test_char.py +++ b/contrib/python/pyasn1/py3/tests/type/test_char.py @@ -13,7 +13,6 @@ from __tests__.base import BaseTestCase from pyasn1.type import char from pyasn1.type import univ from pyasn1.type import constraint -from pyasn1.compat.octets import ints2octs from pyasn1.error import PyAsn1Error @@ -26,8 +25,8 @@ class AbstractStringTestCase(object): def setUp(self): BaseTestCase.setUp(self) - self.asn1String = self.asn1Type(ints2octs(self.initializer), encoding=self.encoding) - self.pythonString = ints2octs(self.initializer).decode(self.encoding) + self.asn1String = self.asn1Type(bytes(self.initializer), encoding=self.encoding) + self.pythonString = bytes(self.initializer).decode(self.encoding) def testUnicode(self): assert self.asn1String == self.pythonString, 'unicode init fails' @@ -51,16 +50,10 @@ class AbstractStringTestCase(object): assert False, 'Size constraint failed' def testSerialised(self): - if sys.version_info[0] < 3: - assert str(self.asn1String) == self.pythonString.encode(self.encoding), '__str__() fails' - else: - assert bytes(self.asn1String) == self.pythonString.encode(self.encoding), '__str__() fails' + assert bytes(self.asn1String) == self.pythonString.encode(self.encoding), '__str__() fails' def testPrintable(self): - if sys.version_info[0] < 3: - assert unicode(self.asn1String) == self.pythonString, '__str__() fails' - else: - assert str(self.asn1String) == self.pythonString, '__str__() fails' + assert str(self.asn1String) == self.pythonString, '__str__() fails' def testInit(self): assert self.asn1Type(self.pythonString) == self.pythonString @@ -153,14 +146,10 @@ class BMPStringTestCase(AbstractStringTestCase, BaseTestCase): asn1Type = char.BMPString -if sys.version_info[0] > 2: - - # Somehow comparison of UTF-32 encoded strings does not work in Py2 - - class UniversalStringTestCase(AbstractStringTestCase, BaseTestCase): - initializer = (0, 0, 4, 48, 0, 0, 4, 68) - encoding = 'utf-32-be' - asn1Type = char.UniversalString +class UniversalStringTestCase(AbstractStringTestCase, BaseTestCase): + initializer = (0, 0, 4, 48, 0, 0, 4, 68) + encoding = 'utf-32-be' + asn1Type = char.UniversalString suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__]) diff --git a/contrib/python/pyasn1/py3/tests/type/test_opentype.py b/contrib/python/pyasn1/py3/tests/type/test_opentype.py index 5ae9715f40..e6454d02ed 100644 --- a/contrib/python/pyasn1/py3/tests/type/test_opentype.py +++ b/contrib/python/pyasn1/py3/tests/type/test_opentype.py @@ -13,7 +13,6 @@ from pyasn1.type import univ from pyasn1.type import tag from pyasn1.type import namedtype from pyasn1.type import opentype -from pyasn1.compat.octets import str2octs from pyasn1.error import PyAsn1Error @@ -34,7 +33,7 @@ class UntaggedAnyTestCase(BaseTestCase): self.s.clear() - self.s['blob'] = univ.Any(str2octs('xxx')) + self.s['blob'] = univ.Any(b'xxx') # this should succeed because Any is untagged and unconstrained self.s['blob'] = univ.Integer(123) @@ -90,7 +89,7 @@ class TaggedAnyOpenTypeTestCase(BaseTestCase): self.s.clear() - self.s['blob'] = univ.Any(str2octs('xxx')) + self.s['blob'] = univ.Any(b'xxx') self.s['blob'] = univ.Integer(123) diff --git a/contrib/python/pyasn1/py3/tests/type/test_univ.py b/contrib/python/pyasn1/py3/tests/type/test_univ.py index 16b3d61465..82c7b68f02 100644 --- a/contrib/python/pyasn1/py3/tests/type/test_univ.py +++ b/contrib/python/pyasn1/py3/tests/type/test_univ.py @@ -18,7 +18,6 @@ from pyasn1.type import constraint from pyasn1.type import namedtype from pyasn1.type import namedval from pyasn1.type import error -from pyasn1.compat.octets import str2octs, ints2octs, octs2ints, octs2str from pyasn1.error import PyAsn1Error from pyasn1.error import PyAsn1UnicodeEncodeError, PyAsn1UnicodeDecodeError @@ -200,25 +199,17 @@ class IntegerTestCase(BaseTestCase): def testDivInt(self): assert univ.Integer(4) / 2 == 2, '__div__() fails' - if sys.version_info[0] > 2: - def testDivFloat(self): - assert univ.Integer(3) / 2 == 1.5, '__div__() fails' + def testDivFloat(self): + assert univ.Integer(3) / 2 == 1.5, '__div__() fails' - def testRdivFloat(self): - assert 3 / univ.Integer(2) == 1.5, '__rdiv__() fails' - else: - def testDivFloat(self): - assert univ.Integer(3) / 2 == 1, '__div__() fails' - - def testRdivFloat(self): - assert 3 / univ.Integer(2) == 1, '__rdiv__() fails' + def testRdivFloat(self): + assert 3 / univ.Integer(2) == 1.5, '__rdiv__() fails' def testRdivInt(self): assert 6 / univ.Integer(3) == 2, '__rdiv__() fails' - if sys.version_info[0] > 2: - def testTrueDiv(self): - assert univ.Integer(3) / univ.Integer(2) == 1.5, '__truediv__() fails' + def testTrueDiv(self): + assert univ.Integer(3) / univ.Integer(2) == 1.5, '__truediv__() fails' def testFloorDiv(self): assert univ.Integer(3) // univ.Integer(2) == 1, '__floordiv__() fails' @@ -430,7 +421,7 @@ class BitStringTestCase(BaseTestCase): assert list(reversed(univ.BitString([0, 0, 1]))) == list(univ.BitString([1, 0, 0])) def testAsOctets(self): - assert self.b.clone(hexValue='A98A').asOctets() == ints2octs((0xa9, 0x8a)), 'testAsOctets() fails' + assert self.b.clone(hexValue='A98A').asOctets() == bytes((0xa9, 0x8a)), 'testAsOctets() fails' def testAsInts(self): assert self.b.clone(hexValue='A98A').asNumbers() == (0xa9, 0x8a), 'testAsNumbers() fails' @@ -474,9 +465,9 @@ class OctetStringWithUnicodeMixIn(object): encoding = 'us-ascii' def setUp(self): - self.pythonString = ints2octs(self.initializer).decode(self.encoding) + self.pythonString = bytes(self.initializer).decode(self.encoding) self.encodedPythonString = self.pythonString.encode(self.encoding) - self.numbersString = tuple(octs2ints(self.encodedPythonString)) + self.numbersString = tuple(self.encodedPythonString) def testInit(self): assert univ.OctetString(self.encodedPythonString) == self.encodedPythonString, '__init__() fails' @@ -486,17 +477,10 @@ class OctetStringWithUnicodeMixIn(object): assert univ.OctetString(univ.Integer(123)) == univ.OctetString('123') def testSerialised(self): - if sys.version_info[0] < 3: - assert str(univ.OctetString(self.encodedPythonString, encoding=self.encoding)) == self.encodedPythonString, '__str__() fails' - else: - assert bytes(univ.OctetString(self.encodedPythonString, encoding=self.encoding)) == self.encodedPythonString, '__str__() fails' + assert bytes(univ.OctetString(self.encodedPythonString, encoding=self.encoding)) == self.encodedPythonString, '__str__() fails' def testPrintable(self): - if sys.version_info[0] < 3: - assert str(univ.OctetString(self.encodedPythonString, encoding=self.encoding)) == self.encodedPythonString, '__str__() fails' - assert unicode(univ.OctetString(self.pythonString, encoding=self.encoding)) == self.pythonString, 'unicode init fails' - else: - assert str(univ.OctetString(self.pythonString, encoding=self.encoding)) == self.pythonString, 'unicode init fails' + assert str(univ.OctetString(self.pythonString, encoding=self.encoding)) == self.pythonString, 'unicode init fails' def testSeq(self): assert univ.OctetString(self.encodedPythonString)[0] == self.encodedPythonString[0], '__getitem__() fails' @@ -538,13 +522,9 @@ class OctetStringWithAsciiTestCase(OctetStringWithUnicodeMixIn, BaseTestCase): class OctetStringUnicodeErrorTestCase(BaseTestCase): def testEncodeError(self): - serialized = ints2octs((0xff, 0xfe)) - - if sys.version_info < (3, 0): - text = serialized.decode('iso-8859-1') + serialized = bytes((0xff, 0xfe)) - else: - text = octs2str(serialized) + text = serialized.decode('iso-8859-1') try: univ.OctetString(text, encoding='us-ascii') @@ -553,16 +533,12 @@ class OctetStringUnicodeErrorTestCase(BaseTestCase): pass def testDecodeError(self): - serialized = ints2octs((0xff, 0xfe)) + serialized = bytes((0xff, 0xfe)) octetString = univ.OctetString(serialized, encoding='us-ascii') try: - if sys.version_info < (3, 0): - unicode(octetString) - - else: - str(octetString) + str(octetString) except PyAsn1UnicodeDecodeError: pass @@ -578,13 +554,9 @@ class OctetStringWithUtf16TestCase(OctetStringWithUnicodeMixIn, BaseTestCase): encoding = 'utf-16-be' -if sys.version_info[0] > 2: - - # Somehow comparison of UTF-32 encoded strings does not work in Py2 - - class OctetStringWithUtf32TestCase(OctetStringWithUnicodeMixIn, BaseTestCase): - initializer = (0, 0, 4, 48, 0, 0, 4, 49, 0, 0, 4, 50) - encoding = 'utf-32-be' +class OctetStringWithUtf32TestCase(OctetStringWithUnicodeMixIn, BaseTestCase): + initializer = (0, 0, 4, 48, 0, 0, 4, 49, 0, 0, 4, 50) + encoding = 'utf-32-be' class OctetStringTestCase(BaseTestCase): @@ -604,13 +576,13 @@ class OctetStringTestCase(BaseTestCase): assert HexDefault() == univ.OctetString(hexValue='FA9823C43E43510DE3422') def testBinStr(self): - assert univ.OctetString(binValue="1000010111101110101111000000111011") == ints2octs((133, 238, 188, 14, 192)), 'bin init fails' + assert univ.OctetString(binValue="1000010111101110101111000000111011") == bytes((133, 238, 188, 14, 192)), 'bin init fails' def testHexStr(self): - assert univ.OctetString(hexValue="FA9823C43E43510DE3422") == ints2octs((250, 152, 35, 196, 62, 67, 81, 13, 227, 66, 32)), 'hex init fails' + assert univ.OctetString(hexValue="FA9823C43E43510DE3422") == bytes((250, 152, 35, 196, 62, 67, 81, 13, 227, 66, 32)), 'hex init fails' def testTuple(self): - assert univ.OctetString((1, 2, 3, 4, 5)) == ints2octs((1, 2, 3, 4, 5)), 'tuple init failed' + assert univ.OctetString((1, 2, 3, 4, 5)) == bytes((1, 2, 3, 4, 5)), 'tuple init failed' def testRepr(self): assert 'abc' in repr(univ.OctetString('abc')) @@ -634,7 +606,7 @@ class OctetStringTestCase(BaseTestCase): class OctetString(univ.OctetString): pass - assert OctetString(hexValue="FA9823C43E43510DE3422") == ints2octs((250, 152, 35, 196, 62, 67, 81, 13, 227, 66, 32)) + assert OctetString(hexValue="FA9823C43E43510DE3422") == bytes((250, 152, 35, 196, 62, 67, 81, 13, 227, 66, 32)) class OctetStringPicklingTestCase(unittest.TestCase): @@ -659,10 +631,10 @@ class Null(BaseTestCase): def testInit(self): assert not univ.Null().isValue - assert univ.Null(0) == str2octs('') - assert univ.Null(False) == str2octs('') - assert univ.Null('') == str2octs('') - assert univ.Null(None) == str2octs('') + assert univ.Null(0) == b'' + assert univ.Null(False) == b'' + assert univ.Null('') == b'' + assert univ.Null(None) == b'' try: assert univ.Null(True) @@ -908,8 +880,6 @@ class ObjectIdentifier(BaseTestCase): def testUnicode(self): s = '1.3.6' - if sys.version_info[0] < 3: - s = s.decode() assert univ.ObjectIdentifier(s) == (1, 3, 6), 'unicode init fails' def testTag(self): @@ -985,8 +955,6 @@ class RelativeOID(BaseTestCase): def testUnicode(self): s = '1.3.6' - if sys.version_info[0] < 3: - s = s.decode() assert univ.RelativeOID(s) == (1, 3, 6), 'unicode init fails' def testTag(self): @@ -1045,9 +1013,9 @@ class SequenceOf(BaseTestCase): def testSeq(self): self.s1.setComponentByPosition(0, univ.OctetString('abc')) - assert self.s1[0] == str2octs('abc'), 'set by idx fails' + assert self.s1[0] == b'abc', 'set by idx fails' self.s1[0] = 'cba' - assert self.s1[0] == str2octs('cba'), 'set by idx fails' + assert self.s1[0] == b'cba', 'set by idx fails' def testCmp(self): self.s1.clear() @@ -1059,11 +1027,11 @@ class SequenceOf(BaseTestCase): def testSubtypeSpec(self): s = self.s1.clone( componentType=univ.OctetString().subtype( - subtypeSpec=constraint.SingleValueConstraint(str2octs('abc')))) + subtypeSpec=constraint.SingleValueConstraint(b'abc'))) try: s.setComponentByPosition( 0, univ.OctetString().subtype( - 'abc', subtypeSpec=constraint.SingleValueConstraint(str2octs('abc')))) + 'abc', subtypeSpec=constraint.SingleValueConstraint(b'abc'))) except PyAsn1Error: assert 0, 'constraint fails' try: @@ -1091,7 +1059,7 @@ class SequenceOf(BaseTestCase): def testComponentConstraintsMatching(self): s = self.s1.clone() o = univ.OctetString().subtype( - subtypeSpec=constraint.ConstraintsUnion(constraint.SingleValueConstraint(str2octs('cba')))) + subtypeSpec=constraint.ConstraintsUnion(constraint.SingleValueConstraint(b'cba'))) s.strictConstraints = True # This requires types equality try: s.setComponentByPosition(0, o.clone('cba')) @@ -1159,25 +1127,25 @@ class SequenceOf(BaseTestCase): def testGetItemSlice(self): s = self.s1.clone() s.extend(['xxx', 'yyy', 'zzz']) - assert s[:1] == [str2octs('xxx')] - assert s[-2:] == [str2octs('yyy'), str2octs('zzz')] - assert s[1:2] == [str2octs('yyy')] + assert s[:1] == [b'xxx'] + assert s[-2:] == [b'yyy', b'zzz'] + assert s[1:2] == [b'yyy'] def testSetItem(self): s = self.s1.clone() s.append('xxx') s[2] = 'yyy' assert len(s) == 3 - assert s[1] == str2octs('') + assert s[1] == b'' def testSetItemSlice(self): s = self.s1.clone() s[:1] = ['xxx'] - assert s == [str2octs('xxx')] + assert s == [b'xxx'] s[-2:] = ['yyy', 'zzz'] - assert s == [str2octs('yyy'), str2octs('zzz')] + assert s == [b'yyy', b'zzz'] s[1:2] = ['yyy'] - assert s == [str2octs('yyy'), str2octs('yyy')] + assert s == [b'yyy', b'yyy'] assert len(s) == 2 def testAppend(self): @@ -1186,7 +1154,7 @@ class SequenceOf(BaseTestCase): assert len(self.s1) == 1 self.s1.append('def') assert len(self.s1) == 2 - assert list(self.s1) == [str2octs(x) for x in ['abc', 'def']] + assert list(self.s1) == [b'abc', b'def'] def testExtend(self): self.s1.clear() @@ -1194,31 +1162,31 @@ class SequenceOf(BaseTestCase): assert len(self.s1) == 1 self.s1.extend(['def', 'ghi']) assert len(self.s1) == 3 - assert list(self.s1) == [str2octs(x) for x in ['abc', 'def', 'ghi']] + assert list(self.s1) == [b'abc', b'def', b'ghi'] def testCount(self): self.s1.clear() for x in ['abc', 'def', 'abc']: self.s1.append(x) - assert self.s1.count(str2octs('abc')) == 2 - assert self.s1.count(str2octs('def')) == 1 - assert self.s1.count(str2octs('ghi')) == 0 + assert self.s1.count(b'abc') == 2 + assert self.s1.count(b'def') == 1 + assert self.s1.count(b'ghi') == 0 def testIndex(self): self.s1.clear() for x in ['abc', 'def', 'abc']: self.s1.append(x) - assert self.s1.index(str2octs('abc')) == 0 - assert self.s1.index(str2octs('def')) == 1 - assert self.s1.index(str2octs('abc'), 1) == 2 + assert self.s1.index(b'abc') == 0 + assert self.s1.index(b'def') == 1 + assert self.s1.index(b'abc', 1) == 2 def testSort(self): self.s1.clear() self.s1[0] = 'b' self.s1[1] = 'a' - assert list(self.s1) == [str2octs('b'), str2octs('a')] + assert list(self.s1) == [b'b', b'a'] self.s1.sort() - assert list(self.s1) == [str2octs('a'), str2octs('b')] + assert list(self.s1) == [b'a', b'b'] def testStaticDef(self): @@ -1228,7 +1196,7 @@ class SequenceOf(BaseTestCase): s = SequenceOf() s[0] = 'abc' assert len(s) == 1 - assert s == [str2octs('abc')] + assert s == [b'abc'] def testUntyped(self): n = univ.SequenceOf() @@ -1264,7 +1232,7 @@ class SequenceOf(BaseTestCase): assert s.getComponentByPosition(0, default=None) is None s[0] = 'test' assert s.getComponentByPosition(0, default=None) is not None - assert s.getComponentByPosition(0, default=None) == str2octs('test') + assert s.getComponentByPosition(0, default=None) == b'test' s.clear() assert s.getComponentByPosition(0, default=None) is None @@ -1277,7 +1245,7 @@ class SequenceOf(BaseTestCase): assert s.getComponentByPosition(0, instantiate=False) is univ.noValue s[0] = 'test' assert s.getComponentByPosition(0, instantiate=False) is not univ.noValue - assert s.getComponentByPosition(0, instantiate=False) == str2octs('test') + assert s.getComponentByPosition(0, instantiate=False) == b'test' s.clear() assert s.getComponentByPosition(0, instantiate=False) is univ.noValue @@ -1289,7 +1257,7 @@ class SequenceOf(BaseTestCase): s = SequenceOf() s.setComponentByPosition(0, 'test') - assert s.getComponentByPosition(0) == str2octs('test') + assert s.getComponentByPosition(0) == b'test' assert len(s) == 1 assert s.isValue @@ -1307,7 +1275,7 @@ class SequenceOf(BaseTestCase): s = SequenceOf() s.setComponentByPosition(0, 'test') - assert s.getComponentByPosition(0) == str2octs('test') + assert s.getComponentByPosition(0) == b'test' assert s.isValue s.reset() @@ -1363,7 +1331,7 @@ class SequenceOfPicklingTestCase(unittest.TestCase): assert serialised new_asn1 = pickle.loads(serialised) assert new_asn1 - assert new_asn1 == [str2octs('test')] + assert new_asn1 == [b'test'] class Sequence(BaseTestCase): @@ -1388,11 +1356,11 @@ class Sequence(BaseTestCase): def testById(self): self.s1.setComponentByName('name', univ.OctetString('abc')) - assert self.s1.getComponentByName('name') == str2octs('abc'), 'set by name fails' + assert self.s1.getComponentByName('name') == b'abc', 'set by name fails' def testByKey(self): self.s1['name'] = 'abc' - assert self.s1['name'] == str2octs('abc'), 'set by key fails' + assert self.s1['name'] == b'abc', 'set by key fails' def testContains(self): assert 'name' in self.s1 @@ -1440,7 +1408,7 @@ class Sequence(BaseTestCase): def testComponentConstraintsMatching(self): s = self.s1.clone() o = univ.OctetString().subtype( - subtypeSpec=constraint.ConstraintsUnion(constraint.SingleValueConstraint(str2octs('cba')))) + subtypeSpec=constraint.ConstraintsUnion(constraint.SingleValueConstraint(b'cba'))) s.strictConstraints = True # This requires types equality try: s.setComponentByName('name', o.clone('cba')) @@ -1528,23 +1496,23 @@ class Sequence(BaseTestCase): self.s1.setComponentByPosition(0, univ.OctetString('abc')) self.s1.setComponentByPosition(1, univ.OctetString('def')) self.s1.setComponentByPosition(2, univ.Integer(123)) - assert list(self.s1.values()) == [str2octs('abc'), str2octs('def'), 123] + assert list(self.s1.values()) == [b'abc', b'def', 123] def testItems(self): self.s1.setComponentByPosition(0, univ.OctetString('abc')) self.s1.setComponentByPosition(1, univ.OctetString('def')) self.s1.setComponentByPosition(2, univ.Integer(123)) - assert list(self.s1.items()) == [(x[0], str2octs(x[1])) for x in [('name', 'abc'), ('nick', 'def')]] + [('age', 123)] + assert list(self.s1.items()) == [('name', b'abc'), ('nick', b'def'), ('age', 123)] def testUpdate(self): self.s1.clear() - assert list(self.s1.values()) == [str2octs(''), str2octs(''), 34] + assert list(self.s1.values()) == [b'', b'', 34] self.s1.update(**{'name': 'abc', 'nick': 'def', 'age': 123}) - assert list(self.s1.items()) == [(x[0], str2octs(x[1])) for x in [('name', 'abc'), ('nick', 'def')]] + [('age', 123)] + assert list(self.s1.items()) == [('name', b'abc'), ('nick', b'def'), ('age', 123)] self.s1.update(('name', 'ABC')) - assert list(self.s1.items()) == [(x[0], str2octs(x[1])) for x in [('name', 'ABC'), ('nick', 'def')]] + [('age', 123)] + assert list(self.s1.items()) == [('name', b'ABC'), ('nick', b'def'), ('age', 123)] self.s1.update(name='CBA') - assert list(self.s1.items()) == [(x[0], str2octs(x[1])) for x in [('name', 'CBA'), ('nick', 'def')]] + [('age', 123)] + assert list(self.s1.items()) == [('name', b'CBA'), ('nick', b'def'), ('age', 123)] def testStaticDef(self): @@ -1557,7 +1525,7 @@ class Sequence(BaseTestCase): s = Sequence() s['name'] = 'abc' - assert s['name'] == str2octs('abc') + assert s['name'] == b'abc' def testGetComponentWithDefault(self): @@ -1569,12 +1537,12 @@ class Sequence(BaseTestCase): s = Sequence() - assert s[0] == str2octs('') + assert s[0] == b'' assert s.getComponentByPosition(1, default=None, instantiate=False) is None assert s.getComponentByName('nick', default=None) is None s[1] = 'test' assert s.getComponentByPosition(1, default=None) is not None - assert s.getComponentByPosition(1, default=None) == str2octs('test') + assert s.getComponentByPosition(1, default=None) == b'test' s.clear() assert s.getComponentByPosition(1, default=None) is None @@ -1603,12 +1571,12 @@ class Sequence(BaseTestCase): ) s = Sequence() - assert s[0] == str2octs('') + assert s[0] == b'' assert s.getComponentByPosition(1, instantiate=False) is univ.noValue assert s.getComponentByName('nick', instantiate=False) is univ.noValue s[1] = 'test' assert s.getComponentByPosition(1, instantiate=False) is not univ.noValue - assert s.getComponentByPosition(1, instantiate=False) == str2octs('test') + assert s.getComponentByPosition(1, instantiate=False) == b'test' s.clear() assert s.getComponentByPosition(1, instantiate=False) is univ.noValue @@ -1639,29 +1607,6 @@ class Sequence(BaseTestCase): class Sequence(univ.Sequence): componentType = namedtype.NamedTypes( - namedtype.OptionalNamedType('name', univ.OctetString()) - ) - - s = Sequence() - - assert s.isValue - - s[0] = 'test' - - assert s.isValue - - s.clear() - - assert s.isValue - - s.reset() - - assert not s.isValue - - def testSchemaWithOptionalComponents(self): - - class Sequence(univ.Sequence): - componentType = namedtype.NamedTypes( namedtype.DefaultedNamedType('name', univ.OctetString('')) ) @@ -1802,13 +1747,13 @@ class SequenceWithoutSchema(BaseTestCase): s = univ.Sequence() s.setComponentByPosition(0, univ.OctetString('abc')) s.setComponentByPosition(1, univ.Integer(123)) - assert list(s.values()) == [str2octs('abc'), 123] + assert list(s.values()) == [b'abc', 123] def testItems(self): s = univ.Sequence() s.setComponentByPosition(0, univ.OctetString('abc')) s.setComponentByPosition(1, univ.Integer(123)) - assert list(s.items()) == [('field-0', str2octs('abc')), ('field-1', 123)] + assert list(s.items()) == [('field-0', b'abc'), ('field-1', 123)] def testUpdate(self): s = univ.Sequence().clear() @@ -1817,12 +1762,12 @@ class SequenceWithoutSchema(BaseTestCase): s.setComponentByPosition(1, univ.Integer(123)) assert s assert list(s.keys()) == ['field-0', 'field-1'] - assert list(s.values()) == [str2octs('abc'), 123] - assert list(s.items()) == [('field-0', str2octs('abc')), ('field-1', 123)] + assert list(s.values()) == [b'abc', 123] + assert list(s.items()) == [('field-0', b'abc'), ('field-1', 123)] s['field-0'] = univ.OctetString('def') - assert list(s.values()) == [str2octs('def'), 123] + assert list(s.values()) == [b'def', 123] s['field-1'] = univ.OctetString('ghi') - assert list(s.values()) == [str2octs('def'), str2octs('ghi')] + assert list(s.values()) == [b'def', b'ghi'] try: s['field-2'] = univ.OctetString('xxx') except KeyError: @@ -1880,7 +1825,7 @@ class SequencePicklingTestCase(unittest.TestCase): assert serialised new_asn1 = pickle.loads(serialised) assert new_asn1 - assert new_asn1['name'] == str2octs('test') + assert new_asn1['name'] == b'test' class SetOf(BaseTestCase): @@ -1896,9 +1841,9 @@ class SetOf(BaseTestCase): def testSeq(self): self.s1.setComponentByPosition(0, univ.OctetString('abc')) - assert self.s1[0] == str2octs('abc'), 'set by idx fails' + assert self.s1[0] == b'abc', 'set by idx fails' self.s1.setComponentByPosition(0, self.s1[0].clone('cba')) - assert self.s1[0] == str2octs('cba'), 'set by idx fails' + assert self.s1[0] == b'cba', 'set by idx fails' def testStaticDef(self): @@ -1908,7 +1853,7 @@ class SetOf(BaseTestCase): s = SetOf() s[0] = 'abc' assert len(s) == 1 - assert s == [str2octs('abc')] + assert s == [b'abc'] @@ -1929,7 +1874,7 @@ class SetOfPicklingTestCase(unittest.TestCase): assert serialised new_asn1 = pickle.loads(serialised) assert new_asn1 - assert new_asn1 == [str2octs('test')] + assert new_asn1 == [b'test'] class Set(BaseTestCase): @@ -1955,13 +1900,13 @@ class Set(BaseTestCase): self.s1.setComponentByType(univ.OctetString.tagSet, 'abc') assert self.s1.getComponentByType( univ.OctetString.tagSet - ) == str2octs('abc'), 'set by name fails' + ) == b'abc', 'set by name fails' def testByTypeWithInstance(self): self.s1.setComponentByType(univ.OctetString.tagSet, univ.OctetString('abc')) assert self.s1.getComponentByType( univ.OctetString.tagSet - ) == str2octs('abc'), 'set by name fails' + ) == b'abc', 'set by name fails' def testGetTagMap(self): assert self.s1.tagMap.presentTypes == { @@ -1996,7 +1941,7 @@ class Set(BaseTestCase): s = Set() s['name'] = 'abc' - assert s['name'] == str2octs('abc') + assert s['name'] == b'abc' def testGetComponentWithDefault(self): @@ -2012,7 +1957,7 @@ class Set(BaseTestCase): assert s.getComponentByName('nick', default=None) is None s[1] = 'test' assert s.getComponentByPosition(1, default=None) is not None - assert s.getComponentByPosition(1, default=None) == str2octs('test') + assert s.getComponentByPosition(1, default=None) == b'test' s.clear() assert s.getComponentByPosition(1, default=None) is None @@ -2031,7 +1976,7 @@ class Set(BaseTestCase): assert s.getComponentByType(univ.OctetString.tagSet, instantiate=False) is univ.noValue s[1] = 'test' assert s.getComponentByPosition(1, instantiate=False) is not univ.noValue - assert s.getComponentByPosition(1, instantiate=False) == str2octs('test') + assert s.getComponentByPosition(1, instantiate=False) == b'test' s.clear() assert s.getComponentByPosition(1, instantiate=False) is univ.noValue @@ -2061,7 +2006,7 @@ class SetPicklingTestCase(unittest.TestCase): assert serialised new_asn1 = pickle.loads(serialised) assert new_asn1 - assert new_asn1['name'] == str2octs('test') + assert new_asn1['name'] == b'test' class Choice(BaseTestCase): @@ -2110,7 +2055,7 @@ class Choice(BaseTestCase): self.s1.setComponentByType(univ.OctetString.tagSet, 'abc') assert self.s1.getComponentByType( univ.OctetString.tagSet - ) == str2octs('abc') + ) == b'abc' def testOuterByTypeWithInstanceValue(self): self.s1.setComponentByType( @@ -2118,7 +2063,7 @@ class Choice(BaseTestCase): ) assert self.s1.getComponentByType( univ.OctetString.tagSet - ) == str2octs('abc') + ) == b'abc' def testInnerByTypeWithPythonValue(self): self.s1.setComponentByType(univ.Integer.tagSet, 123, innerFlag=True) @@ -2136,11 +2081,11 @@ class Choice(BaseTestCase): def testCmp(self): self.s1.setComponentByName('name', univ.OctetString('abc')) - assert self.s1 == str2octs('abc'), '__cmp__() fails' + assert self.s1 == b'abc', '__cmp__() fails' def testGetComponent(self): self.s1.setComponentByType(univ.OctetString.tagSet, 'abc') - assert self.s1.getComponent() == str2octs('abc'), 'getComponent() fails' + assert self.s1.getComponent() == b'abc', 'getComponent() fails' def testGetName(self): self.s1.setComponentByType(univ.OctetString.tagSet, 'abc') @@ -2148,7 +2093,7 @@ class Choice(BaseTestCase): def testSetComponentByPosition(self): self.s1.setComponentByPosition(0, univ.OctetString('Jim')) - assert self.s1 == str2octs('Jim') + assert self.s1 == b'Jim' def testClone(self): self.s1.setComponentByPosition(0, univ.OctetString('abc')) @@ -2252,7 +2197,7 @@ class ChoicePicklingTestCase(unittest.TestCase): assert serialised new_asn1 = pickle.loads(serialised) assert new_asn1 - assert new_asn1['name'] == str2octs('test') + assert new_asn1['name'] == b'test' suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__]) diff --git a/contrib/python/pyasn1/py3/tests/ya.make b/contrib/python/pyasn1/py3/tests/ya.make index 95837ba4a4..1add9c8912 100644 --- a/contrib/python/pyasn1/py3/tests/ya.make +++ b/contrib/python/pyasn1/py3/tests/ya.make @@ -21,9 +21,6 @@ TEST_SRCS( codec/native/test_decoder.py codec/native/test_encoder.py codec/test_streaming.py - compat/__init__.py - compat/test_integer.py - compat/test_octets.py test_debug.py type/__init__.py type/test_char.py diff --git a/contrib/python/pyasn1/py3/ya.make b/contrib/python/pyasn1/py3/ya.make index 966cbc6695..ce7879bfca 100644 --- a/contrib/python/pyasn1/py3/ya.make +++ b/contrib/python/pyasn1/py3/ya.make @@ -2,7 +2,7 @@ PY3_LIBRARY() -VERSION(0.6.0) +VERSION(0.6.1) LICENSE(BSD-3-Clause) @@ -28,7 +28,6 @@ PY_SRCS( pyasn1/codec/streaming.py pyasn1/compat/__init__.py pyasn1/compat/integer.py - pyasn1/compat/octets.py pyasn1/debug.py pyasn1/error.py pyasn1/type/__init__.py |