1use crate::pel::InputContext;
5
6const ALLOWED_FUNCTIONS: [(&str, &str); 16] = [
7 ("dw::Core::++", "++"),
8 ("dw::Core::--", "--"),
9 ("dw::Core::contains", "contains"),
10 ("dw::Core::splitBy", "splitBy"),
11 ("dw::Core::trim", "trim"),
12 ("dw::Core::lower", "lower"),
13 ("dw::Core::upper", "upper"),
14 ("dw::Core::sizeOf", "sizeOf"),
15 ("dw::Core::uuid", "uuid"),
16 ("dw::Core::isEmpty", "isEmpty"),
17 ("dw::core::Strings::substringBefore", "substringBefore"),
18 ("dw::core::Strings::substringAfter", "substringAfter"),
19 (
20 "dw::core::Strings::substringBeforeLast",
21 "substringBeforeLast",
22 ),
23 (
24 "dw::core::Strings::substringAfterLast",
25 "substringAfterLast",
26 ),
27 ("dw::core::Binaries::toBase64", "toBase64"),
28 ("dw::core::Binaries::fromBase64", "fromBase64"),
29];
30
31const ALLOWED_INPUTS: [&str; 4] = ["payload", "attributes", "vars", "authentication"];
32
33pub fn dw2pel(dw: &str) -> String {
44 let ctx = InputContext {
45 inputs: ALLOWED_INPUTS.to_vec(),
46 functions: ALLOWED_FUNCTIONS.iter().map(|(k, _)| *k).collect(),
47 };
48
49 let result = crate::pel::compile_to_pel_expr("", dw, &ctx);
50 if result.pel.is_some() {
51 format!(
52 "P[{}, \"#[{}]\"]",
53 result.pel.unwrap(),
54 dw.replace("\"", "\\\"")
55 )
56 } else {
57 panic!("dw2pel failed: {:?}", result.messages)
58 }
59}