Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SigningKey cannot be deserialized from CBOR #315

Open
Calmarius opened this issue Dec 29, 2023 · 2 comments
Open

SigningKey cannot be deserialized from CBOR #315

Calmarius opened this issue Dec 29, 2023 · 2 comments

Comments

@Calmarius
Copy link

Calmarius commented Dec 29, 2023

The following code panics:

use ed25519_dalek::SigningKey;
use ciborium;
use rand;


fn main() {
    let mut csprng = rand::rngs::OsRng;

    let key = ed25519_dalek::SigningKey::generate(&mut csprng);

    // JSON serde works
    let json_str = serde_json::to_string(&key).unwrap();
    println!("Serialized JSON: {:?}", json_str);
    let _: SigningKey = serde_json::from_str(json_str.as_str()).unwrap();

    // CBOR serde doesn't work
    let mut serialized = Vec::<u8>::new();
    ciborium::into_writer(&key, &mut serialized).unwrap();
    println!("serialized: {:x?}", serialized);
    let _: SigningKey = ciborium::from_reader(serialized.as_slice()).unwrap(); // panics

    println!("Hello, world!");
}

Dependencies:

ciborium = "0.2.1"
ed25519-dalek = { version = "2.1.0", features = ["serde", "rand_core"] }
rand = "0.8.5"
serde = { version = "1.0.193", features = ["derive"] }
serde_json = "1.0.108"

Running results in:

Serialized JSON: "[62,94,122,7,201,143,23,39,141,27,130,149,78,220,112,4,31,90,202,131,52,70,82,144,223,151,232,138,27,78,87,132]"
serialized: [58, 20, 3e, 5e, 7a, 7, c9, 8f, 17, 27, 8d, 1b, 82, 95, 4e, dc, 70, 4, 1f, 5a, ca, 83, 34, 46, 52, 90, df, 97, e8, 8a, 1b, 4e, 57, 84]
thread 'main' panicked at src/main.rs:20:70:
called `Result::unwrap()` on an `Err` value: Semantic(None, "invalid type: byte array, expected An ed25519 signing (private) key")
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

The problem is that ciborium calls visit_bytes on the visitor but only visit_borrowed_bytes is implemented for the SingingKey class.

I haven't checked other structs, those may also be affected.

@robjtede
Copy link
Contributor

robjtede commented Jan 17, 2024

This repo has moved to https://github.com/dalek-cryptography/curve25519-dalek. You'll want to re-file this over there.

@marley1989
Copy link

Let them go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants