diff --git a/src/lib/environment.rs b/src/lib/environment.rs index 9881d6e..4bf7ad8 100644 --- a/src/lib/environment.rs +++ b/src/lib/environment.rs @@ -5,13 +5,13 @@ use serde_derive::Deserialize; use crate::errors::*; #[derive(Deserialize, Clone)] -pub struct TempEnvirontment { +pub struct TempEnvironment { pub ssh_host_username: String, pub ssh_key: String, } -pub fn read_temp_env(path: &str) -> Result { +pub fn read_temp_env(path: &str) -> Result { let toml_str = fs::read_to_string(path)?; - let env: TempEnvirontment = toml::from_str(&toml_str)?; + let env: TempEnvironment = toml::from_str(&toml_str)?; Ok(env) } diff --git a/src/lib/keyhouse.rs b/src/lib/keyhouse.rs index aee3577..397056d 100644 --- a/src/lib/keyhouse.rs +++ b/src/lib/keyhouse.rs @@ -1,10 +1,11 @@ -extern crate base64; extern crate crypto; extern crate reqwest; extern crate serde_json; use std::time::Duration; +use base64::{engine::general_purpose::STANDARD, Engine as _}; + use crypto::digest::Digest; use crypto::sha2::Sha256; @@ -46,13 +47,15 @@ pub fn validate_user(config: &Config, user: String, ssh_key: &str) -> Result Result { let json: serde_json::Value = serde_json::from_str(json_text) .chain_err(|| "Invalid JSON recieved from GitHub. Probably GitHub is facing some issues. Check https://githubstatus.com.")?; - let encoded_content = json["content"] + + let b64_enc_content = json["content"] .as_str() .ok_or(Error::from("")) .chain_err(|| "No key 'content' found in JSON recieved from GitHub.")?; - let len = str::len(encoded_content); - let content = base64::decode(&encoded_content.trim_end()) + + let content = STANDARD.decode(b64_enc_content.trim_end().as_bytes()) .chain_err(|| "Bad Base64 Encoding. Probably GitHub is facing some issues. Check https://githubstatus.com.")?; + Ok(String::from_utf8(content).chain_err(|| { "Bad UTF8 Encoding. Make sure the file you are trying to access is human readable." })?)