From 06cbbd2b171d9125605fd938ddd4c6b9fb58d8e7 Mon Sep 17 00:00:00 2001 From: Dustin Frisch Date: Wed, 20 Jun 2018 00:40:42 +0200 Subject: [PATCH 1/2] Add Cred::ssh_key_from_memory --- src/cred.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/cred.rs b/src/cred.rs index 5de8cf22f1..24470c80d8 100644 --- a/src/cred.rs +++ b/src/cred.rs @@ -68,6 +68,24 @@ impl Cred { } } + /// Create a new ssh key credential object reading the keys from memory. + pub fn ssh_key_from_memory(username: &str, + publickey: Option<&str>, + privatekey: &str, + passphrase: Option<&str>) -> Result { + ::init(); + let username = try!(CString::new(username)); + let publickey = try!(::opt_cstr(publickey)); + let privatekey = try!(CString::new(privatekey)); + let passphrase = try!(::opt_cstr(passphrase)); + let mut out = ptr::null_mut(); + unsafe { + try_call!(raw::git_cred_ssh_key_memory_new(&mut out, username, publickey, + privatekey, passphrase)); + Ok(Binding::from_raw(out)) + } + } + /// Create a new plain-text username and password credential object. pub fn userpass_plaintext(username: &str, password: &str) -> Result { From 9335c76b67ea3c445ade0d554459da53c8736ded Mon Sep 17 00:00:00 2001 From: Dustin Frisch Date: Mon, 2 Jul 2018 23:04:06 +0200 Subject: [PATCH 2/2] fixup! Add Cred::ssh_key_from_memory --- src/cred.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/cred.rs b/src/cred.rs index 24470c80d8..29d514885a 100644 --- a/src/cred.rs +++ b/src/cred.rs @@ -522,6 +522,48 @@ echo username=c .execute().is_none()); } + #[test] + fn ssh_key_from_memory() { + let cred = Cred::ssh_key_from_memory( + "test", + Some("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDByAO8uj+kXicj6C2ODMspgmUoVyl5eaw8vR6a1yEnFuJFzevabNlN6Ut+CPT3TRnYk5BW73pyXBtnSL2X95BOnbjMDXc4YIkgs3YYHWnxbqsD4Pj/RoGqhf+gwhOBtL0po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kObpVgBQZcNZb/hKUYPGk + g4zehfIgAfCdnQHwZvQ6Fdzhcs3SZeO+zVyuiZN3Gsi9HU0/1vpAKiuuOzcG02vF + b6Y6hwsAA9yphF3atI+ARD4ZwXdDfzuGb3yJglMT3Fr/xuLwAvdchRo1spANKA0E + tT5okLrK0H4wnHvf2SniVVWRhmJis0lQo9LjGGwRIdsPpVnJSDvaISIVF+fHT90r + HvxN8zXI93x9jcPtwp7puQ1C7ehKJK10sZ71OLIZeuUgwt+5DRunqg6evPco9Go7 + UOGwcVhLY200KT+1k7zWzCS0yVQp2HRm6cxsZXAp4ClBSwIx15eIoLIrjZdJRjCq + COp6pZx1fnvJ9ERIvl5hon+Ty+renMcFKz2HmchC7egpcqIxW9Dsv6zjhHle6pxb + 37GaEKHF2KA3RN+dSV/K8n+C9Yent5tx5Y9a/pMcgRGtgu+G+nyFmkPKn5Zt39yX + qDpyM0LtbRVZPs+MgiqoGIwYc/ujoCq7GL38gezsBQoHaTt79yYBqCp6UR0LMuZ5 + f/7CtWqffgySfJ/0wjGidDAumDv8CK45AURpL/Z+tbFG3M9ar/LZz/Y6EyBcLtGY + Wwb4zs8zXIA0qHrjNTnPqHDvezziArYfgPjxCIHMZzms9Yn8+N02p39uIytqg434 + BAlCqZ7GYdDFfTpWIwX+segTK9ux0KdBqcQv+9Fwwjkq9KySnRKqNl7ZJcefFZJq + c6PA1iinZWBjuaO1HKx3PFulrl0bcpR9Kud1ZIyfnh5rwYN8UQkkcR/wZPla04TY + 8l5dq/LI/3G5sZXwUHKOcuQWTj7Saq7Q6gkKoMfqt0wC5bpZ1m17GHPoMz6GtX9O + -----END RSA PRIVATE KEY----- + "#, + Some("test123")); + assert!(cred.is_ok()); + } + + #[cfg(unix)] fn chmod(path: &Path) { use std::os::unix::prelude::*;