< 返回版块

eruca 发表于 2024-06-03 23:24

Diesel 发布新版本 2.2.0

Diesel 是一个安全且高性能的查询构建器和用 Rust 编写的 ORM。此版本包含多项新功能并改进了现有功能。Diesel 现在提供了一个过程宏属性,用于推断查询的正确返回类型。现在可以检测Diesel提供的连接实现,以执行记录和性能测量。我们添加了对 PostgreSQL COPY FROM 和 COPY TO 语法的支持,可用于有效地发送和接收大量数据。我们的依赖项包装了本机数据库驱动程序,现在支持所有构建数据库驱动程序作为 . cargo build 这使我们能够轻松地分发 diesel-cli 的静态预编译版本。最后,我们与 Rust 团队合作,稳定属性,以自定义编译器发出的错误消息。现在,Diesel使用它来提高某些难以理解的错误消息的质量。

更多信息查看 GitHub,https://github.com/diesel-rs/diesel

rencrypt-python 在 Rust 中实现的 Python 加密库。

它支持带有 AES-GCM 和 ChaCha20Poly1305 的 AEAD。它使用ring crate来处理加密。

使用内存中的缓冲区进行加密和解密 这是使用它的最高性能方式,因为它不会将字节复制到缓冲区,也不会为明文和密文分配新内存。

from rencrypt import REncrypt, Cipher
import os
from zeroize import zeroize1


# You can use also other ciphers like `cipher = Cipher.ChaCha20Poly1305`.
cipher = Cipher.AES256GCM
key = cipher.generate_key()
# The key is copied and the input key is zeroized for security reasons.
# The copied key will also be zeroized when the object is dropped.
enc = REncrypt(cipher, key)

# we get a buffer based on block len 4096 plaintext
# the actual buffer will be 28 bytes larger as in ciphertext we also include the tag and nonce
plaintext_len, ciphertext_len, buf = enc.create_buf(4096)
aad = b"AAD"

# put some plaintext in the buffer, it would be ideal if you can directly collect the data into the buffer without allocating new memory
# but for the sake of example we will allocate and copy the data
plaintext = bytearray(os.urandom(plaintext_len))
# enc.copy_slice is slighlty faster than buf[:plaintext_len] = plaintext, especially for large plaintext, because it copies the data in parallel
# enc.copy_slice takes bytes as input, enc.copy_slice1 takes bytearray
enc.copy_slice1(plaintext, buf)
# encrypt it, this will encrypt in-place the data in the buffer
print("encryping...")
ciphertext_len = enc.encrypt(buf, plaintext_len, 42, aad)
cipertext = buf[:ciphertext_len]
# you can do something with the ciphertext

# decrypt it
# if you need to copy ciphertext to buffer, we don't need to do it now as it's already in the buffer
# enc.copy_slice(ciphertext, buf[:len(ciphertext)])
print("decryping...")
plaintext_len = enc.decrypt(buf, ciphertext_len, 42, aad)
plaintext2 = buf[:plaintext_len]
assert plaintext == plaintext2

# best practice, you should always zeroize the plaintext and keys after you are done with it (key will be zeroized when the enc object is dropped)
zeroize1(plaintext)
zeroize1(plaintext2)

print("bye!")

更多信息请查看github, https://github.com/radumarias/rencrypt-python

GPM 一个完全可定制的通用包管理器

你想制作自己的包管理器吗?

初始化包管理器

gpm init

添加新的包类型

gpm type add <NAME> <EXT> <SHELL>

Change your shell config at ~/.gpm/types.toml.
在 ~/.gpm/types.toml 中更改 shell 配置。

更多信息查看 GitHub,https://github.com/8LWXpg/gpm


From 日报小组 [倪步烤Neo]

社区学习交流平台订阅:

评论区

写评论

还没有评论

1 共 0 条评论, 1 页