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

Cannot build a KES private key from a vector of bytes #524

Open
ghost opened this issue Oct 20, 2024 · 0 comments
Open

Cannot build a KES private key from a vector of bytes #524

ghost opened this issue Oct 20, 2024 · 0 comments

Comments

@ghost
Copy link

ghost commented Oct 20, 2024

I am trying to reconstruct a KesSecretKey from a base64-encoded string coming from a JSON structure that's generated in Haskell, for the purpose of testing header validation logic. Here is the code I am using:

fn deserialize_secret_kes_key<'a, 'de, D>(deserializer: D) -> Result<KesSecretKey<'a>, D::Error>
where
    D: Deserializer<'de>,
{
    let buf = <&str>::deserialize(deserializer)?;
    let mut bytes = general_purpose::STANDARD
        .decode(buf)
        .map_err(serde::de::Error::custom)?;
    KesSecretKey::from_bytes(&mut bytes).map_err(serde::de::Error::custom)
}

which fails to compile because of

error[E0515]: cannot return value referencing local variable `bytes`
  --> ouroboros-praos/tests/validation.rs:35:5
   |
35 |     KesSecretKey::from_bytes(&mut bytes).map_err(serde::de::Error::custom)
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^----------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |     |                        |
   |     |                        `bytes` is borrowed here
   |     returns a value referencing data owned by the current function

My knowledge of Rust's borrow-checking is still fledgling so I would appreciate if someone could help me figure out what's the right way to build KesSecretKey

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

No branches or pull requests

0 participants