#[non_exhaustive]pub struct Bundle {
pub code: BundleCode,
pub source_map: Option<Arc<str>>,
pub policy: Policy,
pub base_url: Option<Arc<str>>,
pub chunks: Arc<Vec<Chunk>>,
pub harden_bytecode: Option<Arc<Vec<u8>>>,
pub app_id: Option<String>,
pub system_paths: TrustedPaths,
pub package: Option<Arc<PackageInfo>>,
}Expand description
An app bundle: its code plus, in development, a source map.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.code: BundleCodeThe code.
source_map: Option<Arc<str>>Source map (JSON) used to show app source locations in stack traces.
policy: PolicyWhat the code may do.
base_url: Option<Arc<str>>What relative request URLs resolve against (the page’s URL on the
web); None: they are invalid.
chunks: Arc<Vec<Chunk>>The chunks of a split bundle that come with it (import() loads
them without asking the platform); those missing are asked of
MountSink::load_chunk. Shared by the bundle’s clones.
harden_bytecode: Option<Arc<Vec<u8>>>The sandbox’s hardening as bytecode (nsh_js::compile_harden),
for a runtime without QuickJS’ parser (the web runtime of published
apps); None: compiled when the policy hardens. Set it with
Bundle::with_harden_bytecode.
app_id: Option<String>The app’s id (nsh.json "id"; a signed package’s verified one):
it names where the app keeps its data (nsh/storage).
system_paths: TrustedPathsTrusted filesystem anchors selected by the native host, never decoded from application code, its manifest or a development server message. Missing anchors deny relative and corresponding placeholder grants.
package: Option<Arc<PackageInfo>>The signed package the bundle came from (Bundle::from_package),
named in the app’s errors (AppError::package).
Implementations§
Source§impl Bundle
impl Bundle
Sourcepub unsafe fn bytecode(bytes: Vec<u8>) -> Self
pub unsafe fn bytecode(bytes: Vec<u8>) -> Self
A bytecode bundle.
§Safety
bytes must be bytecode from nsh_js::compile_bytecode for this
runtime’s BYTECODE_VERSION, from a trusted source: QuickJS does not
validate bytecode, and loading crafted bytecode corrupts memory. Trusted
are the app’s own signed resources, a development server the developer
pointed the host at, and verified packages (Bundle::from_package).
Sourcepub fn with_system_paths(self, paths: TrustedPaths) -> Self
pub fn with_system_paths(self, paths: TrustedPaths) -> Self
Selects trusted source/package and home directory anchors. Supplying a path grants nothing by itself: the manifest and host grant must still allow the filesystem operation. Only existing absolute directories are accepted; unavailable anchors are left unset.
Sourcepub fn with_app_id(self, id: Option<&str>) -> Self
pub fn with_app_id(self, id: Option<&str>) -> Self
The app’s id (Bundle::app_id), as nsh.json or the dev server
gives it.
Sourcepub fn with_source_map(self, map: impl Into<Arc<str>>) -> Self
pub fn with_source_map(self, map: impl Into<Arc<str>>) -> Self
Attaches a source map.
Sourcepub fn with_base_url(self, url: impl Into<Arc<str>>) -> Self
pub fn with_base_url(self, url: impl Into<Arc<str>>) -> Self
Sets the URL relative request URLs resolve against.
Sourcepub unsafe fn with_harden_bytecode(self, bytes: Vec<u8>) -> Self
pub unsafe fn with_harden_bytecode(self, bytes: Vec<u8>) -> Self
Hardens with bytes (Bundle::harden_bytecode).
§Safety
As Bundle::bytecode: bytes comes from nsh_js::compile_harden
of this runtime’s BYTECODE_VERSION, from a trusted source.
Sourcepub fn with_policy(self, policy: Policy) -> Self
pub fn with_policy(self, policy: Policy) -> Self
Replaces the policy.
Sourcepub fn with_chunks(self, chunks: impl IntoIterator<Item = Chunk>) -> Self
pub fn with_chunks(self, chunks: impl IntoIterator<Item = Chunk>) -> Self
Adds chunks of a split bundle (see Bundle::chunks).
Sourcepub fn read(path: &Path) -> Result<Bundle>
pub fn read(path: &Path) -> Result<Bundle>
Reads a JS source bundle written by nsh build (bundle.js), plus
bundle.js.map, the app’s capabilities.json and its id
(app.json "id") next to it if present. Bytecode (bundle.nshc) is refused: files can be replaced, and
only Bundle::read_trusted (the app’s own resources) or a verified
package may load bytecode.
Sourcepub unsafe fn read_trusted(path: &Path) -> Result<Bundle>
pub unsafe fn read_trusted(path: &Path) -> Result<Bundle>
Like Bundle::read, also reading bundle.nshc as bytecode.
§Safety
A .nshc file must be trusted as Bundle::bytecode requires (e.g.
inside the app’s own signed bundle).
Source§impl Bundle
impl Bundle
Sourcepub fn from_package(package: &VerifiedPackage) -> Result<Bundle, String>
pub fn from_package(package: &VerifiedPackage) -> Result<Bundle, String>
The bundle of a verified package: its bytecode when it was compiled for this runtime (else its source), its source map and its declared capabilities. What a newer signer wrote that this runtime does not know (header fields, files, capabilities) is logged and left out: an unknown capability is not granted.