NAH 1.0.6
Native Application Host - Library API Reference
Loading...
Searching...
No Matches
materializer.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <string>
5#include <vector>
6
7namespace nah {
8
9// ============================================================================
10// Build-Time Remote Materialization Utilities (per SPEC L2815-L2890)
11// ============================================================================
12//
13// This module provides utility functions for remote artifact handling:
14// - Parsing artifact references (file: and https:// URLs)
15// - SHA-256 hash computation and verification
16// - HTTPS fetching
17//
18// These utilities are used by install_nak() and install_app() in packaging.hpp
19// to support remote sources. For installation, use those functions directly.
20//
21// IMPORTANT: Contract composition (nah contract show / compose_contract)
22// MUST NOT perform any network operations. It operates only on local state.
23
24// ============================================================================
25// Remote Artifact Reference Parsing
26// ============================================================================
27
28enum class ReferenceType {
29 File, // file:<path>
30 Https, // https://...#sha256=<hex>
32};
33
36 std::string path_or_url; // File path or HTTPS URL (without fragment)
37 std::string sha256_digest; // Required for HTTPS, empty for file:
38 std::string error; // Error message if invalid
39};
40
41// Parse a NAK pack reference string
42// Accepts:
43// - file:<absolute_or_relative_path>
44// - https://...#sha256=<64_hex_chars>
46
47// ============================================================================
48// SHA-256 Hashing
49// ============================================================================
50
51struct HashResult {
52 bool ok = false;
53 std::string error;
54 std::string hex_digest; // Lowercase hex string (64 chars)
55};
56
57// Compute SHA-256 hash of data
58HashResult compute_sha256(const std::vector<uint8_t>& data);
60
61// Verify data matches expected SHA-256 digest
63 bool ok = false;
64 std::string error;
65 std::string actual_digest;
66 std::string expected_digest;
67};
68
69Sha256VerifyResult verify_sha256(const std::vector<uint8_t>& data,
70 const std::string& expected_hex);
71
72// ============================================================================
73// HTTP Fetching
74// ============================================================================
75
77 bool ok = false;
78 std::string error;
79 std::vector<uint8_t> data;
80 long http_status = 0;
81 std::string content_type;
82};
83
84// Fetch data from an HTTPS URL
85// Follows redirects, verifies TLS certificates
86FetchResult fetch_https(const std::string& url);
87
88} // namespace nah
Result type for fallible operations.
Definition nahhost.hpp:109
FetchResult fetch_https(const std::string &url)
HashResult compute_sha256(const std::vector< uint8_t > &data)
Sha256VerifyResult verify_sha256(const std::vector< uint8_t > &data, const std::string &expected_hex)
ParsedReference parse_artifact_reference(const std::string &reference)
std::string content_type
std::string error
std::vector< uint8_t > data
std::string hex_digest
std::string error
std::string sha256_digest