Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created August 21, 2018 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/8098480aafd1113aeb39b985a1ee83be to your computer and use it in GitHub Desktop.
Save rust-play/8098480aafd1113aeb39b985a1ee83be to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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