Rust扩展为信号协议提供Python绑定

signal-protocol的Python项目详细描述


信号协议

实验性的Python绑定到^{}Rust信号协议实现。这个项目提供了一个使用PyO3来定义signal_protocolPython模块的Rust扩展。请参见here,了解在Python分配的内存中存储机密的基本限制。⚠️使用风险自负!⚠️ 在

使用

初始设置

fromsignal_protocolimportcurve,identity_key,state,storage# Each client must generate a long-term identity key pair.# This should be stored somewhere safe and persistent.identity_key_pair=identity_key.IdentityKeyPair.generate()# Clients must generate prekeys. The example here is generating a# single prekey, but clients will generate many as they are one-time use# and consumed when a message from a new chat participant is sent. See issue #7.pre_key_pair=curve.KeyPair.generate()# Clients must generate a registration_id and store it somewhere safe and persistent.registration_id=12# TODO generate (not yet supported in upstream crate)# The InMemSignalProtocolStore is a single object which provide the four storage# interfaces required: IdentityKeyStore (for one's own identity key state and the (public)# identity keys for other chat participants), PreKeyStore (for one's own prekey state),# SignedPreKeyStore (for one's own signed prekeys), and SessionStore (for established sessions# with chat participants).store=storage.InMemSignalProtocolStore(identity_key_pair,registration_id)# Clients should also generate a signed prekey.signed_pre_key_pair=curve.KeyPair.generate()serialized_signed_pre_pub_key=signed_pre_key_pair.public_key().serialize()signed_pre_key_signature=store.get_identity_key_pair().private_key().calculate_signature(serialized_signed_pre_pub_key)# Clients should store their prekeys (both one-time and signed) in the protocol store# along with IDs that can be used to retrieve them later.pre_key_id=10pre_key_record=state.PreKeyRecord(pre_key_id,pre_key_pair)store.save_pre_key(pre_key_id,pre_key_record)signed_pre_key_id=33signed_prekey=state.SignedPreKeyRecord(signed_pre_key_id,42,# This is a timestamp since this key should be periodically rotatedsigned_pre_key_pair,signed_pre_key_signature,)store.save_signed_pre_key(signed_pre_key_id,signed_prekey)

向新参与者发送消息

^{pr2}$

开发人员入门

您需要在系统上同时安装Rust和python3.7+。要在virtualenv中安装项目,请执行以下操作:

pip install -r requirements.txt
python setup.py develop  # This will call out to rustc

然后通过pytest -v tests/运行测试,以确认所有测试都正常。测试从上游的板条箱移植到Python上。您可以将测试用作如何使用库的参考。在

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java XStream自定义转换器,可从列表生成平面XML结构?   java GridView项目文本不改变颜色   java您必须在主类中扩展JApplet吗?   如何使用java编写基于Excel的csv文件?   java如何从这段代码中得到整个多边形的颜色?   具有多个表连接和sum()的java HQL,first()   java如何使用一种方法将两个数组添加到一起   带鼠标+键盘的VBO Java LWJGL   java如何在XDB中创建小数点为2的浮点字段   java如何从XAuthToken获得身份验证?   内存管理如何正确使用java。终结者先生?   音频如何在Java中使用PortAudio(带处理的jpab)绘制波形?   java是Youtube上的视频列表,包含400个错误代码   爪哇我的巴恩斯利蕨太瘦了   java为什么Android会忽略READ_SMS权限?   jpeg问题从JAVA启动MATLAB代码   java如何判断当前bash脚本是否从调用脚本调用   方法重写中的Java静态变量   java如何在peerpeer Ad hoc网络中的两个具有两跳距离的对等方之间中继RTP(实时传输协议)流   java Android:以编程方式检索资源字符串