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

PANIC on serialize_openssh() #4

Closed
lambdalisue opened this issue Oct 26, 2021 · 0 comments · Fixed by #5
Closed

PANIC on serialize_openssh() #4

lambdalisue opened this issue Oct 26, 2021 · 0 comments · Fixed by #5

Comments

@lambdalisue
Copy link
Contributor

Thanks for the library. It saved me. However, I found that serialize_openssh() panic with the following error

thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', /Users/alisue/.asdf/installs/rust/1.54.0/registry/src/git.luolix.top-1ecc6299db9ec823/oss
hkeys-0.5.1/src/format/ossh_privkey.rs:321:42
stack backtrace:
   0: rust_begin_unwind
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/panicking.rs:515:5
   1: core::panicking::panic_fmt
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/panicking.rs:92:14
   2: core::panicking::panic
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/panicking.rs:50:5
   3: core::option::Option<T>::unwrap
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/option.rs:388:21
   4: osshkeys::format::ossh_privkey::encode_key
             at /Users/alisue/.asdf/installs/rust/1.54.0/registry/src/git.luolix.top-1ecc6299db9ec823/osshkeys-0.5.1/src/format/ossh_privkey.rs:321:29
   5: osshkeys::format::ossh_privkey::encode_ossh_priv
             at /Users/alisue/.asdf/installs/rust/1.54.0/registry/src/git.luolix.top-1ecc6299db9ec823/osshkeys-0.5.1/src/format/ossh_privkey.rs:259:5
   6: osshkeys::format::ossh_privkey::serialize_ossh_privkey
             at /Users/alisue/.asdf/installs/rust/1.54.0/registry/src/git.luolix.top-1ecc6299db9ec823/osshkeys-0.5.1/src/format/ossh_privkey.rs:190:15
   7: osshkeys::keys::KeyPair::serialize_openssh
             at /Users/alisue/.asdf/installs/rust/1.54.0/registry/src/git.luolix.top-1ecc6299db9ec823/osshkeys-0.5.1/src/keys/mod.rs:342:16
   8: rust_osshkeys_panic::main
             at ./src/main.rs:8:9
   9: core::ops::function::FnOnce::call_once
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

With the following code

use anyhow::Result;

fn main() -> Result<()> {
    let private_key_str = include_str!("id_rsa");
    let keypair = osshkeys::keys::KeyPair::from_keystr(&private_key_str, None)?;
    println!(
        "{}",
        keypair.serialize_openssh(None, osshkeys::cipher::Cipher::Null)?
    );
    Ok(())
}

With the following id_rsa

-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn
NhAAAAAwEAAQAAAYEAsNyUbp+gPn1lSbo67q+Cvtqt3ECc5qMRxx68/HaY2ad9/azbfJGg
1PXD9r5wRcJyi0wn92bkmAt3KckrEs7D4oMTOP7Q+OkcCrnuhpY8AKS2HGvcyItm9gl54R
2B+oM5ivLGiMCkBeLkrtXKL4gOleo1IwlOv4+o+N+bQrROtGqBZcCcEZiFyGx//dO0MGVn
6MDD/zCQA3uxWwHYIljF36uC5oe1buPRJwBKNLZI0TrxR2gFljf2cXT15HN/yau1ovjTm8
0295XFqWIYBWXke6HpHGGSuzrEFFL9AGk28dIVZkJvAm+1FneYoZCTzh8Gvj+GmXIifbvY
tbTrehx8KIgP2Tb0wQjxD561E0YcGbTgcNF1km09eqvdoXMBfhokgJZkZnilK7LcimzHDJ
HZF/96Zd13AlUZOA+cGJOvh0O/afmRtH6nR8vPFyglJ8ELlWHtSzLcZ2loo9QtNk5/y7tk
COLWoTUCjSmFgThuz8x8xyTGbLYmFKPBslGLG4CvAAAFmLPq8Lez6vC3AAAAB3NzaC1yc2
EAAAGBALDclG6foD59ZUm6Ou6vgr7ardxAnO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kwIOaRs2vL06OOhB6Orlh8Tq
vfvnQFlKAvAgf7ad05pnbAGDT/4Je+tGhdM5usjUeJYxJ54g8iaRQCn/ELJs0GKZFtViPp
Xn7UqwfKtVOS+yGVqKpzxerb5u+bQXBa8DWj2aE/FidxH+F4QMhc9Bp6LuAbUiShtFTQrD
rj/cFimcKnuTvmT9PgpyEUvozMcH6MHWK2SS8BtrhIAhMEmgAAAMEA1ZKc0wyPwNH9btjB
l7RB+cHMyySXZgqJtQEDU+5yKB2YLMKP2HILN27SwxmcKKs+erIrbCrr8j4iLQgWBKvGO5
yBtnbDrdL5Kyf9E/vwywvzZNHnj/cBeMkmSohxj2sDQ4O5uEfO4Ln+VQEhihcLEoxJCext
qv2G3jf9+MelPT4bvSX9ISHJbNaJzcsK+Lj4Uyl8Bjgi19nWykScNFYjp8B4PLl+kpubbO
/3Haz5i1uwh3UChfvAo8r61DLdzmmLAAAAwQDT/wApTpeVAVGRB2urieEsZ5xMeJRG+lUO
QLIooHBbpoExrJJYPL4X+3w/vo304s5ZZEapB1rEsiTeZutIAiEE87YGWxse2PdBMzKUq7
7nFTdJ/XH4Dt6MdZZsisA5H9mrwwZbKRMnnJV/XKfMj7w/FNT5zhvZNZYe+sV6O+xqkDJv
Rbr+GBk2/AOeWmB/0tgaLZJmxhq9uksv+8O59hDr17VSbEIWVuiUMZIbB0kA/hAwBR/HIk
ZY45+nuvqWwe0AAAAgYWxpc3VlQGFsaXN1ZS1ob21lLW1hY21pbmkubG9jYWwBAgM=
-----END OPENSSH PRIVATE KEY-----
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

Successfully merging a pull request may close this issue.

1 participant