Reputation: 45
I am creating a protocol simulation and research tool made with Rust as a library for Python through maturin and Pyo3. I´m relying on different crates that implement protocols in a secure way, but I run into the same problem every time I use a structs from a crate, the problem being that when I try to turn the data from a variable into bytes or from it to make use those types in Python, I run into this problem:
no method named
to_bytes
found for structsidh::sidh::SIDHSecretKeyBob
in the current scope method not found inSIDHSecretKeyBob
#[pyfunction]
pub fn sidh_keygen(py: Python) -> PyResult<(Py<PyBytes>, Py<PyBytes>, Py<PyBytes>, Py<PyBytes>)> {
let mut rng = thread_rng();
// Generate key pairs for Alice and Bob
let (alice_public, alice_secret) = generate_alice_keypair(&mut rng);
let (bob_public, bob_secret) = generate_bob_keypair(&mut rng);
// Convert keys to bytes for Python compatibility
let alice_pub_bytes = PyBytes::new_bound(py, &alice_public.to_bytes());
let bob_pub_bytes = PyBytes::new_bound(py, &bob_public.to_bytes());
let alice_sec_bytes = PyBytes::new_bound(py, &alice_secret.to_bytes()); // Serializing Alice's secret
let bob_sec_bytes = PyBytes::new_bound(py, &bob_secret.to_bytes()); // Serializing Bob's secret
// Returning both public keys and secret keys for encapsulation/decapsulation
Ok((alice_pub_bytes.into(), alice_sec_bytes.into(), bob_pub_bytes.into(), bob_sec_bytes.into()))
}
I´m not used to Rust yet but I thought there should be an easy way to do the to_bytes or from_bytes in "anything" so it can be used right? Maybe there is a better approach to working with data types through Python with maturin and Pyo3.
Upvotes: 1
Views: 88