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


Python Packer.pack_fstring方法代码示例

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


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

示例1: send

# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_fstring [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()
开发者ID:bartacruz,项目名称:fgatc,代码行数:13,代码来源:messages.py

示例2: generate_message

# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_fstring [as 别名]
    def generate_message(self, recipient_id, message):
        connect_info = self._session_keeper.get_connect_info(recipient_id)
        symmetric_key = connect_info['symmetric_key']
        p = Packer()
        if connect_info.has_key('session_id_out'):
            p.pack_fstring(4, '\000\000\000\001')
            p.pack_fstring(SIZE_OF_UNIQS, connect_info['session_id_out'])
        else:
            #debugprint('including full header on message to %s\n', args=(recipient_id,), vs='mesgen') # XXX verbose
            p.pack_fstring(4, '\000\000\000\000')
            p.pack_string(connect_info['header'])

        iv = randsource.get(8)
        p.pack_fstring(8, iv)
        pdec = Packer()
        pdec.pack_string(message)

        # debugprint("------ ------ ------ ------ hmachish(key=%s, message=%s)\n" % (`symmetric_key`, `message`))
        mac = cryptutil.hmacish(key=symmetric_key, message=message)

        pdec.pack_fstring(SIZE_OF_UNIQS, mac)
        encrypted = tripledescbc.new(symmetric_key).encrypt(iv, pdec.get_buffer())
        p.pack_string(encrypted)
        return p.get_buffer()
开发者ID:zooko,项目名称:egtp,代码行数:26,代码来源:mesgen.py

示例3: __store_key

# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_fstring [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()
开发者ID:zooko,项目名称:egtp,代码行数:58,代码来源:mesgen.py


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