Skip to content

Commit

Permalink
remove deprecated functions and fix base64 decoding
Browse files Browse the repository at this point in the history
Signed-off-by: Praneeth Sarode <[email protected]>
  • Loading branch information
DarkPhoenix42 committed Nov 10, 2024
1 parent a46cb7c commit 4db723a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/lib/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TempEnvirontment> {
pub fn read_temp_env(path: &str) -> Result<TempEnvironment> {
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)
}
11 changes: 7 additions & 4 deletions src/lib/keyhouse.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -46,13 +47,15 @@ pub fn validate_user(config: &Config, user: String, ssh_key: &str) -> Result<boo
fn get_content_from_github_json(json_text: &str) -> Result<String> {
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."
})?)
Expand Down

0 comments on commit 4db723a

Please sign in to comment.