omaha_client/configuration.rs
1// Copyright 2019 The Fuchsia Authors
2//
3// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
4// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
5// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
6// This file may not be copied, modified, or distributed except according to
7// those terms.
8
9use crate::cup_ecdsa::PublicKeys;
10use crate::protocol::request::OS;
11use crate::version::Version;
12
13/// This is the name and version of the updater binary that is built using this crate.
14///
15/// This is how the updater identifies itself with the Omaha service.
16///
17#[derive(Clone, Debug)]
18pub struct Updater {
19 /// The string identifying the updater itself. (e.g. 'Omaha', 'Fuchsia/Rust')
20 pub name: String,
21
22 /// The version of the updater itself. (e.g '0.0.1.0')
23 pub version: Version,
24}
25
26/// This struct wraps up the configuration data that an updater binary needs to supply.
27///
28#[derive(Clone, Debug)]
29pub struct Config {
30 pub updater: Updater,
31
32 pub os: OS,
33
34 /// This is the address of the Omaha service that should be used.
35 pub service_url: String,
36
37 /// These are the public keys to use when communicating with the Omaha server.
38 pub omaha_public_keys: Option<PublicKeys>,
39}
40
41#[cfg(test)]
42pub mod test_support {
43
44 use super::*;
45 use crate::cup_ecdsa::{PublicKeyAndId, PublicKeys};
46 use p256::ecdsa::{SigningKey, VerifyingKey};
47 use signature::rand_core::OsRng;
48 use std::convert::TryInto;
49
50 /// Handy generator for an updater configuration. Used to reduce test boilerplate.
51 pub fn config_generator() -> Config {
52 let signing_key = SigningKey::random(&mut OsRng);
53 let omaha_public_keys = PublicKeys {
54 latest: PublicKeyAndId {
55 id: 42.try_into().unwrap(),
56 key: VerifyingKey::from(&signing_key),
57 },
58 historical: vec![],
59 };
60
61 Config {
62 updater: Updater {
63 name: "updater".to_string(),
64 version: Version::from([1, 2, 3, 4]),
65 },
66 os: OS {
67 platform: "platform".to_string(),
68 version: "0.1.2.3".to_string(),
69 service_pack: "sp".to_string(),
70 arch: "test_arch".to_string(),
71 },
72 service_url: "http://example.com/".to_string(),
73 omaha_public_keys: Some(omaha_public_keys),
74 }
75 }
76}