-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
305 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
(typename $shield_backend_options | ||
(flags (@witx repr u32) | ||
$reserved | ||
$use_cache_key | ||
)) | ||
|
||
(typename $shield_backend_config | ||
(record | ||
(field $cache_key (@witx pointer (@witx char8))) | ||
(field $cache_key_len u32) | ||
)) | ||
|
||
(module $fastly_shielding | ||
|
||
(@interface func (export "shield_info") | ||
(param $name string) | ||
(param $info_block (@witx pointer (@witx char8))) | ||
(param $info_block_max_len (@witx usize)) | ||
(result $err (expected $num_bytes (error $fastly_status))) | ||
) | ||
|
||
(@interface func (export "backend_for_shield") | ||
(param $shield_name string) | ||
(param $backend_config_mask $shield_backend_options) | ||
(param $backend_configuration (@witx pointer $shield_backend_config)) | ||
(param $backend_name_out (@witx pointer (@witx char8))) | ||
(param $backend_name_max_len (@witx usize)) | ||
(result $err (expected $num_bytes (error $fastly_status))) | ||
) | ||
|
||
) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use super::fastly::api::{shielding, types}; | ||
use crate::linking::ComponentCtx; | ||
|
||
#[async_trait::async_trait] | ||
impl shielding::Host for ComponentCtx { | ||
async fn shield_info(&mut self, name: Vec<u8>, _max_len: u64) -> Result<Vec<u8>, types::Error> { | ||
// Validate input name and return the unsupported error. | ||
let _name = String::from_utf8(name)?; | ||
|
||
Err(types::Error::Unsupported) | ||
} | ||
|
||
async fn backend_for_shield( | ||
&mut self, | ||
name: Vec<u8>, | ||
options_mask: shielding::ShieldBackendOptionsMask, | ||
options: shielding::ShieldBackendOptions, | ||
_max_len: u64, | ||
) -> Result<Vec<u8>, types::Error> { | ||
// Validate our inputs and return the unsupported error. | ||
let _target_shield = String::from_utf8(name)?; | ||
|
||
if options_mask.contains(shielding::ShieldBackendOptionsMask::CACHE_KEY) { | ||
let _ = String::from_utf8(options.cache_key)?; | ||
} | ||
|
||
Err(types::Error::Unsupported) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use crate::error::Error; | ||
use crate::session::Session; | ||
use crate::wiggle_abi::{fastly_shielding, types}; | ||
|
||
impl fastly_shielding::FastlyShielding for Session { | ||
fn shield_info( | ||
&mut self, | ||
memory: &mut wiggle::GuestMemory<'_>, | ||
name: wiggle::GuestPtr<str>, | ||
_out_buffer: wiggle::GuestPtr<u8>, | ||
_out_buffer_max_len: u32, | ||
) -> Result<u32, Error> { | ||
// Validate the input name and then return the unsupported error. | ||
let name_bytes = memory.to_vec(name.as_bytes())?; | ||
let _name = String::from_utf8(name_bytes).map_err(|_| Error::InvalidArgument)?; | ||
|
||
Err(Error::Unsupported { | ||
msg: "shielding hostcalls are not supported", | ||
}) | ||
} | ||
|
||
fn backend_for_shield( | ||
&mut self, | ||
memory: &mut wiggle::GuestMemory<'_>, | ||
shield_name: wiggle::GuestPtr<str>, | ||
shield_backend_options: types::ShieldBackendOptions, | ||
shield_backend_config: wiggle::GuestPtr<types::ShieldBackendConfig>, | ||
_out_buffer: wiggle::GuestPtr<u8>, | ||
_out_buffer_max_len: u32, | ||
) -> Result<u32, Error> { | ||
// Validate our inputs and then return the unsupported error. | ||
let Some(_) = memory.as_str(shield_name)?.map(str::to_string) else { | ||
return Err(Error::ValueAbsent); | ||
}; | ||
|
||
if shield_backend_options.contains(types::ShieldBackendOptions::RESERVED) { | ||
return Err(Error::InvalidArgument); | ||
} | ||
|
||
let config = memory.read(shield_backend_config)?; | ||
|
||
if shield_backend_options.contains(types::ShieldBackendOptions::USE_CACHE_KEY) { | ||
let field_string = config.cache_key.as_array(config.cache_key_len).cast(); | ||
if memory.as_str(field_string)?.is_none() { | ||
return Err(Error::InvalidArgument); | ||
} | ||
} | ||
|
||
Err(Error::Unsupported { | ||
msg: "shielding hostcalls are not supported", | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters