本文整理汇总了Python中pyasn1.codec.ber.encoder.encode函数的典型用法代码示例。如果您正苦于以下问题:Python encode函数的具体用法?Python encode怎么用?Python encode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了encode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testBadValueType
def testBadValueType(self):
try:
encoder.encode('not an Asn1Item')
except PyAsn1Error:
pass
else:
assert 0, 'Invalid value type accepted'
示例2: testImpossible1
def testImpossible1(self):
try:
encoder.encode(univ.ObjectIdentifier((3,1,2)))
except PyAsn1Error:
pass
else:
assert 0, 'impossible leading arc tolerated'
示例3: testImpossible2
def testImpossible2(self):
try:
encoder.encode(univ.ObjectIdentifier((0,)))
except PyAsn1Error:
pass
else:
assert 0, 'single arc OID tolerated'
示例4: testImpossible4
def testImpossible4(self):
try:
encoder.encode(univ.ObjectIdentifier((1,40)))
except PyAsn1Error:
pass
else:
assert 0, 'second arc overflow tolerated'
示例5: testEmpty
def testEmpty(self):
try:
encoder.encode(self.s)
except PyAsn1Error:
pass
else:
assert 0, 'encoded unset choice'
示例6: testEmpty
def testEmpty(self):
s = univ.Choice()
try:
encoder.encode(s)
except PyAsn1Error:
pass
else:
assert 0, 'encoded unset choice'
示例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))
示例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)
示例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'
示例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
示例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 )
示例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
示例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))
示例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))
示例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))