mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
Improvements (#33)
1. Skip recording undefined variables 2. Parse `in` correctly if it is not imported. 3. base64.decode 4. Handle `with` modifier for qualified data and input. Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
This commit is contained in:
committed by
GitHub
parent
6228eaab4a
commit
c53d002347
28
src/builtins/encoding.rs
Normal file
28
src/builtins/encoding.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
use crate::ast::Expr;
|
||||
use crate::builtins;
|
||||
use crate::builtins::utils::{ensure_args_count, ensure_string};
|
||||
use crate::lexer::Span;
|
||||
use crate::value::Value;
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use anyhow::Result;
|
||||
use data_encoding::BASE64;
|
||||
|
||||
pub fn register(m: &mut HashMap<&'static str, builtins::BuiltinFcn>) {
|
||||
m.insert("base64.decode", (base64_decode, 1));
|
||||
}
|
||||
|
||||
fn base64_decode(span: &Span, params: &[Expr], args: &[Value]) -> Result<Value> {
|
||||
let name = "base64.decode";
|
||||
ensure_args_count(span, name, params, args, 1)?;
|
||||
|
||||
let encoded_str = ensure_string(name, ¶ms[0], &args[0])?;
|
||||
let decoded_bytes = BASE64.decode(encoded_str.as_bytes())?;
|
||||
Ok(Value::String(
|
||||
String::from_utf8_lossy(&decoded_bytes).to_string(),
|
||||
))
|
||||
}
|
||||
Reference in New Issue
Block a user