本文整理汇总了Python中xdrlib.Packer.get_buffer方法的典型用法代码示例。如果您正苦于以下问题:Python Packer.get_buffer方法的具体用法?Python Packer.get_buffer怎么用?Python Packer.get_buffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xdrlib.Packer
的用法示例。
在下文中一共展示了Packer.get_buffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: secure_data
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import get_buffer [as 别名]
def secure_data(self, cred, data):
log_gss.debug("secure_data(%r)" % cred)
cred = cred.body
if cred.service == rpc_gss_svc_none or \
cred.gss_proc in (RPCSEC_GSS_INIT, RPCSEC_GSS_CONTINUE_INIT):
return data
p = Packer()
context = self._get_context(cred.handle)
try:
if cred.service == rpc_gss_svc_integrity:
# data = opaque[gss_seq_num+data] + opaque[checksum]
p.pack_uint(cred.seq_num)
data = p.get_buffer() + data
token = context.getMIC(data) # XXX BUG set qop
p.reset()
p.pack_opaque(data)
p.pack_opaque(token)
data = p.get_buffer()
elif cred.service == rpc_gss_svc_privacy:
# data = opaque[wrap([gss_seq_num+data])]
p.pack_uint(cred.seq_num)
data = p.get_buffer() + data
token = context.wrap(data) # XXX BUG set qop
p.reset()
p.pack_opaque(token)
data = p.get_buffer()
else:
# Can't get here, but doesn't hurt
log_gss.error("Unknown service %i for RPCSEC_GSS" % cred.service)
except gssapi.Error as e:
# XXX What now?
log_gss.warn("secure_data: gssapi call returned %s" % e.name)
raise
return data
示例2: pack
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import get_buffer [as 别名]
def pack(self, values):
metric = {
'hostname': '',
'spoof': 0,
'units': '',
'slope': 'both',
'tmax': 60,
'dmax': 0
}
metric.update(values)
if metric.get('spoof', False):
metric['spoof'] = 1
else:
metric['spoof'] = 0
metric['slope'] = SLOPE[metric['slope']]
for key in ('name', 'value', 'type'):
if key not in metric:
raise KeyError("Missing {0}".format(key))
if metric['type'] not in ('string', 'int8', 'uint8', 'int16', 'uint16', 'int32', 'uint32', 'float', 'double'):
raise TypeError("Invalid metric type")
convert = lambda v: v.encode() if isinstance(v, str) else v
metric = {key: convert(value) for key, value in metric.items()}
# Metadata
meta = Packer()
meta.pack_int(128)
meta.pack_string(metric['hostname'])
meta.pack_string(metric['name'])
meta.pack_int(int(metric['spoof']))
meta.pack_string(metric['type'])
meta.pack_string(metric['name'])
meta.pack_string(metric['units'])
meta.pack_int(metric['slope'])
meta.pack_uint(int(metric['tmax']))
meta.pack_uint(int(metric['dmax']))
# Group support
if 'group' in metric:
meta.pack_int(1)
meta.pack_string(b"GROUP")
meta.pack_string(metric['group'])
else:
meta.pack_int(0)
# Data
data = Packer()
data.pack_int(128 + 5)
data.pack_string(metric['hostname'])
data.pack_string(metric['name'])
data.pack_int(int(metric['spoof']))
data.pack_string(b"%s")
data.pack_string(bytes(metric['value']))
return meta.get_buffer(), data.get_buffer()
示例3: __store_key
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import get_buffer [as 别名]
def __store_key(self, full_key):
self.extres.db_env.nosyncerror_txn_checkpoint(MINS_BETWEEN_DB_CHECKPOINTS)
trans = self.extres.db_env.txn_begin()
try:
key_id = sha(full_key).digest()
if self.extres.counterparty_map.get(key_id, txn=trans, flags=db.DB_RMW) is not None :
return
id_in_rep = randsource.get(SIZE_OF_UNIQS)
id_in = _mix_counterparties(self.__my_public_key_id, key_id, id_in_rep)
id_out_rep = randsource.get(SIZE_OF_UNIQS)
id_out = _mix_counterparties(self.__my_public_key_id, key_id, id_out_rep)
key_seed = randsource.get(SIZE_OF_UNIQS)
sr = HashRandom.SHARandom(_mix_counterparties(self.__my_public_key_id, key_id, key_seed))
symmetric_key = sr.get(SIZE_OF_SYMMETRIC_KEYS)
iv = randsource.get(8)
p = Packer()
p.pack_fstring(SIZE_OF_UNIQS, key_id)
x = MojoKey.makeRSAPublicKeyMVFromSexpString(full_key)
padded = '\000' + cryptutil.oaep(symmetric_key, len(self.__key.get_modulus()) - 1) # The prepended 0 byte is to make modval happy.
assert len(padded) == len(self.__key.get_modulus())
x.set_value_string(padded)
x.encrypt()
p.pack_string(x.get_value())
p.pack_fstring(8, iv)
penc = Packer()
penc.pack_string(self.__key.get_modulus())
penc.pack_fstring(SIZE_OF_UNIQS, id_out_rep)
penc.pack_fstring(SIZE_OF_UNIQS, id_in_rep)
penc.pack_fstring(SIZE_OF_UNIQS, key_seed)
# debugprint("------ ------ ------ ------ hmachish(key=%s, message=%s)\n" % (`symmetric_key`, `penc.get_buffer()`))
hashie = cryptutil.hmacish(key=symmetric_key, message=penc.get_buffer())
paddedhashie = '\000' + cryptutil.oaep(hashie, len(self.__key.get_modulus()) - 1) # The prepended 0 byte is to make modval happy.
assert len(paddedhashie) == len(self.__key.get_modulus())
self.__key.set_value_string(paddedhashie)
self.__key.sign()
signature = self.__key.get_value()
penc.pack_fstring(len(signature), signature)
encrypted = tripledescbc.new(symmetric_key).encrypt(iv, penc.get_buffer())
p.pack_string(encrypted)
header = p.get_buffer()
self.extres.counterparty_map.put(key_id, dumps([id_in, id_out, symmetric_key, header, full_key], 1), txn=trans)
self.extres.session_map.put(id_in, full_key, txn=trans)
trans.commit()
trans = None
finally:
if trans is not None:
trans.abort()
示例4: __call__
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import get_buffer [as 别名]
def __call__(self, arg):
msg = rpc_msg(xid=self.xid,
body=rpc_msg.body(mtype=msg_type.CALL,
cbody=call_body(rpcvers=2,
prog=self.prog,
vers=self.vers,
proc=self.procedure.procedure_id,
cred=opaque_auth.NONE(),
verf=opaque_auth.NONE())))
from xdrlib import Packer
packer = Packer()
msg.pack(packer)
print("msg: %s" % packer.get_buffer())
arg.pack(packer)
print("msg: %s" % packer.get_buffer())
示例5: gmetric_meta
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import get_buffer [as 别名]
def gmetric_meta(NAME, TYPE, UNITS, SLOPE, TMAX, DMAX, EXTRAS=None):
"""
Arguments are in all upper-case to match XML
"""
packer = Packer()
packer.pack_int(128) # "gmetadata_full"
packer.pack_string('nickg-macbook.local')
packer.pack_string(NAME)
packer.pack_bool(False)
packer.pack_string(TYPE)
packer.pack_string(NAME)
packer.pack_string(UNITS)
packer.pack_int(slope_str2int[SLOPE]) # map slope string to int
packer.pack_uint(int(TMAX))
packer.pack_uint(int(DMAX))
if EXTRAS is None:
packer.pack_uint(0)
else:
packer.pack_uint(len(EXTRAS))
for k,v in EXTRAS.iteritems():
packer.pack_string(k)
packer.pack_string(v)
return packer.get_buffer()
示例6: gmetric_write_meta
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import get_buffer [as 别名]
def gmetric_write_meta(HOST, NAME, TYPE, UNITS, SLOPE, TMAX, DMAX, GROUP):
"""
Arguments are in all upper-case to match XML
"""
packer = Packer()
"""
ganglia message formats
gmetadata_full = 128,
gmetric_ushort = 129,
gmetric_short = 130,
gmetric_int = 131,
gmetric_uint = 132,
gmetric_string = 133,
gmetric_float = 134,
gmetric_double = 135
"""
packer.pack_int(128) # type gmetadata_full
packer.pack_string(HOST)
packer.pack_string(NAME)
packer.pack_int(0)
packer.pack_string(TYPE)
packer.pack_string(NAME)
packer.pack_string(UNITS)
packer.pack_int(slope_str2int[SLOPE]) # map slope string to int
packer.pack_int(TMAX)
packer.pack_int(DMAX)
packer.pack_int(1)
packer.pack_string("GROUP")
packer.pack_string(GROUP)
return packer.get_buffer()
示例7: gmetric_write
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import get_buffer [as 别名]
def gmetric_write(NAME, VAL, TYPE, UNITS, SLOPE, TMAX, DMAX, GROUP, SPOOF):
"""
Arguments are in all upper-case to match XML
"""
packer = Packer()
HOSTNAME="test"
if SPOOF == "":
SPOOFENABLED=0
else :
SPOOFENABLED=1
# Meta data about a metric
packer.pack_int(128)
if SPOOFENABLED == 1:
packer.pack_string(SPOOF)
else:
packer.pack_string(HOSTNAME)
packer.pack_string(NAME)
packer.pack_int(SPOOFENABLED)
packer.pack_string(TYPE)
packer.pack_string(NAME)
packer.pack_string(UNITS)
packer.pack_int(slope_str2int[SLOPE]) # map slope string to int
packer.pack_uint(int(TMAX))
packer.pack_uint(int(DMAX))
# Magic number. Indicates number of entries to follow. Put in 1 for GROUP
if GROUP == "":
packer.pack_int(0)
else:
packer.pack_int(1)
packer.pack_string("GROUP")
packer.pack_string(GROUP)
# Actual data sent in a separate packet
data = Packer()
data.pack_int(128+5)
if SPOOFENABLED == 1:
data.pack_string(SPOOF)
else:
data.pack_string(HOSTNAME)
data.pack_string(NAME)
data.pack_int(SPOOFENABLED)
data.pack_string("%s")
data.pack_string(str(VAL))
return ( packer.get_buffer() , data.get_buffer() )
示例8: gmetric_value
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import get_buffer [as 别名]
def gmetric_value(NAME, VAL):
packer = Packer()
packer.pack_int(128+5) # string
packer.pack_string('nickg-macbook.local')
packer.pack_string(NAME)
packer.pack_bool(False)
packer.pack_string('%s')
packer.pack_string(VAL)
return packer.get_buffer()
示例9: _mix_counterparties
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import get_buffer [as 别名]
def _mix_counterparties(cp1, cp2, data):
assert type(cp1) == type('')
assert type(cp2) == type('')
assert type(data) == type('')
p = Packer()
p.pack_string(cp1)
p.pack_string(cp2)
p.pack_string(data)
return sha(p.get_buffer()).digest()
示例10: send_metareq
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import get_buffer [as 别名]
def send_metareq(self, values, address):
packer = Packer()
packer.pack_int(136)
if not values['spoof']:
packer.pack_string(address[0])
else:
packer.pack_string(":".join((address[0], values['hostname'])))
packer.pack_string(values['metricname'])
packer.pack_bool(values['spoof'])
self.transport.write(packer.get_buffer(),address)
return
示例11: send
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import get_buffer [as 别名]
def send(self):
''' packs the Header vars into a buffer '''
unp = Packer()
unp.pack_uint(self.magic)
unp.pack_uint(self.version)
unp.pack_uint(self.msgid)
unp.pack_uint(self.msglen)
unp.pack_uint(0) # reply_addr y reply_port
unp.pack_uint(0) # reply_addr y reply_port
unp.pack_fstring(8, self.callsign.encode())
return unp.get_buffer()
示例12: gmetric_write
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import get_buffer [as 别名]
def gmetric_write(ID, HOST, NAME, VAL):
"""
Arguments are in all upper-case to match XML
"""
packer = Packer()
packer.pack_int(133)
packer.pack_string(HOST)
packer.pack_string(NAME)
packer.pack_int(0)
packer.pack_string("%s")
packer.pack_string(str(VAL))
return packer.get_buffer()
示例13: _bytes_from_length
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import get_buffer [as 别名]
def _bytes_from_length(len, closing):
"""
The RPC standard calls for the length of a message to be sent as the least
significant 31 bits of an XDR encoded unsigned integer. The most
significant bit encodes a True/False bit which indicates that this message
will be the last.
"""
assert 0 <= len < 2**31
from xdrlib import Packer
if closing:
len += 2**31
packer = Packer()
packer.pack_uint(len)
return packer.get_buffer()
示例14: gmetric_write
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import get_buffer [as 别名]
def gmetric_write(NAME, VAL, TYPE, UNITS, SLOPE, TMAX, DMAX, GROUP, SPOOF):
packer = Packer()
HOSTNAME = 'test'
if SPOOF == '':
SPOOFENABLED = 0
else:
SPOOFENABLED = 1
packer.pack_int(128)
if SPOOFENABLED == 1:
packer.pack_string(SPOOF)
else:
packer.pack_string(HOSTNAME)
packer.pack_string(NAME)
packer.pack_int(SPOOFENABLED)
packer.pack_string(TYPE)
packer.pack_string(NAME)
packer.pack_string(UNITS)
packer.pack_int(slope_str2int[SLOPE])
packer.pack_uint(int(TMAX))
packer.pack_uint(int(DMAX))
if GROUP == '':
packer.pack_int(0)
else:
packer.pack_int(1)
packer.pack_string('GROUP')
packer.pack_string(GROUP)
data = Packer()
data.pack_int(133)
if SPOOFENABLED == 1:
data.pack_string(SPOOF)
else:
data.pack_string(HOSTNAME)
data.pack_string(NAME)
data.pack_int(SPOOFENABLED)
data.pack_string('%s')
data.pack_string(str(VAL))
return (packer.get_buffer(), data.get_buffer())
示例15: __init__
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import get_buffer [as 别名]
def __init__(self, stamp, machinename, uid, gid, gids):
if len(machinename) > 255:
raise SecError("machinename %s is too long" % machinename)
if len(gids) > 16:
raise SecError("gid array too long: %s" % str(gids))
try:
p = Packer()
p.pack_int(stamp)
p.pack_string(machinename)
p.pack_uint(uid)
p.pack_uint(gid)
p.pack_array(gids, p.pack_uint)
self.cred = p.get_buffer()
except Error, e:
raise SecError("Packing error: %s", str(e))