本文整理汇总了Python中pyasn1.codec.ber.encoder.encode函数的典型用法代码示例。如果您正苦于以下问题:Python encode函数的具体用法?Python encode怎么用?Python encode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了encode函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: testBadValueType
def testBadValueType(self):
try:
encoder.encode('not an Asn1Item')
except PyAsn1Error:
pass
else:
assert 0, 'Invalid value type accepted'
开发者ID:anthrotype,项目名称:pyasn1,代码行数:7,代码来源:test_encoder.py
示例2: testImpossible1
def testImpossible1(self):
try:
encoder.encode(univ.ObjectIdentifier((3,1,2)))
except PyAsn1Error:
pass
else:
assert 0, 'impossible leading arc tolerated'
开发者ID:coruus,项目名称:pyasn1,代码行数:7,代码来源:test_encoder.py
示例3: testImpossible2
def testImpossible2(self):
try:
encoder.encode(univ.ObjectIdentifier((0,)))
except PyAsn1Error:
pass
else:
assert 0, 'single arc OID tolerated'
开发者ID:coruus,项目名称:pyasn1,代码行数:7,代码来源:test_encoder.py
示例4: testImpossible4
def testImpossible4(self):
try:
encoder.encode(univ.ObjectIdentifier((1,40)))
except PyAsn1Error:
pass
else:
assert 0, 'second arc overflow tolerated'
开发者ID:coruus,项目名称:pyasn1,代码行数:7,代码来源:test_encoder.py
示例5: testEmpty
def testEmpty(self):
try:
encoder.encode(self.s)
except PyAsn1Error:
pass
else:
assert 0, 'encoded unset choice'
开发者ID:andviro,项目名称:pyasn1,代码行数:7,代码来源:test_encoder.py
示例6: testEmpty
def testEmpty(self):
s = univ.Choice()
try:
encoder.encode(s)
except PyAsn1Error:
pass
else:
assert 0, 'encoded unset choice'
开发者ID:catapult-project,项目名称:catapult,代码行数:8,代码来源:test_encoder.py
示例7: set_ap_title
def set_ap_title(self, ap_title):
if not hasattr(self, '_ap_title'):
raise Exception(self.__class__.__name__ + ' does not support the ap_title element')
if isinstance(ap_title, univ.ObjectIdentifier):
self._ap_title = ber_encoder.encode(ap_title)
if isinstance(ap_title, str):
self._ap_title = ap_title
else:
self._ap_title = ber_encoder.encode(univ.ObjectIdentifier(ap_title))
开发者ID:securestate,项目名称:termineter,代码行数:9,代码来源:data.py
示例8: updatepac
def updatepac(key, rawticket, pac, debug=False, verbose=False):
# attempt decoding of ticket
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)
if decserverticketraw == None:
raise ValueError('Unable to decrypt ticket. Invalid key.')
elif verbose:
print 'Decryption successful'
decserverticket, extra = decoder.decode(decserverticketraw)
#for i in range(len(decserverticket[3])):
# print '---%i---' % i
# print decserverticket[3][i]
# have two here because I was using one to verify that the rewrite matched
# This stuff should be removed, if it is still here Tim forgot...again
origdecserverticket, extra = decoder.decode(decserverticketraw)
# change the validity times in the server ticket
updatetimestampsserverticket(decserverticket, str(decserverticket[5]), str(decserverticket[6]), str(decserverticket[7]), str(decserverticket[8]))
adifrelevant, extra = decoder.decode(decserverticket[9][0][1])
chksum = kerberos.chksum(key, '\x11\x00\x00\x00', pac)
#print 'newchecksum: %s' % chksum.encode('hex')
# repair server checksum
newpac = pac[:-44] + chksum + pac[-28:]
# rebuild AD-IF-RELEVANT
#print adifrelevant
#print dir(adifrelevant.getComponentByPosition(0).getComponentByPosition(1))
adifrelevant.getComponentByPosition(0).getComponentByPosition(1)._value = newpac
#print adifrelevant
decserverticket.getComponentByPosition(9).getComponentByPosition(0).getComponentByPosition(1)._value = encoder.encode(adifrelevant)
# put the ticket back together again
newencserverticket = kerberos.encrypt(key, 2, encoder.encode(decserverticket), nonce)
ramticket.getComponentByPosition(2).getComponentByPosition(0).getComponentByPosition(3).getComponentByPosition(2)._value = newencserverticket
#print decserverticket
return encoder.encode(ramticket)
开发者ID:KorayAgaya,项目名称:kerberoast,代码行数:55,代码来源:kerberoast.py
示例9: testEncodeOpenTypeIncompatibleType
def testEncodeOpenTypeIncompatibleType(self):
self.s.clear()
self.s[0] = 2
self.s[1] = univ.ObjectIdentifier('1.3.6')
try:
encoder.encode(self.s, asn1Spec=self.s)
except PyAsn1Error:
assert False, 'incompatible open type tolerated'
开发者ID:catapult-project,项目名称:catapult,代码行数:11,代码来源:test_encoder.py
示例10: extended_operation
def extended_operation(request_name,
request_value=None):
request = ExtendedRequest()
request['requestName'] = RequestName(request_name)
if request_value and isinstance(request_value, Asn1Item):
request['requestValue'] = RequestValue(encoder.encode(request_value))
elif str != bytes and isinstance(request_value, (bytes, bytearray)): # in python3 doesn't try to encode a byte value
request['requestValue'] = request_value
elif request_value: # tries to encode as a octet string
request['requestValue'] = RequestValue(encoder.encode(OctetString(str(request_value))))
# elif request_value is not None:
# raise LDAPExtensionError('unable to encode value for extended operation')
return request
开发者ID:TLoebner,项目名称:ldap3-debian,代码行数:13,代码来源:extended.py
示例11: generateResponseMsg
def generateResponseMsg(
self,
snmpEngine,
messageProcessingModel,
globalData,
maxMessageSize,
securityModel,
securityEngineID,
securityName,
securityLevel,
scopedPDU,
securityStateReference
):
# rfc2576: 5.2.2
msg, = globalData
contextEngineId, contextName, pdu = scopedPDU
cachedSecurityData = self._cache.pop(securityStateReference)
communityName = cachedSecurityData['communityName']
debug.logger & debug.flagSM and debug.logger('generateResponseMsg: recovered community %r by securityStateReference %s' % (communityName, securityStateReference))
msg.setComponentByPosition(1, communityName)
msg.setComponentByPosition(2)
msg.getComponentByPosition(2).setComponentByType(
pdu.tagSet, pdu, verifyConstraints=False
)
debug.logger & debug.flagMP and debug.logger('generateResponseMsg: %s' % (msg.prettyPrint(),))
wholeMsg = encoder.encode(msg)
return ( communityName, wholeMsg )
开发者ID:chilikk,项目名称:snmp-course-project,代码行数:31,代码来源:rfc2576.py
示例12: encode_keys
def encode_keys(keys):
"""
Encode into asn.1 format given kerberos keys which must be an array of
dictionaries with the following keys: type, value, salt
"""
ret = []
if not isinstance(keys, list):
raise ValueError("Keys parameter must be a list of dict")
for key in keys:
if not isinstance(key, dict):
raise ValueError("Each key must be a dict")
if 'type' not in key or 'value' not in key:
raise ValueError("A key must have 'type' and 'value' entries")
k = Key()
# mkvno
k.setComponentByPosition(0, 0)
# key
ek = k.setComponentByPosition(1).getComponentByPosition(1)
ek.setComponentByPosition(0, key['type'])
ek.setComponentByPosition(1, key['value'])
if 'salt' in key:
# salt
salt = k.setComponentByPosition(2).getComponentByPosition(2)
salt.setComponentByPosition(0, 3)
salt.setComponentByPosition(1, key['salt'])
salt.setComponentByPosition(2, '')
# Encode and add it to ret values
ret.append(encoder.encode(k))
return ret
开发者ID:eonpatapon,项目名称:mmc,代码行数:29,代码来源:k5key_asn1.py
示例13: BuildSend_DoneMsg
def BuildSend_DoneMsg(addr, sys_name, comm_string, dst_ipaddr, snmp_sock):
global startedAt
done_oid, done_val = BASE_OID + [14,52987], SNMPModule.Integer(1)
doneMsg = Build_SetPDU(done_oid, done_val, comm_string)
startedAt=time()
#Send_CopyPDU(doneMsg, addr)
snmp_sock.sendto(encoder.encode(doneMsg), (addr, 161))
开发者ID:az0ne,项目名称:python_scrirpts,代码行数:7,代码来源:cisco_config_retrieval.py
示例14: BuildSend_DstFileNameMsg
def BuildSend_DstFileNameMsg(addr, sys_name, comm_string, dst_ipaddr, snmp_sock):
global startedAt
dstFname_oid, dstFname_val = BASE_OID + [6,52987], SNMPModule.OctetString(sys_name+".CiscoConfig")
dstFnameMsg = Build_SetPDU(dstFname_oid, dstFname_val, comm_string)
startedAt=time()
#Send_CopyPDU(dstFnameMsg, addr)
snmp_sock.sendto(encoder.encode(dstFnameMsg), (addr, 161))
开发者ID:az0ne,项目名称:python_scrirpts,代码行数:7,代码来源:cisco_config_retrieval.py
示例15: BuildSend_DstAddrMsg
def BuildSend_DstAddrMsg(addr, sys_name, comm_string, dst_ipaddr, snmp_sock):
global startedAt
dstAddr_oid, dstAddr_val = BASE_OID + [5,52987], SNMPModule.IpAddress(dst_ipaddr)
addrMsg = Build_SetPDU(dstAddr_oid, dstAddr_val, comm_string)
startedAt=time()
#Send_CopyPDU(addrMsg, addr)
snmp_sock.sendto(encoder.encode(addrMsg), (addr, 161))
开发者ID:az0ne,项目名称:python_scrirpts,代码行数:7,代码来源:cisco_config_retrieval.py
示例16: encodeData
def encodeData(self, recDict, st, et):
toplevel = TopLevel()
smsRecord = SmsRecord()
for key in recDict.keys():
if ":" not in key:
if ('TimeStamp' in key):
continue
smsRecord.setComponentByName('%s' %(key), recDict[key])
else:
address = Address()
(name, addressType, npi, addressDigit) = recDict[key].split(':')
address.setComponentByName('addressType', addressType)
address.setComponentByName('npi', npi)
address.setComponentByName('addressDigit', addressDigit)
smsRecord.setComponentByName('%s' %(name), address)
terminateTimeStamp = random.randint(st,et)
termTS = self.convertTS(terminateTimeStamp)
smsRecord.setComponentByName('terminateTimeStamp', termTS)
submitTimeStamp = random.randint(st, terminateTimeStamp)
subTS = self.convertTS(submitTimeStamp)
smsRecord.setComponentByName('submitTimeStamp', subTS)
toplevel.setComponentByName('sMSRecord', smsRecord)
substrate = encoder.encode(toplevel,defMode=False,)
return substrate
开发者ID:cabhi,项目名称:SparkGraph,代码行数:26,代码来源:smdrGenerator.py
示例17: BuildSend_SrcFileMsg
def BuildSend_SrcFileMsg(addr, sys_name, comm_string, dst_ipaddr, snmp_sock):
global startedAt
srcFileType_oid, srcFT_val = BASE_OID + [3,52987], SNMPModule.Integer(4)
sftMsg = Build_SetPDU(srcFileType_oid, srcFT_val, comm_string)
startedAt=time()
#Send_CopyPDU(sftMsg, addr)
snmp_sock.sendto(encoder.encode(sftMsg), (addr, 161))
开发者ID:az0ne,项目名称:python_scrirpts,代码行数:7,代码来源:cisco_config_retrieval.py
示例18: generateRequestMsg
def generateRequestMsg(self, snmpEngine, messageProcessingModel,
globalData, maxMessageSize, securityModel,
securityEngineId, securityName, securityLevel,
scopedPDU):
msg, = globalData
contextEngineId, contextName, pdu = scopedPDU
# rfc2576: 5.2.3
communityName = self._sec2com(snmpEngine, securityName,
contextEngineId, contextName)
debug.logger & debug.flagSM and debug.logger('generateRequestMsg: using community %r for securityModel %r, securityName %r, contextEngineId %r contextName %r' % (communityName, securityModel, securityName, contextEngineId, contextName))
securityParameters = communityName
msg.setComponentByPosition(1, securityParameters)
msg.setComponentByPosition(2)
msg.getComponentByPosition(2).setComponentByType(
pdu.tagSet, pdu, verifyConstraints=False
)
debug.logger & debug.flagMP and debug.logger('generateRequestMsg: %s' % (msg.prettyPrint(),))
try:
return securityParameters, encoder.encode(msg)
except PyAsn1Error:
debug.logger & debug.flagMP and debug.logger('generateRequestMsg: serialization failure: %s' % sys.exc_info()[1])
raise error.StatusInformation(errorIndication=errind.serializationError)
开发者ID:437049211,项目名称:PyQYT,代码行数:29,代码来源:rfc2576.py
示例19: __init__
def __init__(self, data, timeout_func=None, receive_func=None, error_func=None):
self.__dict__.update(data)
self.timeout_func = timeout_func
self.receive_func = receive_func
self.error_func = error_func
headVars = [v2c.ObjectIdentifier(oid) for oid in
map(lambda oid: (int(i) for i in oid.split('.')), self.oid_keys)]
self.reqPDU = reqPDU = v2c.GetBulkRequestPDU()
v2c.apiBulkPDU.setDefaults(reqPDU)
v2c.apiBulkPDU.setNonRepeaters(reqPDU, self.non_repeaters)
v2c.apiBulkPDU.setMaxRepetitions(reqPDU, self.max_repetitions)
v2c.apiBulkPDU.setVarBinds(reqPDU, [(x, v2c.null) for x in headVars])
reqMsg = v2c.Message()
v2c.apiMessage.setDefaults(reqMsg)
v2c.apiMessage.setCommunity(reqMsg, self.community)
v2c.apiMessage.setPDU(reqMsg, reqPDU)
self.startedAt = time()
transportDispatcher = AsyncoreDispatcher()
transportDispatcher.registerRecvCbFun(self.cbRecvFun)
transportDispatcher.registerTimerCbFun(self.cbTimerFun)
transportDispatcher.registerTransport(udp.domainName, udp.UdpSocketTransport().openClientMode())
transportDispatcher.sendMessage(encoder.encode(reqMsg), udp.domainName, (self.network_address, self.port))
transportDispatcher.jobStarted(1)
transportDispatcher.runDispatcher()
transportDispatcher.closeDispatcher()
开发者ID:RahyabGroup,项目名称:PyFacil,代码行数:33,代码来源:bulk.py
示例20: send
def send(self, host, community, oid, value):
self.pMod.apiPDU.setDefaults(self.reqPDU)
self.pMod.apiPDU.setVarBinds(
self.reqPDU,
((oid, self.pMod.OctetString(value)),
)
)
# Build message
reqMsg = self.pMod.Message()
self.pMod.apiMessage.setDefaults(reqMsg)
self.pMod.apiMessage.setCommunity(reqMsg, community)
self.pMod.apiMessage.setPDU(reqMsg, self.reqPDU)
transportDispatcher = AsynsockDispatcher()
transportDispatcher.registerRecvCbFun(self.cbRecvFun)
transportDispatcher.registerTimerCbFun(self.cbTimerFun)
# UDP/IPv4
transportDispatcher.registerTransport(
udp.domainName, udp.UdpSocketTransport().openClientMode()
)
# Pass message to dispatcher
transportDispatcher.sendMessage(
encoder.encode(reqMsg), udp.domainName, (host, 161)
)
transportDispatcher.jobStarted(1)
# Dispatcher will finish as job#1 counter reaches zero
transportDispatcher.runDispatcher()
transportDispatcher.closeDispatcher()
开发者ID:gdumee,项目名称:LISA-PLUGINS-BBox,代码行数:32,代码来源:bbox.py
注:本文中的pyasn1.codec.ber.encoder.encode函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论