From ed1156c14eb7f49e001cb800da3e8bfe0eeaf0a6 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Fri, 20 Jan 2023 00:09:19 +0000 Subject: [PATCH] build: use non-deprecated base64 api --- --- a/crates/jrsonnet-stdlib/src/encoding.rs +++ b/crates/jrsonnet-stdlib/src/encoding.rs @@ -1,3 +1,4 @@ +use base64::{engine::general_purpose::STANDARD, Engine}; use jrsonnet_evaluator::{ error::{ErrorKind::RuntimeError, Result}, function::builtin, @@ -21,21 +22,24 @@ pub fn builtin_base64(input: Either![IStr, IBytes]) -> String { use Either2::*; match input { - A(l) => base64::encode(l.as_bytes()), - B(a) => base64::encode(a.as_slice()), + A(l) => STANDARD.encode(l.as_bytes()), + B(a) => STANDARD.encode(a.as_slice()), } } #[builtin] pub fn builtin_base64_decode_bytes(str: IStr) -> Result { - Ok(base64::decode(str.as_bytes()) - .map_err(|_| RuntimeError("bad base64".into()))? + Ok(STANDARD + .decode(str.as_bytes()) + .map_err(|e| RuntimeError(format!("invalid base64: {e}").into()))? .as_slice() .into()) } #[builtin] pub fn builtin_base64_decode(str: IStr) -> Result { - let bytes = base64::decode(str.as_bytes()).map_err(|_| RuntimeError("bad base64".into()))?; + let bytes = STANDARD + .decode(str.as_bytes()) + .map_err(|e| RuntimeError(format!("invalid base64: {e}").into()))?; Ok(String::from_utf8(bytes).map_err(|_| RuntimeError("bad utf8".into()))?) } -- gitstuff