fix: don't panic on invalid hex strings
This commit is contained in:
parent
dfa0378404
commit
308fb47e40
|
@ -203,16 +203,24 @@ peg::parser! {
|
||||||
= b:$("True" / "False") { b == "True" }
|
= b:$("True" / "False") { b == "True" }
|
||||||
|
|
||||||
rule bytestring() -> Vec<u8>
|
rule bytestring() -> Vec<u8>
|
||||||
= "#" i:ident()* { hex::decode(String::from_iter(i)).unwrap() }
|
= "#" i:ident()* {?
|
||||||
|
hex::decode(String::from_iter(i)).map_err(|_| "Invalid bytestring")
|
||||||
|
}
|
||||||
|
|
||||||
rule bls_element() -> Vec<u8>
|
rule bls_element() -> Vec<u8>
|
||||||
= "0x" i:ident()* { hex::decode(String::from_iter(i)).unwrap() }
|
= "0x" i:ident()* {?
|
||||||
|
hex::decode(String::from_iter(i)).map_err(|_| "Invalid bls element hex")
|
||||||
|
}
|
||||||
|
|
||||||
rule g1_element() -> blst::blst_p1
|
rule g1_element() -> blst::blst_p1
|
||||||
= element:bls_element() { blst::blst_p1::uncompress(&element).unwrap() }
|
= element:bls_element() {?
|
||||||
|
blst::blst_p1::uncompress(&element).map_err(|_| "Invalid bls g1 element encoding")
|
||||||
|
}
|
||||||
|
|
||||||
rule g2_element() -> blst::blst_p2
|
rule g2_element() -> blst::blst_p2
|
||||||
= element:bls_element() { blst::blst_p2::uncompress(&element).unwrap() }
|
= element:bls_element() {?
|
||||||
|
blst::blst_p2::uncompress(&element).map_err(|_| "Invalid bls g2 element encoding")
|
||||||
|
}
|
||||||
|
|
||||||
rule string() -> String
|
rule string() -> String
|
||||||
= "\"" s:character()* "\"" { String::from_iter(s) }
|
= "\"" s:character()* "\"" { String::from_iter(s) }
|
||||||
|
|
|
@ -16,8 +16,10 @@ const EVALUATION_FAILURE: &str = "evaluation failure";
|
||||||
fn expected_to_program(expected_file: &PathBuf) -> Result<Program<Name>, String> {
|
fn expected_to_program(expected_file: &PathBuf) -> Result<Program<Name>, String> {
|
||||||
let code = fs::read_to_string(expected_file).expect("Failed to read .uplc.expected file");
|
let code = fs::read_to_string(expected_file).expect("Failed to read .uplc.expected file");
|
||||||
|
|
||||||
if code == PARSE_ERROR || code == EVALUATION_FAILURE {
|
if code.contains(PARSE_ERROR) {
|
||||||
Err(code)
|
Err(PARSE_ERROR.to_string())
|
||||||
|
} else if code.contains(EVALUATION_FAILURE) {
|
||||||
|
Err(EVALUATION_FAILURE.to_string())
|
||||||
} else {
|
} else {
|
||||||
parser::program(&code).map_err(|_| code)
|
parser::program(&code).map_err(|_| code)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue