我目前正在从事一个密码学项目,我对Rust还不熟悉,我现在对如何打印这些公钥和私钥感到非常困惑。
目标:打印出私钥和公钥,这样我就可以看到它了。
锈蚀码
pub use pqcrypto_dilithium::dilithium5::{
public_key_bytes as public_key_bytes,
secret_key_bytes as secret_key_bytes,
signature_bytes as signature_bytes,
verify_detached_signature as verify_detached_signature,
detached_sign as detached_sign,
keypair as keypair,
open as open,
sign as sign,
};
fn main () {
let (public_key, private_key) = keypair();
// Print variable here...
}Cargo.toml
[package]
name = "project"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
pqcrypto-dilithium = "0.4.5"错误
error[E0277]: `pqcrypto_dilithium::dilithium5::PublicKey` doesn't implement `Debug`
--> src\main.rs:14:23
|
14 | println!("{:#?}", public_key)
| ^^^^^^^^^^ `pqcrypto_dilithium::dilithium5::PublicKey` cannot be formatted using `{:?}` because it doesn't implement `Debug`
|
= help: the trait `Debug` is not implemented for `pqcrypto_dilithium::dilithium5::PublicKey`
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
For more information about this error, try `rustc --explain E0277`.使用cargo run运行此代码
发布于 2022-06-18 02:30:16
为了打印具有{:?}格式占位符的任何类型的实例,该类型必须实现Debug特性。这个特性告诉铁锈如何显示实例的内容。
PublicKey和SecretKey类型都不直接实现Debug。但是,它们都有公开包含键的u8片的方法:as_bytes方法。
注意,as_bytes()方法是特征pqcrypto_traits::sign::PublicKey的一部分。为了使用属性方法,您需要在作用域中具有该特性,因此必须在源文件中对其进行use。
片implement Debug只要片元素实现Debug,哪个u8 does,就可以打印u8片。
use pqcrypto_traits::sign::PublicKey;
//...
println!("Public key: {:#?}", public_key.as_bytes());发布于 2022-06-19 22:54:37
对我来说,解决办法如下
pqcrypto-traits = "0.3.4" to Cargo.toml,并使用pub use pqcrypto_traits::sign::PublicKey;保存.toml文件.如果您对Sha256::new()有问题,请将pub use pqcrypto_traits::sign::PublicKey;放在该行下面。这就是对我起作用的东西。
https://stackoverflow.com/questions/72666068
复制相似问题