rauc 0.2.0

Build reliable embedded Linux updates with Rust.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
use std::collections::HashMap;

use serde::{Deserialize, Deserializer, Serialize};

use zbus::as_variant;
use zbus::{DeserializeDict, OwnedVariant, SerializeDict, Signature, Type};

/// Status of a configured artifact repository.
#[derive(DeserializeDict, Type, Debug, Clone, PartialEq, Eq)]
#[zbus(signature = "a{sv}", rename_all = "kebab-case")]
pub struct ArtifactStatusInfo {
    /// Repository name.
    pub name: String,
    /// Human-readable repository description.
    pub description: Option<String>,
    /// Repository storage path.
    pub path: String,

    /// Repository type.
    #[zbus(rename = "type")]
    pub r#type: String,

    /// Slot-class to which the repository belongs.
    pub parent_class: Option<String>,
    /// Artifacts stored in the repository.
    pub artifacts: Vec<ArtifactStatusArtifactInfo>,
}

/// Status of an artifact stored in a repository.
#[derive(DeserializeDict, Type, Debug, Clone, PartialEq, Eq)]
#[zbus(signature = "a{sv}", rename_all = "kebab-case")]
pub struct ArtifactStatusArtifactInfo {
    /// Artifact name.
    pub name: String,
    /// Available instances of the artifact.
    pub instances: Vec<ArtifactStatusInstanceInfo>,
}

/// Status of one artifact instance.
#[derive(DeserializeDict, Type, Debug, Clone, PartialEq, Eq)]
#[zbus(signature = "a{sv}", rename_all = "kebab-case")]
pub struct ArtifactStatusInstanceInfo {
    /// Checksum identifying the instance.
    pub checksum: String,
    /// Names that refer to this instance.
    pub references: Vec<String>,
}

/// Runtime state of a slot.
#[derive(Deserialize, Type, Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[serde(rename_all = "lowercase")]
#[zbus(signature = "s")]
pub enum SlotState {
    /// The system was booted from this slot.
    Booted,
    /// The slot is active but was not booted.
    Active,
    /// The slot is inactive.
    Inactive,
}

/// Bootloader status of a slot.
#[derive(Deserialize, Type, Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[serde(rename_all = "lowercase")]
#[zbus(signature = "s")]
pub enum SlotBootStatus {
    /// The slot is considered bootable.
    Good,
    /// The slot is considered unbootable.
    Bad,
    /// The boot status could not be determined.
    Unknown,
}

/// Result of the most recent installation to a slot.
#[derive(Deserialize, Type, Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[serde(rename_all = "lowercase")]
#[zbus(signature = "s")]
pub enum SlotInstallationStatus {
    /// Installation completed successfully.
    Ok,
    /// Installation failed.
    Failed,
    /// The slot is currently being updated.
    Pending,
}

/// Name identifying a RAUC slot, such as `rootfs.0`.
pub type SlotName = String;

/// Slot selector accepted by the mark operation.
#[derive(Type, Debug, Clone, PartialEq, Eq, Hash)]
#[zbus(signature = "s")]
pub enum SlotIdentifier {
    /// Select the currently booted slot.
    Booted,
    /// Select the other slot.
    Other,
    /// Select a slot by its configured name, such as `rootfs.1`.
    Named(SlotName),
}

impl SlotIdentifier {
    /// Returns the string passed to RAUC.
    pub fn as_str(&self) -> &str {
        match self {
            Self::Booted => "booted",
            Self::Other => "other",
            Self::Named(name) => name,
        }
    }
}

impl Serialize for SlotIdentifier {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        serializer.serialize_str(self.as_str())
    }
}

/// Status and metadata of a RAUC slot.
#[derive(DeserializeDict, Type, Debug, Clone, PartialEq, Eq)]
#[zbus(signature = "a{sv}", rename_all = "kebab-case")]
pub struct GetSlotStatusInfo {
    /// Slot class, such as `rootfs`.
    pub class: String,
    /// Backing device path.
    pub device: String,

    /// Slot type configured by RAUC.
    #[zbus(rename = "type")]
    pub r#type: String,

    /// Name used by the bootloader.
    pub bootname: Option<String>,
    /// Current runtime state.
    pub state: Option<SlotState>,
    /// Name of the parent slot.
    pub parent: Option<String>,
    /// Current mount point.
    pub mountpoint: Option<String>,
    /// Status reported by the bootloader.
    pub boot_status: Option<SlotBootStatus>,
    /// Result of the most recent installation.
    pub status: Option<SlotInstallationStatus>,
    /// SHA-256 checksum of the last installed image.
    pub sha256: Option<String>,
    /// Size of the last installed image in bytes.
    pub size: Option<u64>,

    /// ISO 8601 timestamp when the last installation completed.
    #[zbus(rename = "installed.timestamp")]
    pub installed_timestamp: Option<String>,

    /// Number of images written to the slot.
    #[zbus(rename = "installed.count")]
    pub installed_count: Option<u32>,

    /// Transaction UUID of the last installation.
    #[zbus(rename = "installed.transaction")]
    pub installed_transaction: Option<String>,

    /// ISO 8601 timestamp when the slot was last activated.
    #[zbus(rename = "activated.timestamp")]
    pub activated_timestamp: Option<String>,

    /// Number of times the slot has been activated.
    #[zbus(rename = "activated.count")]
    pub activated_count: Option<u32>,

    /// Compatibility identifier from the last installed bundle.
    #[zbus(rename = "bundle.compatible")]
    pub bundle_compatible: Option<String>,

    /// Version from the last installed bundle.
    #[zbus(rename = "bundle.version")]
    pub bundle_version: Option<String>,

    /// Description from the last installed bundle.
    #[zbus(rename = "bundle.description")]
    pub bundle_description: Option<String>,

    /// Build identifier from the last installed bundle.
    #[zbus(rename = "bundle.build")]
    pub bundle_build: Option<String>,

    /// Manifest hash of the last installed bundle.
    #[zbus(rename = "bundle.hash")]
    pub bundle_hash: Option<String>,
}

/// Options for inspecting a local or remote bundle.
#[derive(SerializeDict, DeserializeDict, Type, Debug, Clone, PartialEq, Eq, Default)]
#[zbus(signature = "a{sv}", rename_all = "kebab-case")]
pub struct InspectBundleArgs {
    /// Certificate file or PKCS#11 URL used for TLS client authentication.
    pub tls_cert: Option<String>,
    /// Private-key file or PKCS#11 URL used for TLS client authentication.
    pub tls_key: Option<String>,
    /// Certificate file or PKCS#11 URL used instead of the system trust store.
    pub tls_ca: Option<String>,
    /// Additional headers sent with every HTTP request.
    pub http_headers: Option<Vec<String>>,
    /// Whether to ignore server certificate verification errors.
    pub tls_no_verify: Option<bool>,
}

/// Metadata read from an inspected bundle.
///
/// RAUC's variant wrappers are consumed during deserialization, exposing only
/// the typed metadata to callers.
#[derive(Deserialize, Type, Debug, Clone, PartialEq, Eq)]
#[zbus(signature = "a{sv}")]
#[serde(rename_all = "kebab-case")]
pub struct InspectBundleInfo {
    /// SHA-256 hash of the bundle manifest.
    #[serde(with = "as_variant")]
    pub manifest_hash: String,
    /// Bundle update metadata.
    #[serde(deserialize_with = "decode_variant_layers")]
    pub update: InspectBundleUpdateInfo,
    /// Bundle format and integrity metadata.
    #[serde(deserialize_with = "decode_variant_layers")]
    pub bundle: InspectBundleBundleInfo,
    /// Hooks declared by the bundle.
    #[serde(default, deserialize_with = "decode_optional_variant_layers")]
    pub hooks: Option<InspectBundleHooksInfo>,
    /// Custom handler declared by the bundle.
    #[serde(default, deserialize_with = "decode_optional_variant_layers")]
    pub handler: Option<InspectBundleHandlerInfo>,
    /// Images contained in the bundle.
    #[serde(deserialize_with = "decode_variant_layers")]
    pub images: Vec<InspectBundleImageInfo>,
    /// Custom manifest metadata grouped by section.
    #[serde(deserialize_with = "decode_variant_layers")]
    pub meta: HashMap<String, HashMap<String, String>>,
}

/// Update metadata from a bundle manifest.
#[derive(DeserializeDict, Type, Debug, Clone, PartialEq, Eq)]
#[zbus(signature = "a{sv}", rename_all = "kebab-case")]
pub struct InspectBundleUpdateInfo {
    /// System compatibility identifier from the manifest.
    pub compatible: String,
    /// Bundle version.
    pub version: Option<String>,
    /// Human-readable bundle description.
    pub description: Option<String>,
    /// Bundle build identifier.
    pub build: Option<String>,
}

/// Format used to package a RAUC bundle.
#[derive(Deserialize, Type, Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[serde(rename_all = "lowercase")]
#[zbus(signature = "s")]
pub enum BundleFormat {
    /// Plain bundle format.
    Plain,
    /// Verity-protected bundle format.
    Verity,
    /// Encrypted, verity-protected bundle format.
    Crypt,
}

/// Bundle format and integrity metadata.
#[derive(DeserializeDict, Type, Debug, Clone, PartialEq, Eq)]
#[zbus(signature = "a{sv}", rename_all = "kebab-case")]
pub struct InspectBundleBundleInfo {
    /// Bundle format.
    pub format: BundleFormat,
    /// Size of the verity-protected payload in bytes.
    pub verity_size: Option<u64>,
    /// Salt used by the verity-protected payload.
    pub verity_salt: Option<String>,
    /// Root hash of the verity-protected payload.
    pub verity_hash: Option<String>,
}

/// Hook metadata from a bundle manifest.
#[derive(Deserialize, Type, Debug, Clone, PartialEq, Eq)]
#[zbus(signature = "a{sv}")]
#[serde(rename_all = "kebab-case")]
pub struct InspectBundleHooksInfo {
    /// Name of the hook executable.
    #[serde(with = "as_variant")]
    pub filename: String,
    /// Hooks enabled for the bundle.
    #[serde(deserialize_with = "decode_variant_layers")]
    pub hooks: Vec<String>,
}

/// Custom handler metadata from a bundle manifest.
#[derive(DeserializeDict, Type, Debug, Clone, PartialEq, Eq)]
#[zbus(signature = "a{sv}", rename_all = "kebab-case")]
pub struct InspectBundleHandlerInfo {
    /// Name of the custom handler executable.
    pub filename: String,
    /// Arguments passed to the custom handler.
    pub args: Option<String>,
}

/// Metadata for an image contained in a bundle.
#[derive(DeserializeDict, Type, Debug, Clone, PartialEq, Eq)]
#[zbus(signature = "a{sv}", rename_all = "kebab-case")]
pub struct InspectBundleImageInfo {
    /// Target slot class.
    pub slot_class: String,
    /// Target system variant.
    pub variant: Option<String>,
    /// Image filename within the bundle.
    pub filename: Option<String>,

    /// Image type.
    #[zbus(rename = "type")]
    pub r#type: Option<String>,

    /// SHA-256 checksum of the original image.
    pub checksum: Option<String>,
    /// Image size in bytes.
    pub size: Option<u64>,
    /// Hooks enabled for the image.
    pub hooks: Vec<String>,
    /// Adaptive update methods enabled for the image.
    pub adaptive: Option<Vec<String>>,
}

/// Options for installing a local or remote bundle.
#[derive(SerializeDict, DeserializeDict, Type, Debug, Clone, PartialEq, Eq, Default)]
#[zbus(signature = "a{sv}", rename_all = "kebab-case")]
pub struct InstallBundleArgs {
    /// Whether to ignore a mismatch with the system compatibility identifier.
    pub ignore_compatible: Option<bool>,
    /// Whether to ignore the configured minimum bundle version.
    pub ignore_version_limit: Option<bool>,
    /// UUID identifying the installation transaction.
    pub transaction_id: Option<String>,
    /// Expected manifest hash; installation stops if it does not match.
    pub require_manifest_hash: Option<String>,
    /// Certificate file or PKCS#11 URL used for TLS client authentication.
    pub tls_cert: Option<String>,
    /// Private-key file or PKCS#11 URL used for TLS client authentication.
    pub tls_key: Option<String>,
    /// Certificate file or PKCS#11 URL used instead of the system trust store.
    pub tls_ca: Option<String>,
    /// Additional headers sent with every HTTP request.
    pub http_headers: Option<Vec<String>>,
    /// Whether to ignore server certificate verification errors.
    pub tls_no_verify: Option<bool>,
}

/// Action used to mark a slot.
#[derive(Serialize, Deserialize, Type, Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[serde(rename_all = "lowercase")]
#[zbus(signature = "s")]
pub enum MarkState {
    /// Mark the slot as bootable.
    Good,
    /// Mark the slot as unbootable.
    Bad,
    /// Select the slot for the next boot.
    Active,
}

/// Result of marking a slot as good, bad, or active.
#[derive(OwnedVariant, Type, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct MarkInfo {
    /// Name of the slot that was marked.
    pub slot_name: String,
    /// Human-readable description of the completed action.
    pub message: String,
}

/// Operation currently performed by RAUC.
#[derive(OwnedVariant, Type, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[zbus(signature = "s", rename_all = "lowercase")]
#[serde(rename_all = "lowercase")]
pub enum Operation {
    /// RAUC is not performing an operation.
    Idle,
    /// RAUC is installing a bundle.
    Installing,
}

/// Result reported by the installation completion signal.
#[derive(Deserialize, Type, Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[serde(from = "i32")]
#[zbus(signature = "i")]
pub enum InstallationResult {
    /// Installation completed successfully (result code zero).
    Success,
    /// Installation failed, preserving the nonzero result code.
    Failure(i32),
}

impl From<i32> for InstallationResult {
    fn from(code: i32) -> Self {
        match code {
            0 => Self::Success,
            code => Self::Failure(code),
        }
    }
}

/// Progress of the current installation operation.
#[derive(OwnedVariant, Type, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct Progress {
    /// Completion percentage from 0 to 100.
    pub percentage: i32,
    /// Human-readable description of the current step.
    pub message: String,
    /// Nesting level of the current step.
    pub nesting_depth: i32,
}

/// One explicit D-Bus variant layer containing `T`.
///
/// Consumes the outer signature and payload explicitly, leaving the inner
/// variant to `as_variant::Deserialize` for unwrapping and signature validation.
#[derive(Deserialize)]
struct Variant<T> {
    #[allow(dead_code)]
    signature: Signature,
    value: T,
}

// Keep RAUC's two variant layers out of the public metadata API.
fn decode_variant_layers<'de, D, T>(deserializer: D) -> Result<T, D::Error>
where
    D: Deserializer<'de>,
    T: Deserialize<'de> + Type + 'de,
{
    let wrapped = Variant::<as_variant::Deserialize<'de, T>>::deserialize(deserializer)?;
    Ok(wrapped.value.0)
}

// Decode both variant layers into Some(T). Missing keys are handled as None.
fn decode_optional_variant_layers<'de, D, T>(deserializer: D) -> Result<Option<T>, D::Error>
where
    D: Deserializer<'de>,
    T: Deserialize<'de> + Type + 'de,
{
    decode_variant_layers(deserializer).map(Some)
}