Created
August 21, 2018 19:51
-
-
Save rust-play/8098480aafd1113aeb39b985a1ee83be to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const BASE64CHARS: [char; 64] = [ | |
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', | |
'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', | |
'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', | |
'5', '6', '7', '8', '9', '+', '/', | |
]; | |
fn main() { | |
println!("{:?}", format_base64_string("foz==")); | |
} | |
fn format_base64_string(base64input: &str) -> Result<&str, &str> { | |
for ch in base64input.trim_right_matches('=').chars() { | |
if !BASE64CHARS.contains(&ch) { | |
return Err("Error.. An invalid base 64 string was input!"); | |
} | |
} | |
Ok(base64input) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment