I try to serialize the PublicKey
struct of sodiumoxide (Rust bindings for libsodium) to a file (e.g. JSON, but binary would be okay, too).
Here is my code:
extern crate serde;
extern crate serde_json;
extern crate sodiumoxide;
use serde::Serialize;
use serde_json::ser::Serializer;
use sodiumoxide::crypto::sign;
fn main() {
let (pk, _) = sign::gen_keypair();
let pk_ser = serde_json::to_string(&pk);
}
I get the following error message:
error: the trait bound `sodiumoxide::crypto::sign::PublicKey: serde::Serialize` is not satisfied [E0277]
So the compiler tells me that PublicKey
should implement the serde::Serialize trait. But it does implement serde::Serialize
as stated here: https://dnaq.github.io/sodiumoxide/sodiumoxide/crypto/sign/ed25519/struct.PublicKey.html
So, what is the problem?
Edit:
Cargo.toml:
[package]
name = ...
version = ...
authors = ...
[dependencies]
serde = "*"
serde_json = "*"
sodiumoxide = "*"