Rust 如何使用新的_类型!宏为sodiumoxide公钥和SecretKey设置更通用的类型?

Rust 如何使用新的_类型!宏为sodiumoxide公钥和SecretKey设置更通用的类型?,rust,libsodium,Rust,Libsodium,我正在尝试为sodiumoxidePublicKey和SecretKey设置更通用的类型 这取决于我们是否使用框或符号: type PubCryptoSecretKey = sodiumoxide::crypto::box_::curve25519xsalsa20poly1305::SecretKey; 我想设置一个与Sodiumxide键的类型兼容的PublicKey类型或结构,类似于struct PublicKey(pub[u8;?]) SecretKey(或任何密钥)的来源是: 其中,S

我正在尝试为sodiumoxide
PublicKey
SecretKey
设置更通用的类型

这取决于我们是否使用
符号

type PubCryptoSecretKey = sodiumoxide::crypto::box_::curve25519xsalsa20poly1305::SecretKey;
我想设置一个与Sodiumxide键的类型兼容的
PublicKey
类型或结构,类似于
struct PublicKey(pub[u8;?])

SecretKey
(或任何密钥)的来源是:

其中,
SECRETKEYBYTES
的类型为
usize

我找不到有关此
新类型的任何信息宏。这里发生了什么,我该如何进一步呢?

这是,但我看不到任何好方法可以轻松地为这两种类型定义泛型类型

一个可能的解决方案是在您的板条箱中定义一个新特性,然后为
PublicKey
SecretKey
实现它。该特性应该为您提供足够的功能来与每个结构交互

new_type! {
    /// `SecretKey` for asymmetric authenticated encryption
    ///
    /// When a `SecretKey` goes out of scope its contents
    /// will be zeroed out
    secret SecretKey(SECRETKEYBYTES);
}