当前位置: 首页>>代码示例>>Python>>正文


Python decoder.decode方法代码示例

本文整理汇总了Python中pyasn1.codec.ber.decoder.decode方法的典型用法代码示例。如果您正苦于以下问题:Python decoder.decode方法的具体用法?Python decoder.decode怎么用?Python decoder.decode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyasn1.codec.ber.decoder的用法示例。


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

示例1: libsnmp_encode_decode

# 需要导入模块: from pyasn1.codec.ber import decoder [as 别名]
# 或者: from pyasn1.codec.ber.decoder import decode [as 别名]
def libsnmp_encode_decode():
    try:
        import libsnmp.rfc1905 as libsnmp_rfc1905

        def decode():
            libsnmp_rfc1905.Message().decode(ENCODED_MESSAGE)

        encode_time = float('inf')
        decode_time = timeit.timeit(decode, number=ITERATIONS)
    except ImportError:
        encode_time = float('inf')
        decode_time = float('inf')
        print('Unable to import libsnmp.')
    except SyntaxError:
        encode_time = float('inf')
        decode_time = float('inf')
        print('Syntax error in libsnmp.')

    return encode_time, decode_time 
开发者ID:eerimoq,项目名称:asn1tools,代码行数:21,代码来源:ber.py

示例2: pyasn1_encode_decode

# 需要导入模块: from pyasn1.codec.ber import decoder [as 别名]
# 或者: from pyasn1.codec.ber.decoder import decode [as 别名]
def pyasn1_encode_decode():
    try:
        from pysnmp.proto import api
        from pyasn1.codec.ber import decoder

        snmp_v1 = api.protoModules[api.protoVersion1].Message()

        def decode():
            decoder.decode(ENCODED_MESSAGE, asn1Spec=snmp_v1)

        encode_time = float('inf')
        decode_time = timeit.timeit(decode, number=ITERATIONS)
    except ImportError:
        encode_time = float('inf')
        decode_time = float('inf')
        print('Unable to import pyasn1.')

    return encode_time, decode_time 
开发者ID:eerimoq,项目名称:asn1tools,代码行数:20,代码来源:ber.py

示例3: _handleControls

# 需要导入模块: from pyasn1.codec.ber import decoder [as 别名]
# 或者: from pyasn1.codec.ber.decoder import decode [as 别名]
def _handleControls(self, requestControls, responseControls):
        done = True
        if requestControls is not None:
            for requestControl in requestControls:
                if responseControls is not None:
                    for responseControl in responseControls:
                        if requestControl['controlType'] == CONTROL_PAGEDRESULTS:
                            if responseControl['controlType'] == CONTROL_PAGEDRESULTS:
                                if hasattr(responseControl, 'getCookie') is not True:
                                    responseControl = decoder.decode(encoder.encode(responseControl),
                                                                 asn1Spec=KNOWN_CONTROLS[CONTROL_PAGEDRESULTS]())[0]
                                if responseControl.getCookie():
                                    done = False
                                requestControl.setCookie(responseControl.getCookie())
                                break
                        else:
                            # handle different controls here
                            pass
        return done 
开发者ID:eth0izzle,项目名称:cracke-dit,代码行数:21,代码来源:ldap.py

示例4: safe_unicode

# 需要导入模块: from pyasn1.codec.ber import decoder [as 别名]
# 或者: from pyasn1.codec.ber.decoder import decode [as 别名]
def safe_unicode(value):
    """ For errors: return best possible unicode...should never lead to errors."""
    try:
        if isinstance(value, unicode):      # is already unicode, just return
            return value            
        elif isinstance(value, str):        # string, encoding unknown.
            for charset in ['utf_8', 'latin_1']:
                try:
                    return value.decode(charset, 'strict')  # decode strict
                except:
                    continue
            return value.decode('utf_8', 'ignore')  # decode as if it is utf-8, ignore errors.
        else:
            return unicode(value)
    except:
        try:
            return repr(value)
        except:
            return u'Error while displaying error'

# **********************************************************/**
# **************  Exception classes ***************************
# **********************************************************/** 
开发者ID:abhishek-ram,项目名称:pyas2,代码行数:25,代码来源:as2utils.py

示例5: check_binary_sig

# 需要导入模块: from pyasn1.codec.ber import decoder [as 别名]
# 或者: from pyasn1.codec.ber.decoder import decode [as 别名]
def check_binary_sig(signature, boundary, content):
    """ Function checks for binary signature and replaces with base64"""
    # Check if the signature is base64 or not
    try:
        raw_sig = signature.get_payload().encode('ascii').strip()
    except UnicodeDecodeError:
        # If not decode to base64 and replace in raw message
        raw_sig = signature.get_payload().encode('base64').strip()

    signature.set_payload(raw_sig)
    content_pts = content.split(boundary)
    content_pts[-2] = '\r\n%s\r\n' % mimetostring(signature, 78)
    content = boundary.join(content_pts)

    # return the contents and raw signature
    return content, raw_sig 
开发者ID:abhishek-ram,项目名称:pyas2,代码行数:18,代码来源:as2utils.py

示例6: updateusernameinencpart

# 需要导入模块: from pyasn1.codec.ber import decoder [as 别名]
# 或者: from pyasn1.codec.ber.decoder import decode [as 别名]
def updateusernameinencpart(key, rawticket, username, debug=False, verbose=False):
	try:
		ramticket, extra = decoder.decode(rawticket)
		serverticket = ramticket.getComponentByPosition(2)
		localticket = ramticket.getComponentByPosition(3)
		encserverticket = serverticket.getComponentByPosition(0).getComponentByPosition(3).getComponentByPosition(2).asOctets()
	except:
		raise ValueError('Unable to decode ticket. Invalid file.')
	if verbose: print('Ticket succesfully decoded')

	decserverticketraw, nonce = kerberos.decrypt(key, 2, encserverticket)

	a = decoder.decode(decserverticketraw)[0]
	a[3][1][0]._value = username
	e = encoder.encode(a)


	newencserverticket = kerberos.encrypt(key, 2, e, nonce)


	ramticket.getComponentByPosition(2).getComponentByPosition(0).getComponentByPosition(3).getComponentByPosition(2)._value = newencserverticket


	return ramticket 
开发者ID:nidem,项目名称:kerberoast,代码行数:26,代码来源:kerberoast.py

示例7: rc4crypt

# 需要导入模块: from pyasn1.codec.ber import decoder [as 别名]
# 或者: from pyasn1.codec.ber.decoder import decode [as 别名]
def rc4crypt(key, data):
    x = 0
    box = list(range(256))
    for i in range(256):
        x = (x + box[i] + (key[i % len(key)])) % 256
        box[i], box[x] = box[x], box[i]
    x = 0
    y = 0
    out = b''
    for char in data:
        x = (x + 1) % 256
        y = (y + box[x]) % 256
        box[x], box[y] = box[y], box[x]
        out += bytes([char ^ box[(box[x] + box[y]) % 256]])
    return out



#print decoder.decode(enc)

#define KERB_ETYPE_RC4_HMAC             23 
开发者ID:nidem,项目名称:kerberoast,代码行数:23,代码来源:kerberos.py

示例8: printdecode

# 需要导入模块: from pyasn1.codec.ber import decoder [as 别名]
# 或者: from pyasn1.codec.ber.decoder import decode [as 别名]
def printdecode(kerbpayload, ktype=2):
    d = decoder.decode(kerbpayload)
    if ktype == 32:
        #print "Protocol Version (pvno):  " + str(d[0][0])
        print("Message Type:             " + str(d[0][1]))
        print("Realm:                    " + str(d[0][2]))
        print("Principal:                " + str(d[0][3][1][0]))
        print("Ticket Version (tkt-vno): " + str(d[0][4][0]))
        print("Ticket Realm:             " + str(d[0][4][1]))
        #print "Name-Type (Service & Instance): " + str(d[0][4][2][0])
        print("Server, Name:             " + str(d[0][4][2][1][0]))
        print("Server, Name:             " + str(d[0][4][2][1][1]))
        #print "Data:                     " + str(d[0][4][3][2]).encode('hex')

        #print "Encryption Type: :        " + str(d[0][5][0])
        #print "Data:                     " + str(d[0])
        #print "Server Realm:             " + str(d[0][4][2][4])
    elif ktype == 2:
        print("a") 
开发者ID:nidem,项目名称:kerberoast,代码行数:21,代码来源:kerberos.py

示例9: callback_func

# 需要导入模块: from pyasn1.codec.ber import decoder [as 别名]
# 或者: from pyasn1.codec.ber.decoder import decode [as 别名]
def callback_func(self, transport_dispatcher, transport_domain,
                      transport_address, whole_msg):
        while whole_msg:
            msg_ver = int(snmp_api.decodeMessageVersion(whole_msg))
            if msg_ver in snmp_api.protoModules:
                p_mod = snmp_api.protoModules[msg_ver]
            else:
                LOG.error('Unsupported SNMP version %s.' % msg_ver)
                return
            req_msg, whole_msg = decoder.decode(
                whole_msg, asn1Spec=p_mod.Message(),
            )
            req_pdu = p_mod.apiMessage.getPDU(req_msg)
            if req_pdu.isSameTypeWith(p_mod.TrapPDU()):
                ver_binds = p_mod.apiTrapPDU.getVarBinds(req_pdu) \
                    if msg_ver == snmp_api.protoVersion1 \
                    else p_mod.apiPDU.getVarBinds(req_pdu)

                binds_dict = self._convert_binds_to_dict(ver_binds)
                LOG.debug('Receive binds info after convert: %s' % binds_dict)
                self._send_snmp_to_queue(binds_dict) 
开发者ID:openstack,项目名称:vitrage,代码行数:23,代码来源:service.py

示例10: OidFromAttid

# 需要导入模块: from pyasn1.codec.ber import decoder [as 别名]
# 或者: from pyasn1.codec.ber.decoder import decode [as 别名]
def OidFromAttid(prefixTable, attr):
    # separate the ATTRTYP into two parts
    upperWord = attr // 65536
    lowerWord = attr % 65536

    # search in the prefix table to find the upperWord, if found,
    # construct the binary OID by appending lowerWord to the end of
    # found prefix.

    binaryOID = None
    for j, item in enumerate(prefixTable):
        if item['ndx'] == upperWord:
            binaryOID = item['prefix']['elements'][:item['prefix']['length']]
            if lowerWord < 128:
                binaryOID.append(pack('B',lowerWord))
            else:
                if lowerWord >= 32768:
                    lowerWord -= 32768
                binaryOID.append(pack('B',(((lowerWord//128) % 128)+128)))
                binaryOID.append(pack('B',(lowerWord%128)))
            break

    if binaryOID is None:
        return None
    return str(decoder.decode(b'\x06' + pack('B',(len(binaryOID))) + b''.join(binaryOID), asn1Spec = univ.ObjectIdentifier())[0]) 
开发者ID:Coalfire-Research,项目名称:Slackor,代码行数:27,代码来源:drsuapi.py

示例11: recv

# 需要导入模块: from pyasn1.codec.ber import decoder [as 别名]
# 或者: from pyasn1.codec.ber.decoder import decode [as 别名]
def recv(dispatcher, domain, address, msg):
  while msg:
    msg_recv, msg = decoder.decode(msg, asn1Spec=pmod.Message())
    pdu_recv = pmod.apiMessage.getPDU(msg_recv)
    # match response to request as we're broadcasting
    if pmod.apiPDU.getRequestID(pdu_send) == pmod.apiPDU.getRequestID(pdu_recv):
      ipaddr = address[0]; device = '?'; uptime = '?'; status = '?'; prstat = 0
      # retrieve device properties
      for oid, val in pmod.apiPDU.getVarBinds(pdu_recv):
        oid, val = oid.prettyPrint(), val.prettyPrint()
        # skip non-printer devices
        if oid == '1.3.6.1.2.1.25.3.2.1.2.1' and val != '1.3.6.1.2.1.25.3.1.5': return
        # harvest device information
        if oid == '1.3.6.1.2.1.25.3.2.1.3.1': device = val
        if oid == '1.3.6.1.2.1.1.3.0': uptime = conv().elapsed(val, 100, True)
        if oid == '1.3.6.1.2.1.43.16.5.1.2.1.1': status = val
        if oid == '1.3.6.1.2.1.25.3.2.1.5.1' and val: prstat = val[:1]
      dispatcher.jobFinished(1)
      results[ipaddr] = [device, uptime, status, prstat] 
开发者ID:RUB-NDS,项目名称:PRET,代码行数:21,代码来源:discovery.py

示例12: asn1tools_encode_decode

# 需要导入模块: from pyasn1.codec.ber import decoder [as 别名]
# 或者: from pyasn1.codec.ber.decoder import decode [as 别名]
def asn1tools_encode_decode():
    snmp_v1 = asn1tools.compile_files(SNMP_V1_ASN_PATHS)

    def encode():
        snmp_v1.encode('Message',
                       DECODED_MESSAGE_ASN1TOOLS,
                       check_types=False)

    def decode():
        snmp_v1.decode('Message', ENCODED_MESSAGE)

    encode_time = timeit.timeit(encode, number=ITERATIONS)
    decode_time = timeit.timeit(decode, number=ITERATIONS)

    return encode_time, decode_time 
开发者ID:eerimoq,项目名称:asn1tools,代码行数:17,代码来源:ber.py

示例13: pycrate_encode_decode

# 需要导入模块: from pyasn1.codec.ber import decoder [as 别名]
# 或者: from pyasn1.codec.ber.decoder import decode [as 别名]
def pycrate_encode_decode():
    try:
        import rfc1155_1157_pycrate

        snmp_v1 = rfc1155_1157_pycrate.RFC1157_SNMP.Message
        snmp_v1._SAFE_INIT = False
        snmp_v1._SAFE_VAL = False
        snmp_v1._SAFE_BND = False
        snmp_v1._SAFE_BNDTAB = False

        def encode():
            snmp_v1.set_val(DECODED_MESSAGE_PYCRATE)
            snmp_v1.to_ber()

        def decode():
            snmp_v1.from_ber(ENCODED_MESSAGE)
            snmp_v1()

        encode_time = timeit.timeit(encode, number=ITERATIONS)
        decode_time = timeit.timeit(decode, number=ITERATIONS)
    except ImportError:
        encode_time = float('inf')
        decode_time = float('inf')
        print('Unable to import pycrate.')
    except Exception as e:
        encode_time = float('inf')
        decode_time = float('inf')
        print('pycrate error:', str(e))

    return encode_time, decode_time 
开发者ID:eerimoq,项目名称:asn1tools,代码行数:32,代码来源:ber.py

示例14: _get_private_key

# 需要导入模块: from pyasn1.codec.ber import decoder [as 别名]
# 或者: from pyasn1.codec.ber.decoder import decode [as 别名]
def _get_private_key(private_key_pkcs8_text):
  """Get an RSA private key object from a pkcs8 representation."""

  der = rsa.pem.load_pem(private_key_pkcs8_text, 'PRIVATE KEY')
  asn1_private_key, _ = decoder.decode(der, asn1Spec=PrivateKeyInfo())
  return rsa.PrivateKey.load_pkcs1(
      asn1_private_key.getComponentByName('privateKey').asOctets(),
      format='DER') 
开发者ID:mortcanty,项目名称:earthengine,代码行数:10,代码来源:service_account.py

示例15: recv

# 需要导入模块: from pyasn1.codec.ber import decoder [as 别名]
# 或者: from pyasn1.codec.ber.decoder import decode [as 别名]
def recv(self):
        REQUEST_SIZE = 8192
        data = ''
        done = False
        while not done:
            recvData = self._socket.recv(REQUEST_SIZE)
            if len(recvData) < REQUEST_SIZE:
                done = True
            data += recvData

        response = []
        while len(data) > 0:
            try:
                message, remaining = decoder.decode(data, asn1Spec=LDAPMessage())
            except SubstrateUnderrunError:
                # We need more data
                remaining = data + self._socket.recv(REQUEST_SIZE)
            else:
                if message['messageID'] == 0:  # unsolicited notification
                    name = message['protocolOp']['extendedResp']['responseName'] or message['responseName']
                    notification = KNOWN_NOTIFICATIONS.get(name, "Unsolicited Notification '%s'" % name)
                    if name == NOTIFICATION_DISCONNECT:  # Server has disconnected
                        self.close()
                    raise LDAPSessionError(
                        error=int(message['protocolOp']['extendedResp']['resultCode']),
                        errorString='%s -> %s: %s' % (notification,
                                                      message['protocolOp']['extendedResp']['resultCode'].prettyPrint(),
                                                      message['protocolOp']['extendedResp']['diagnosticMessage'])
                    )
                response.append(message)
            data = remaining

        self._messageId += 1
        return response 
开发者ID:joxeankoret,项目名称:CVE-2017-7494,代码行数:36,代码来源:ldap.py


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