omaha_client/configuration.rs
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
// Copyright 2019 The Fuchsia Authors
//
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
// This file may not be copied, modified, or distributed except according to
// those terms.
use crate::cup_ecdsa::PublicKeys;
use crate::protocol::request::OS;
use crate::version::Version;
/// This is the name and version of the updater binary that is built using this crate.
///
/// This is how the updater identifies itself with the Omaha service.
///
#[derive(Clone, Debug)]
pub struct Updater {
/// The string identifying the updater itself. (e.g. 'Omaha', 'Fuchsia/Rust')
pub name: String,
/// The version of the updater itself. (e.g '0.0.1.0')
pub version: Version,
}
/// This struct wraps up the configuration data that an updater binary needs to supply.
///
#[derive(Clone, Debug)]
pub struct Config {
pub updater: Updater,
pub os: OS,
/// This is the address of the Omaha service that should be used.
pub service_url: String,
/// These are the public keys to use when communicating with the Omaha server.
pub omaha_public_keys: Option<PublicKeys>,
}
#[cfg(test)]
pub mod test_support {
use super::*;
use crate::cup_ecdsa::{PublicKeyAndId, PublicKeys};
use p256::ecdsa::{SigningKey, VerifyingKey};
use signature::rand_core::OsRng;
use std::convert::TryInto;
/// Handy generator for an updater configuration. Used to reduce test boilerplate.
pub fn config_generator() -> Config {
let signing_key = SigningKey::random(&mut OsRng);
let omaha_public_keys = PublicKeys {
latest: PublicKeyAndId {
id: 42.try_into().unwrap(),
key: VerifyingKey::from(&signing_key),
},
historical: vec![],
};
Config {
updater: Updater {
name: "updater".to_string(),
version: Version::from([1, 2, 3, 4]),
},
os: OS {
platform: "platform".to_string(),
version: "0.1.2.3".to_string(),
service_pack: "sp".to_string(),
arch: "test_arch".to_string(),
},
service_url: "http://example.com/".to_string(),
omaha_public_keys: Some(omaha_public_keys),
}
}
}