本文整理汇总了Python中pyasn1.codec.ber.encoder.encode方法的典型用法代码示例。如果您正苦于以下问题:Python encoder.encode方法的具体用法?Python encoder.encode怎么用?Python encoder.encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyasn1.codec.ber.encoder
的用法示例。
在下文中一共展示了encoder.encode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_dbman_msg
# 需要导入模块: from pyasn1.codec.ber import encoder [as 别名]
# 或者: from pyasn1.codec.ber.encoder import encode [as 别名]
def send_dbman_msg(self, opcode, msg):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((self.target_ip, self.dbman_port))
encodedMsg = encoder.encode(msg, defMode=True)
msgLen = len(encodedMsg)
values = (opcode, msgLen, encodedMsg)
s = struct.Struct(">ii%ds" % msgLen)
packed_data = s.pack(*values)
sock.send(packed_data)
res = sock.recv(1024)
if res is not None:
print "Received 10002 response..."
sock.close()
示例2: _handleControls
# 需要导入模块: from pyasn1.codec.ber import encoder [as 别名]
# 或者: from pyasn1.codec.ber.encoder import encode [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
示例3: check_binary_sig
# 需要导入模块: from pyasn1.codec.ber import encoder [as 别名]
# 或者: from pyasn1.codec.ber.encoder import encode [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
示例4: updateusernameinencpart
# 需要导入模块: from pyasn1.codec.ber import encoder [as 别名]
# 或者: from pyasn1.codec.ber.encoder import encode [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
示例5: getInternalValue
# 需要导入模块: from pyasn1.codec.ber import encoder [as 别名]
# 或者: from pyasn1.codec.ber.encoder import encode [as 别名]
def getInternalValue(self, sout, parent):
"""
Return the internal value of this date element. This
value comes before any modifications such as packing,
padding, truncating, etc.
For Numbers this is the python int value.
"""
if parent is None:
return u""
value = ""
for c in self:
if isinstance(c, DataElement):
value = c.getValue()
break
if self.xmlNamespace is not None:
attrib = "{%s}%s" % (self.xmlNamespace, self.attributeName)
else:
attrib = self.attributeName
parent.set(attrib, value.decode('latin-1').encode('utf8'))
return None
示例6: fingerprint
# 需要导入模块: from pyasn1.codec.ber import encoder [as 别名]
# 或者: from pyasn1.codec.ber.encoder import encode [as 别名]
def fingerprint(self):
"""
Get the user presentation of the fingerprint of this L{Key}. As
described by U{RFC 4716 section
4<http://tools.ietf.org/html/rfc4716#section-4>}::
The fingerprint of a public key consists of the output of the MD5
message-digest algorithm [RFC1321]. The input to the algorithm is
the public key data as specified by [RFC4253]. (...) The output
of the (MD5) algorithm is presented to the user as a sequence of 16
octets printed as hexadecimal with lowercase letters and separated
by colons.
@since: 8.2
@return: the user presentation of this L{Key}'s fingerprint, as a
string.
@rtype: L{str}
"""
return ':'.join([x.encode('hex') for x in md5(self.blob()).digest()])
示例7: _preparePingPongData
# 需要导入模块: from pyasn1.codec.ber import encoder [as 别名]
# 或者: from pyasn1.codec.ber.encoder import encode [as 别名]
def _preparePingPongData(reqType, msgId, serial, secret):
msg = Message()
msg['version'] = PROTOCOL_VERSION
msg['msg-id'] = msgId
msg['content-id'] = reqType
if msg['content-id'] == MSG_TYPE_PING:
r = Ping()
elif msg['content-id'] == MSG_TYPE_PONG:
r = Pong()
else:
raise SnmpfwdError('not a ping-pong message')
r['serial'] = serial
msg['payload'] = encoder.encode(r)
if secret:
msg['payload'] = crypto.encrypt(secret, encoder.encode(r))
else:
msg['payload'] = encoder.encode(r)
return encoder.encode(msg)
示例8: compress_payload
# 需要导入模块: from pyasn1.codec.ber import encoder [as 别名]
# 或者: from pyasn1.codec.ber.encoder import encode [as 别名]
def compress_payload(payload):
cdata_attr = CompressedDataAttr()
cdata_attr.setComponentByName('compressionAlgorithm', (1, 2, 840, 113549, 1, 9, 16, 3, 8))
cdata_payload = CompressedDataPayload()
cdata_payload.setComponentByName('content-type', (1, 2, 840, 113549, 1, 7, 1))
cdata_payload.setComponentByName('content',
Content(univ.OctetString(hexValue=zlib.compress(payload).encode('hex'))))
cdata = CompressedData()
cdata.setComponentByName('version', 0)
cdata.setComponentByName('attributes', cdata_attr)
cdata.setComponentByName('payload', cdata_payload)
cdata_main = CompressedDataMain()
cdata_main.setComponentByName('id-ct-compressedData', (1, 2, 840, 113549, 1, 9, 16, 1, 9))
cdata_main.setComponentByName('compressedData', cdata)
return encoder.encode(cdata_main, defMode=False).encode('base64')
示例9: send
# 需要导入模块: from pyasn1.codec.ber import encoder [as 别名]
# 或者: from pyasn1.codec.ber.encoder import encode [as 别名]
def send(self, request, controls=None):
message = LDAPMessage()
message['messageID'] = self._messageId
message['protocolOp'].setComponentByType(request.getTagSet(), request)
if controls is not None:
message['controls'].setComponents(*controls)
data = encoder.encode(message)
return self._socket.sendall(data)
示例10: encodeControlValue
# 需要导入模块: from pyasn1.codec.ber import encoder [as 别名]
# 或者: from pyasn1.codec.ber.encoder import encode [as 别名]
def encodeControlValue(self):
self['controlValue'] = encoder.encode(SimplePagedResultsControlValue().setComponents(self._size, self._cookie))
示例11: encodeControlValue
# 需要导入模块: from pyasn1.codec.ber import encoder [as 别名]
# 或者: from pyasn1.codec.ber.encoder import encode [as 别名]
def encodeControlValue(self):
self['controlValue'] = encoder.encode(
SDFlagsControlValue().setComponents(self.flags))
示例12: fromString
# 需要导入模块: from pyasn1.codec.ber import encoder [as 别名]
# 或者: from pyasn1.codec.ber.encoder import encode [as 别名]
def fromString(cls, data, type=None, passphrase=None):
"""
Return a Key object corresponding to the string data.
type is optionally the type of string, matching a _fromString_*
method. Otherwise, the _guessStringType() classmethod will be used
to guess a type. If the key is encrypted, passphrase is used as
the decryption key.
@type data: L{bytes}
@param data: The key data.
@type type: L{str} or L{None}
@param type: A string describing the format the key data is in, or
L{None} to attempt detection of the type.
@type passphrase: L{bytes} or L{None}
@param passphrase: The passphrase the key is encrypted with, or L{None}
if there is no encryption.
@rtype: L{Key}
@return: The loaded key.
"""
if isinstance(data, unicode):
data = data.encode("utf-8")
if isinstance(passphrase, unicode):
passphrase = passphrase.encode("utf-8")
if type is None:
type = cls._guessStringType(data)
if type is None:
raise BadKeyError('cannot guess the type of %r' % (data,))
method = getattr(cls, '_fromString_%s' % (type.upper(),), None)
if method is None:
raise BadKeyError('no _fromString method for %s' % (type,))
if method.__code__.co_argcount == 2: # No passphrase
if passphrase:
raise BadKeyError('key not encrypted')
return method(data)
else:
return method(data, passphrase)
示例13: sshType
# 需要导入模块: from pyasn1.codec.ber import encoder [as 别名]
# 或者: from pyasn1.codec.ber.encoder import encode [as 别名]
def sshType(self):
"""
Get the type of the object we wrap as defined in the SSH protocol,
defined in RFC 4253, Section 6.6. Currently this can only be b'ssh-rsa',
b'ssh-dss' or b'ecdsa-sha2-[identifier]'.
identifier is the standard NIST curve name
@return: The key type format.
@rtype: L{bytes}
"""
if self.type() == 'EC':
return b'ecdsa-sha2-' + _secToNist[self._keyObject.curve.name.encode('ascii')]
else:
return {'RSA': b'ssh-rsa', 'DSA': b'ssh-dss'}[self.type()]
示例14: toString
# 需要导入模块: from pyasn1.codec.ber import encoder [as 别名]
# 或者: from pyasn1.codec.ber.encoder import encode [as 别名]
def toString(self, type, extra=None):
"""
Create a string representation of this key. If the key is a private
key and you want the representation of its public key, use
C{key.public().toString()}. type maps to a _toString_* method.
@param type: The type of string to emit. Currently supported values
are C{'OPENSSH'}, C{'LSH'}, and C{'AGENTV3'}.
@type type: L{str}
@param extra: Any extra data supported by the selected format which
is not part of the key itself. For public OpenSSH keys, this is
a comment. For private OpenSSH keys, this is a passphrase to
encrypt with.
@type extra: L{bytes} or L{unicode} or L{None}
@rtype: L{bytes}
"""
if isinstance(extra, unicode):
extra = extra.encode("utf-8")
method = getattr(self, '_toString_%s' % (type.upper(),), None)
if method is None:
raise BadKeyError('unknown key type: %s' % (type,))
if method.__code__.co_argcount == 2:
return method(extra)
else:
return method()
示例15: custom_asn1_marshal
# 需要导入模块: from pyasn1.codec.ber import encoder [as 别名]
# 或者: from pyasn1.codec.ber.encoder import encode [as 别名]
def custom_asn1_marshal(values):
return encode(values, asn1Spec=Record())