gpt4 book ai didi

rust - 如何使用new_type!宏来为氧化钠PublicKey和SecretKey设置更通用的类型?

转载 作者:行者123 更新时间:2023-12-03 11:47:54 25 4
gpt4 key购买 nike

我正在尝试为氧化钠PublicKeySecretKey设置一个更通用的类型。
这取决于我们使用box_还是sign:

type PubCryptoSecretKey = sodiumoxide::crypto::box_::curve25519xsalsa20poly1305::SecretKey;
我想设置一个 PublicKey类型或与氧化钠键类型兼容的结构,例如 struct PubKey(pub [u8; ?])SecretKey(或任何键)的来源是:
new_type! {
/// `SecretKey` for asymmetric authenticated encryption
///
/// When a `SecretKey` goes out of scope its contents
/// will be zeroed out
secret SecretKey(SECRETKEYBYTES);
}
其中 SECRETKEYBYTES的类型为 usize我找不到有关此 new_type!宏的任何信息。这是怎么回事,我该怎么走?

最佳答案

这是how the macro defines the structure,但是我看不到任何简单的方法来轻松定义它们的通用类型。
一种可能的解决方案是在 crate 中定义一个新特征,然后对PublicKeySecretKey实现它。该特征应为您提供足够的功能以与每个结构进行交互。

关于rust - 如何使用new_type!宏来为氧化钠PublicKey和SecretKey设置更通用的类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63694663/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com