• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python octets.oct2int函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pyasn1.compat.octets.oct2int函数的典型用法代码示例。如果您正苦于以下问题:Python oct2int函数的具体用法?Python oct2int怎么用?Python oct2int使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了oct2int函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: valueDecoder

 def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length,
                  state, decodeFun):
     substrate = substrate[:length]        
     if tagSet[0][1] == tag.tagFormatSimple:    # XXX what tag to check?
         if not substrate:
             raise error.PyAsn1Error('Missing initial octet')
         trailingBits = oct2int(substrate[0])
         if trailingBits > 7:
             raise error.PyAsn1Error(
                 'Trailing bits overflow %s' % trailingBits
                 )
         substrate = substrate[1:]
         lsb = p = 0; l = len(substrate)-1; b = ()
         while p <= l:
             if p == l:
                 lsb = trailingBits
             j = 7                    
             o = oct2int(substrate[p])
             while j >= lsb:
                 b = b + ((o>>j)&0x01,)
                 j = j - 1
             p = p + 1
         return self._createComponent(asn1Spec, tagSet, b), ''
     r = self._createComponent(asn1Spec, tagSet, ())
     if not decodeFun:
         return r, substrate
     while substrate:
         component, substrate = decodeFun(substrate)
         r = r + component
     return r, substrate
开发者ID:bullseyestudio,项目名称:guns-game,代码行数:30,代码来源:decoder.py


示例2: valueDecoder

    def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length,
                     state, decodeFun, substrateFun):
        head, tail = substrate[:length], substrate[length:]
        if not head:
            raise error.PyAsn1Error('Empty substrate')

        # Get the first subid
        subId = oct2int(head[0])
        oid = divmod(subId, 40)

        index = 1
        substrateLen = len(head)
        while index < substrateLen:
            subId = oct2int(head[index])
            index = index + 1
            if subId == 128:
                # ASN.1 spec forbids leading zeros (0x80) in sub-ID OID
                # encoding, tolerating it opens a vulnerability.
                # See http://www.cosic.esat.kuleuven.be/publications/article-1432.pdf page 7
                raise error.PyAsn1Error('Invalid leading 0x80 in sub-OID')
            elif subId > 128:
                # Construct subid from a number of octets
                nextSubId = subId
                subId = 0
                while nextSubId >= 128:
                    subId = (subId << 7) + (nextSubId & 0x7F)
                    if index >= substrateLen:
                        raise error.SubstrateUnderrunError(
                            'Short substrate for sub-OID past %s' % (oid,)
                            )
                    nextSubId = oct2int(head[index])
                    index = index + 1
                subId = (subId << 7) + nextSubId
            oid = oid + (subId,)
        return self._createComponent(asn1Spec, tagSet, oid), tail
开发者ID:andviro,项目名称:pyasn1,代码行数:35,代码来源:decoder.py


示例3: valueDecoder

 def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length,
                  state, decodeFun, substrateFun):
     head, tail = substrate[:length], substrate[length:]
     if tagSet[0][1] == tag.tagFormatSimple:    # XXX what tag to check?
         if not head:
             raise error.PyAsn1Error('Empty substrate')
         trailingBits = oct2int(head[0])
         if trailingBits > 7:
             raise error.PyAsn1Error(
                 'Trailing bits overflow %s' % trailingBits
                 )
         head = head[1:]
         lsb = p = 0; l = len(head)-1; b = []
         while p <= l:
             if p == l:
                 lsb = trailingBits
             j = 7
             o = oct2int(head[p])
             while j >= lsb:
                 b.append((o>>j)&0x01)
                 j -= 1
             p += 1
         return self._createComponent(asn1Spec, tagSet, b), tail
     r = self._createComponent(asn1Spec, tagSet, ())
     if substrateFun:
         return substrateFun(r, substrate, length)
     while head:
         component, head = decodeFun(head, self.protoComponent)
         r = r + component
     return r, tail
开发者ID:mmattice,项目名称:pyasn1,代码行数:30,代码来源:decoder.py


示例4: __asSocketAddress

 def __asSocketAddress(self):
     if not hasattr(self, '__tuple_value'):
         v = self.asOctets()
         self.__tuple_value = (
             inet_ntop(AF_INET, v[:4]),
             oct2int(v[4]) << 8 | oct2int(v[5])
         )
     return self.__tuple_value
开发者ID:etingof,项目名称:pysnmp,代码行数:8,代码来源:SNMPv2-TM.py


示例5: __getitem__

 def __getitem__(self, i):
     if not hasattr(self, '__tuple_value'):
         v = self.asOctets()
         self.__tuple_value = (
             inet_ntop(AF_INET, v[:4]),
             oct2int(v[4]) << 8 | oct2int(v[5])
         )
     return self.__tuple_value[i]
开发者ID:BoundaryDev,项目名称:boundary-plugin-mongodb-enterprise-dev,代码行数:8,代码来源:SNMPv2-TM.py


示例6: __getitem__

 def __getitem__(self, i):
     if not hasattr(self, '__tuple_value'):
         if AF_INET6 is None:
             raise error.PySnmpError('IPv6 not supported by platform')
         v = self.asOctets()
         self.__tuple_value = (
             inet_ntop(AF_INET6, v[:16]),
             oct2int(v[16]) << 8 | oct2int(v[17]),
             0,
             0)
     return self.__tuple_value[i]
开发者ID:carmackjia,项目名称:pysnmp,代码行数:11,代码来源:TRANSPORT-ADDRESS-MIB.py


示例7: __getitem__

 def __getitem__(self, i):
     if not hasattr(self, '__tuple_value'):
         if not has_ipv6:
             raise error.PySnmpError('IPv6 not supported by platform')
         v = self.asOctets()
         self.__tuple_value = (
             inet_ntop(socket.AF_INET6, v[:16]),
             oct2int(v[16]) << 8 | oct2int(v[17]),
             0,  # flowinfo
             0)  # scopeid
     return self.__tuple_value[i]
开发者ID:bbmorten,项目名称:pysnmp,代码行数:11,代码来源:TRANSPORT-ADDRESS-MIB.py


示例8: valueDecoder

 def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet,
                  length, state, decodeFun, substrateFun):
     head, tail = substrate[:length], substrate[length:]
     if not head:
         raise error.SubstrateUnderrunError('Short substrate for Real')
     fo = oct2int(head[0]); head = head[1:]
     if fo & 0x40:  # infinite value
         value = fo & 0x01 and '-inf' or 'inf'
     elif fo & 0x80:  # binary enoding
         n = (fo & 0x03) + 1
         if n == 4:
             n = oct2int(head[0])
         eo, head = head[:n], head[n:]
         if not eo or not head:
             raise error.PyAsn1Error('Real exponent screwed')
         e = oct2int(eo[0]) & 0x80 and -1 or 0
         while eo:         # exponent
             e <<= 8
             e |= oct2int(eo[0])
             eo = eo[1:]
         p = 0
         while head:  # value
             p <<= 8
             p |= oct2int(head[0])
             head = head[1:]
         if fo & 0x40:    # sign bit
             p = -p
         value = (p, 2, e)
     elif fo & 0xc0 == 0:  # character encoding
         try:
             if fo & 0x3 == 0x1:  # NR1
                 value = (int(head), 10, 0)
             elif fo & 0x3 == 0x2:  # NR2
                 value = float(head)
             elif fo & 0x3 == 0x3:  # NR3
                 value = float(head)
             else:
                 raise error.SubstrateUnderrunError(
                     'Unknown NR (tag %s)' % fo
                     )
         except ValueError:
             raise error.SubstrateUnderrunError(
                 'Bad character Real syntax'
                 )
     elif fo & 0xc0 == 0x40:  # special real value
         pass
     else:
         raise error.SubstrateUnderrunError(
             'Unknown encoding (tag %s)' % fo
             )
     return self._createComponent(asn1Spec, tagSet, value), tail
开发者ID:2flcastro,项目名称:ka-lite,代码行数:51,代码来源:decoder.py


示例9: valueDecoder

 def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length,
                  state, decodeFun):
     substrate = substrate[:length]
     if not substrate:
         raise error.PyAsn1Error('Empty substrate')
     if substrate in self.precomputedValues:
         value = self.precomputedValues[substrate]
     else:
         firstOctet = oct2int(substrate[0])
         if firstOctet & 0x80:
             value = -1
         else:
             value = 0
         for octet in substrate:
             value = value << 8 | oct2int(octet)
     return self._createComponent(asn1Spec, tagSet, value), substrate
开发者ID:404minds,项目名称:quiz-forest,代码行数:16,代码来源:decoder.py


示例10: valueDecoder

    def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length,
                     state, decodeFun, substrateFun):
        head, tail = substrate[:length], substrate[length:]
        if tagSet[0].tagFormat == tag.tagFormatSimple:  # XXX what tag to check?
            if not head:
                raise error.PyAsn1Error('Empty substrate')
            trailingBits = oct2int(head[0])
            if trailingBits > 7:
                raise error.PyAsn1Error(
                    'Trailing bits overflow %s' % trailingBits
                )
            head = head[1:]
            value = self.protoComponent.fromOctetString(head, trailingBits)
            return self._createComponent(asn1Spec, tagSet, value), tail

        if not self.supportConstructedForm:
            raise error.PyAsn1Error('Constructed encoding form prohibited at %s' % self.__class__.__name__)

        bitString = self._createComponent(asn1Spec, tagSet)

        if substrateFun:
            return substrateFun(bitString, substrate, length)

        while head:
            component, head = decodeFun(head, self.protoComponent)
            bitString += component

        return bitString, tail
开发者ID:0-vortex,项目名称:ZeroNet,代码行数:28,代码来源:decoder.py


示例11: from_bytes

    def from_bytes(octets, signed=False):
        value = long(b2a_hex(str(octets)), 16)

        if signed and oct2int(octets[0]) & 0x80:
            return value - (1 << len(octets) * 8)

        return value
开发者ID:0-vortex,项目名称:ZeroNet,代码行数:7,代码来源:integer.py


示例12: from_bytes

    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
开发者ID:danacton,项目名称:appengine-endpoints-modules-lnkr,代码行数:10,代码来源:integer.py


示例13: valueDecoder

 def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length,
                  state, decodeFun):
     substrate = substrate[:length]
     if not substrate:
         raise error.PyAsn1Error('Empty substrate')
     byte = oct2int(substrate[0])
     if byte == 0xff:
         value = 1
     elif byte == 0x00:
         value = 0
     else:
         raise error.PyAsn1Error('Boolean CER violation: %s' % byte)
     return self._createComponent(asn1Spec, tagSet, value), substrate[1:]
开发者ID:404minds,项目名称:quiz-forest,代码行数:13,代码来源:decoder.py


示例14: valueDecoder

 def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length,
                  state, decodeFun, substrateFun):
     head, tail = substrate[:length], substrate[length:]
     if tagSet[0][1] == tag.tagFormatSimple:    # XXX what tag to check?
         if not head:
             raise error.PyAsn1Error('Empty substrate')
         trailingBits = oct2int(head[0])
         if trailingBits > 7:
             raise error.PyAsn1Error(
                 'Trailing bits overflow %s' % trailingBits
                 )
         head = head[1:]
         if BITPATTERN:
             # Use faster method with lookup table
             p = 0; l = len(head)-1; b = []
             while p < l:
                 b.extend(BITPATTERN[oct2int(head[p])])
                 p += 1
             b.extend(BITPATTERN[oct2int(head[p])][0:8-trailingBits])
         else:
             # Use original, slower method
             lsb = p = 0; l = len(head)-1; b = ()
             while p <= l:
                 if p == l:
                     lsb = trailingBits
                 j = 7                    
                 o = oct2int(head[p])
                 while j >= lsb:
                     b = b + ((o>>j)&0x01,)
                     j = j - 1
                 p = p + 1
         return self._createComponent(asn1Spec, tagSet, b), tail
     r = self._createComponent(asn1Spec, tagSet, ())
     if substrateFun:
         return substrateFun(r, substrate, length)
     while head:
         component, head = decodeFun(head)
         r = r + component
     return r, tail
开发者ID:dmbaggett,项目名称:pyasn1,代码行数:39,代码来源:decoder.py


示例15: valueDecoder

 def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length, state, decodeFun, substrateFun):
     head, tail = substrate[:length], substrate[length:]
     if not head or length != 1:
         raise error.PyAsn1Error("Not single-octet Boolean payload")
     byte = oct2int(head[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
     # in http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf
     if byte == 0xFF:
         value = 1
     elif byte == 0x00:
         value = 0
     else:
         raise error.PyAsn1Error("Unexpected Boolean payload: %s" % byte)
     return self._createComponent(asn1Spec, tagSet, value), tail
开发者ID:vmurashev,项目名称:crystax-dev-utils,代码行数:15,代码来源:decoder.py


示例16: encodeValue

 def encodeValue(self, encodeFun, value, defMode, maxChunkSize):
     if value.isPlusInfinity():
         return int2oct(0x40), 0
     if value.isMinusInfinity():
         return int2oct(0x41), 0
     m, b, e = value
     if not m:
         return null, 0
     if b == 10:
         return str2octs('\x03%dE%s%d' % (m, e == 0 and '+' or '', e)), 0
     elif b == 2:
         fo = 0x80                 # binary enoding
         if m < 0:
             fo = fo | 0x40  # sign bit
             m = -m
         while int(m) != m: # drop floating point
             m *= 2
             e -= 1
         while m & 0x1 == 0: # mantissa normalization
             m >>= 1
             e += 1
         eo = null
         while e not in (0, -1):
             eo = int2oct(e&0xff) + eo
             e >>= 8
         if e == 0 and eo and oct2int(eo[0]) & 0x80:
             eo = int2oct(0) + eo
         n = len(eo)
         if n > 0xff:
             raise error.PyAsn1Error('Real exponent overflow')
         if n == 1:
             pass
         elif n == 2:
             fo |= 1
         elif n == 3:
             fo |= 2
         else:
             fo |= 3
             eo = int2oct(n//0xff+1) + eo
         po = null
         while m:
             po = int2oct(m&0xff) + po
             m >>= 8
         substrate = int2oct(fo) + eo + po
         return substrate, 0
     else:
         raise error.PyAsn1Error('Prohibited Real base %s' % b)
开发者ID:GymWenFLL,项目名称:tpp_libs,代码行数:47,代码来源:encoder.py


示例17: __call__

 def __call__(self, substrate, asn1Spec=None, tagSet=None,
              length=None, state=stDecodeTag, recursiveFlag=1):
     fullSubstrate = substrate
     while state != stStop:
         if state == stDecodeTag:
             # Decode tag
             if not substrate:
                 raise error.SubstrateUnderrunError(
                     'Short octet stream on tag decoding'
                     )
             
             firstOctet = substrate[0]
             substrate = substrate[1:]
             if firstOctet in self.__tagCache:
                 lastTag = self.__tagCache[firstOctet]
             else:
                 t = oct2int(firstOctet)
                 tagClass = t&0xC0
                 tagFormat = t&0x20
                 tagId = t&0x1F
                 if tagId == 0x1F:
                     tagId = 0
                     while 1:
                         if not substrate:
                             raise error.SubstrateUnderrunError(
                                 'Short octet stream on long tag decoding'
                                 )
                         t = oct2int(substrate[0])
                         tagId = tagId << 7 | (t&0x7F)
                         substrate = substrate[1:]
                         if not t&0x80:
                             break
                 lastTag = tag.Tag(
                     tagClass=tagClass, tagFormat=tagFormat, tagId=tagId
                     )
                 if tagId < 31:
                     # cache short tags
                     self.__tagCache[firstOctet] = lastTag
             if tagSet is None:
                 if firstOctet in self.__tagSetCache:
                     tagSet = self.__tagSetCache[firstOctet]
                 else:
                     # base tag not recovered
                     tagSet = tag.TagSet((), lastTag)
                     if firstOctet in self.__tagCache:
                         self.__tagSetCache[firstOctet] = tagSet
             else:
                 tagSet = lastTag + tagSet
             state = stDecodeLength
         if state == stDecodeLength:
             # Decode length
             if not substrate:
                  raise error.SubstrateUnderrunError(
                      'Short octet stream on length decoding'
                      )
             firstOctet  = oct2int(substrate[0])
             if firstOctet == 128:
                 size = 1
                 length = -1
             elif firstOctet < 128:
                 length, size = firstOctet, 1
             else:
                 size = firstOctet & 0x7F
                 # encoded in size bytes
                 length = 0
                 lengthString = substrate[1:size+1]
                 # missing check on maximum size, which shouldn't be a
                 # problem, we can handle more than is possible
                 if len(lengthString) != size:
                     raise error.SubstrateUnderrunError(
                         '%s<%s at %s' %
                         (size, len(lengthString), tagSet)
                         )
                 for char in lengthString:
                     length = (length << 8) | oct2int(char)
                 size = size + 1
             state = stGetValueDecoder
             substrate = substrate[size:]
             if length != -1 and len(substrate) < length:
                 raise error.SubstrateUnderrunError(
                     '%d-octet short' % (length - len(substrate))
                     )
         if state == stGetValueDecoder:
             if asn1Spec is None:
                 state = stGetValueDecoderByTag
             else:
                 state = stGetValueDecoderByAsn1Spec
         #
         # There're two ways of creating subtypes in ASN.1 what influences
         # decoder operation. These methods are:
         # 1) Either base types used in or no IMPLICIT tagging has been
         #    applied on subtyping.
         # 2) Subtype syntax drops base type information (by means of
         #    IMPLICIT tagging.
         # The first case allows for complete tag recovery from substrate
         # while the second one requires original ASN.1 type spec for
         # decoding.
         #
         # In either case a set of tags (tagSet) is coming from substrate
         # in an incremental, tag-by-tag fashion (this is the case of
#.........这里部分代码省略.........
开发者ID:bullseyestudio,项目名称:guns-game,代码行数:101,代码来源:decoder.py


示例18: prettyOut

    def prettyOut(self, value):  # override asn1 type method
        """Implements DISPLAY-HINT evaluation"""
        if self.displayHint and (self.__integer.isSuperTypeOf(self, matchConstraints=False) and not self.getNamedValues() or
                                 self.__unsigned32.isSuperTypeOf(self, matchConstraints=False) or
                                 self.__timeticks.isSuperTypeOf(self, matchConstraints=False)):
            _ = lambda t, f=0: (t, f)
            displayHintType, decimalPrecision = _(*self.displayHint.split('-'))
            if displayHintType == 'x':
                return '0x%x' % value
            elif displayHintType == 'd':
                try:
                    return '%.*f' % (int(decimalPrecision), float(value) / pow(10, int(decimalPrecision)))
                except Exception as exc:
                    raise SmiError(
                        'float evaluation error: %s' % exc
                    )
            elif displayHintType == 'o':
                return '0%o' % value
            elif displayHintType == 'b':
                runningValue = value
                outputValue = ['B']
                while runningValue:
                    outputValue.insert(0, '%d' % (runningValue & 0x01))
                    runningValue >>= 1
                return ''.join(outputValue)
            else:
                raise SmiError(
                    'Unsupported numeric type spec "%s" at %s' % (displayHintType, self.__class__.__name__)
                )
        elif self.displayHint and self.__octetString.isSuperTypeOf(self, matchConstraints=False):
            outputValue = ''
            runningValue = OctetString(value).asOctets()
            displayHint = self.displayHint
            while runningValue and displayHint:
                # 1
                if displayHint[0] == '*':
                    repeatIndicator = repeatCount = octets.oct2int(runningValue[0])
                    displayHint = displayHint[1:]
                    runningValue = runningValue[1:]
                else:
                    repeatCount = 1
                    repeatIndicator = None

                # 2
                octetLength = ''
                while displayHint and displayHint[0] in string.digits:
                    octetLength += displayHint[0]
                    displayHint = displayHint[1:]

                # length is manatory, but people ignore that
                if not octetLength:
                    octetLength = len(runningValue)

                try:
                    octetLength = int(octetLength)
                except Exception:
                    raise SmiError(
                        'Bad octet length: %s' % octetLength
                    )

                if not displayHint:
                    raise SmiError(
                        'Short octet length: %s' % self.displayHint
                    )

                # 3
                displayFormat = displayHint[0]
                displayHint = displayHint[1:]

                # 4
                if displayHint and displayHint[0] not in string.digits and displayHint[0] != '*':
                    displaySep = displayHint[0]
                    displayHint = displayHint[1:]
                else:
                    displaySep = ''

                # 5
                if displayHint and displaySep and repeatIndicator is not None:
                    repeatTerminator = displayHint[0]
                    displaySep = ''
                    displayHint = displayHint[1:]
                else:
                    repeatTerminator = None

                while repeatCount:
                    repeatCount -= 1
                    if displayFormat == 'a':
                        outputValue += runningValue[:octetLength].decode('ascii', 'ignore')
                    elif displayFormat == 't':
                        outputValue += runningValue[:octetLength].decode('utf-8', 'ignore')
                    elif displayFormat in ('x', 'd', 'o'):
                        number = 0
                        numberString = runningValue[:octetLength]
                        while numberString:
                            number <<= 8
                            try:
                                number |= octets.oct2int(numberString[0])
                                numberString = numberString[1:]
                            except Exception as exc:
                                raise SmiError(
#.........这里部分代码省略.........
开发者ID:etingof,项目名称:pysnmp,代码行数:101,代码来源:SNMPv2-TC.py


示例19: __call__

    def __call__(self, substrate, asn1Spec=None, tagSet=None,
                 length=None, state=stDecodeTag, recursiveFlag=1,
                 substrateFun=None, allowEoo=False):
        if debug.logger & debug.flagDecoder:
            debug.logger('decoder called at scope %s with state %d, working with up to %d octets of substrate: %s' % (debug.scope, state, len(substrate), debug.hexdump(substrate)))
        if asn1Spec is not None and not isinstance(asn1Spec, (base.Asn1Item, tagmap.TagMap)):
            raise error.PyAsn1Error('asn1Spec is not valid (should be an instance of an ASN.1 Item, not %s)' % asn1Spec.__class__.__name__)

        fullSubstrate = substrate
        while state != stStop:
            if state == stDecodeTag:
                if not substrate:
                    raise error.SubstrateUnderrunError(
                        'Short octet stream on tag decoding'
                        )
                if not isOctetsType(substrate) and \
                   not isinstance(substrate, univ.OctetString):
                    raise error.PyAsn1Error('Bad octet stream type')
                # Decode tag
                firstOctet = substrate[0]
                substrate = substrate[1:]
                if firstOctet in self.__tagCache:
                    lastTag = self.__tagCache[firstOctet]
                else:
                    t = oct2int(firstOctet)
                    # Look for end-of-octets sentinel
                    if t == 0:
                        if substrate and oct2int(substrate[0]) == 0:
                            if allowEoo and self.supportIndefLength:
                                debug.logger and debug.logger & debug.flagDecoder and debug.logger('end-of-octets sentinel found')
                                value, substrate = eoo.endOfOctets, substrate[1:]
                                state = stStop
                                continue
                            else:
                                raise error.PyAsn1Error('Unexpected end-of-contents sentinel')
                        else:
                            raise error.PyAsn1Error('Zero tag encountered')
                    tagClass = t&0xC0
                    tagFormat = t&0x20
                    tagId = t&0x1F
                    if tagId == 0x1F:
                        tagId = 0
                        while 1:
                            if not substrate:
                                raise error.SubstrateUnderrunError(
                                    'Short octet stream on long tag decoding'
                                    )
                            t = oct2int(substrate[0])
                            tagId = tagId << 7 | (t&0x7F)
                            substrate = substrate[1:]
                            if not t&0x80:
                                break
                    lastTag = tag.Tag(
                        tagClass=tagClass, tagFormat=tagFormat, tagId=tagId
                    )
                    if tagId < 31:
                        # cache short tags
                        self.__tagCache[firstOctet] = lastTag
                if tagSet is None:
                    if firstOctet in self.__tagSetCache:
                        tagSet = self.__tagSetCache[firstOctet]
                    else:
                        # base tag not recovered
                        tagSet = tag.TagSet((), lastTag)
                        if firstOctet in self.__tagCache:
                            self.__tagSetCache[firstOctet] = tagSet
                else:
                    tagSet = lastTag + tagSet
                state = stDecodeLength
                debug.logger and debug.logger & debug.flagDecoder and debug.logger('tag decoded into %s, decoding length' % tagSet)
            if state == stDecodeLength:
                # Decode length
                if not substrate:
                    raise error.SubstrateUnderrunError(
                        'Short octet stream on length decoding'
                    )
                firstOctet  = oct2int(substrate[0])
                if firstOctet == 128:
                    size = 1
                    length = -1
                elif firstOctet < 128:
                    length, size = firstOctet, 1
                else:
                    size = firstOctet & 0x7F
                    # encoded in size bytes
                    length = 0
                    lengthString = substrate[1:size+1]
                    # missing check on maximum size, which shouldn't be a
                    # problem, we can handle more than is possible
                    if len(lengthString) != size:
                        raise error.SubstrateUnderrunError(
                            '%s<%s at %s' %
                            (size, len(lengthString), tagSet)
                            )
                    for char in lengthString:
                        length = (length << 8) | oct2int(char)
                    size += 1
                substrate = substrate[size:]
                if length != -1 and len(substrate) < length:
                    raise error.SubstrateUnderrunError(
#.........这里部分代码省略.........
开发者ID:mmattice,项目名称:pyasn1,代码行数:101,代码来源:decoder.py


示例20: encodeValue

    def encodeValue(self, value, asn1Spec, encodeFun, **options):
        if asn1Spec is not None:
            value = asn1Spec.clone(value)

        if value.isPlusInf:
            return (0x40,), False, False

        if value.isMinusInf:
            return (0x41,), False, False

        m, b, e = value

        if not m:
            return null, 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

        elif b == 2:
            fo = 0x80  # binary encoding
            ms, m, encbase, e = self._chooseEncBase(value)

            if ms < 0:  # mantissa sign
                fo |= 0x40  # sign bit

            # exponent & mantissa normalization
            if encbase == 2:
                while m & 0x1 == 0:
                    m >>= 1
                    e += 1

            elif encbase == 8:
                while m & 0x7 == 0:
                    m >>= 3
                    e += 1
                fo |= 0x10

            else:  # encbase = 16
                while m & 0xf == 0:
                    m >>= 4
                    e += 1
                fo |= 0x20

            sf = 0  # scale factor

            while m & 0x1 == 0:
                m >>= 1
                sf += 1

            if sf > 3:
                raise error.PyAsn1Error('Scale factor overflow')  # bug if raised

            fo |= sf << 2
            eo = null
            if e == 0 or e == -1:
                eo = int2oct(e & 0xff)

            else:
                while e not in (0, -1):
                    eo = int2oct(e & 0xff) + eo
                    e >>= 8

                if e == 0 and eo and oct2int(eo[0]) & 0x80:
                    eo = int2oct(0) + eo

                if e == -1 and eo and not (oct2int(eo[0]) & 0x80):
                    eo = int2oct(0xff) + eo

            n = len(eo)
            if n > 0xff:
                raise error.PyAsn1Error('Real exponent overflow')

            if n == 1:
                pass

            elif n == 2:
                fo |= 1

            elif n == 3:
                fo |= 2

            else:
                fo |= 3
                eo = int2oct(n & 0xff) + eo

            po = null

            while m:
                po = int2oct(m & 0xff) + po
                m >>= 8

            substrate = int2oct(fo) + eo + po

            return substrate, False, True

        else:
            raise error.PyAsn1Error('Prohibited Real base %s' % b)
开发者ID:KernelPanicAUS,项目名称:got-your-back,代码行数:100,代码来源:encoder.py



注:本文中的pyasn1.compat.octets.oct2int函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python octets.str2octs函数代码示例发布时间:2022-05-25
下一篇:
Python octets.ints2octs函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap