I am trying to set a more generic type for a sodiumoxide PublicKey
and SecretKey
.
This changes depending if we use box_
or sign
:
type PubCryptoSecretKey = sodiumoxide::crypto::box_::curve25519xsalsa20poly1305::SecretKey;
I would like to set a PublicKey
type or struct which is compatible with sodiumoxide key's type, something like struct PubKey(pub [u8; ?])
.
The source of SecretKey
(or any key) is:
new_type! {
/// `SecretKey` for asymmetric authenticated encryption
///
/// When a `SecretKey` goes out of scope its contents
/// will be zeroed out
secret SecretKey(SECRETKEYBYTES);
}
where SECRETKEYBYTES
is of type usize
I can not find any information about this new_type!
macro. What is going on here and how can I go further?
This is how the macro defines the structure, but I don't see any good way to easily define generic types for both of them.
A possible solution is to define a new trait in your crate and then implement it for both
PublicKey
andSecretKey
. The trait should provide you enough functionality to interact with each structure.