Add bounded structured crypto operations
This commit is contained in:
@@ -3674,6 +3674,28 @@ private:
|
||||
return(add([self](Caller, Span<const Val> args, Span<Val> results) -> Result<std::monostate, Trap> { String password,encoded; self->hostcall_read(args[0].i32(), args[1].i32(), password); self->hostcall_read(args[2].i32(), args[3].i32(), encoded); bool valid=password_verify_native(password,encoded); results[0]=Val((int32_t)(valid?1:0)); return(std::monostate()); }));
|
||||
if(mod == "env" && name == "uce_host_password_needs_rehash")
|
||||
return(add([self](Caller, Span<const Val> args, Span<Val> results) -> Result<std::monostate, Trap> { String encoded; self->hostcall_read(args[0].i32(), args[1].i32(), encoded); results[0]=Val((int32_t)(password_needs_rehash_native(encoded)?1:0)); return(std::monostate()); }));
|
||||
if(mod == "env" && name == "uce_host_crypto_operation")
|
||||
return(add([self](Caller, Span<const Val> args, Span<Val> results) -> Result<std::monostate, Trap> {
|
||||
String encoded, out;
|
||||
DValue request, response;
|
||||
String error;
|
||||
int32_t input_size = args[1].i32();
|
||||
u32 cap = (u32)args[3].i32();
|
||||
int32_t buf = args[2].i32();
|
||||
String stage_key = "crypto_operation";
|
||||
if(!self->hostcall_staged(stage_key, out))
|
||||
{
|
||||
if(input_size > 0 && input_size <= 64 * 1024 && self->hostcall_read(args[0].i32(), input_size, encoded) == "" && ucb_decode(encoded, request, &error))
|
||||
response = crypto_operation_native(request);
|
||||
else
|
||||
response["error"] = "invalid_request";
|
||||
out = ucb_encode(response);
|
||||
if(buf == 0) self->hostcall_stage(stage_key, out);
|
||||
}
|
||||
if(buf && cap >= out.size()) self->hostcall_write(buf, out);
|
||||
results[0] = Val((int32_t)out.size());
|
||||
return(std::monostate());
|
||||
}));
|
||||
if(mod == "env" && name == "uce_host_log")
|
||||
return(add([self](Caller, Span<const Val> args, Span<Val>) -> Result<std::monostate, Trap> {
|
||||
String text;
|
||||
|
||||
Reference in New Issue
Block a user