use super::funejson::Value; use super::encoding_base64_base64_encode::base64_encode; /// Bytes as base64url (RFC 4648 section 5) without padding, as JWTs use it. /// /// # Panics /// Panics if any value is outside 0-255. pub fn base64_url_encode(bytes: &[i64]) -> String { base64_encode(bytes) .trim_end_matches('=') .chars() .map(|c| match c { '+' => '-', '/' => '_', other => other, }) .collect() } pub fn fune_vector(args: &[Value]) -> Value { let bytes: Vec = match &args[0] { Value::Arr(items) => items .iter() .map(|item| match item { Value::Int(i) => *i, _ => panic!("bytes must be a list of integers from 0 to 255"), }) .collect(), _ => panic!("bytes must be a list of integers from 0 to 255"), }; Value::str(&base64_url_encode(&bytes)) }