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

问题描述

我正在尝试为氧化钠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,但我看不出有什么好方法可以轻松地为它们两者定义通用类型。

可能的解决方案是在板条箱中定义一个新特征,然后为PublicKeySecretKey实施。该特征应为您提供足够的功能以与每个结构进行交互。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...