Crate tuf [] [src]

This crate provides an API for talking to repositories that implement The Update Framework (TUF).

If you are unfamiliar with TUF, you should read up on via the official website. This crate aims to implement the entirety of the specification as defined at the head of the develop branch in the official TUF git repository.

Example

extern crate hyper;
extern crate tuf;
extern crate url;

use hyper::client::Client as HttpClient;
use std::path::PathBuf;
use tuf::Tuf;
use tuf::crypto::KeyId;
use tuf::client::{Client, Config};
use tuf::metadata::{RootMetadata, SignedMetadata, Role, MetadataPath,
    MetadataVersion};
use tuf::interchange::JsonDataInterchange;
use tuf::repository::{Repository, FileSystemRepository, HttpRepository};
use url::Url;

static TRUSTED_ROOT_KEY_IDS: &'static [&str] = &[
    "diNfThTFm0PI8R-Bq7NztUIvZbZiaC_weJBgcqaHlWw=",
    "ar9AgoRsmeEcf6Ponta_1TZu1ds5uXbDemBig30O7ck=",
    "T5vfRrM1iHpgzGwAHe7MbJH_7r4chkOAphV3OPCCv0I=",
];

fn main() {
    let key_ids: Vec<KeyId> = TRUSTED_ROOT_KEY_IDS.iter()
        .map(|k| KeyId::from_string(k).unwrap())
        .collect();

    let mut local = FileSystemRepository::new(PathBuf::from("~/.rustup"));

    let mut remote = HttpRepository::new(
        Url::parse("https://static.rust-lang.org/").unwrap(),
        HttpClient::new(),
        Some("rustup/1.4.0".into()));

    let config = Config::build().finish().unwrap();

    // fetching this original root from the network is safe because
    // we are using trusted, pinned keys to verify it
    let root = remote.fetch_metadata(&Role::Root,
                                     &MetadataPath::from_role(&Role::Root),
                                     &MetadataVersion::None,
                                     config.max_root_size(),
                                     None).unwrap();

    let tuf = Tuf::<JsonDataInterchange>::from_root_pinned(root, &key_ids).unwrap();

    let mut client = Client::new(tuf, config, local, remote).unwrap();
    let _ = client.update_local().unwrap();
    let _ = client.update_remote().unwrap();
}

Reexports

pub use tuf::*;
pub use error::*;

Modules

client

Clients for high level interactions with TUF repositories.

crypto

Cryptographic structures and functions.

error

Error types and converters.

interchange

Structures and functions to aid in various TUF data interchange formats.

metadata

Structures used to represent TUF metadata

repository

Interfaces for interacting with different types of TUF repositories.

tuf

Components needed to verify TUF metadata and targets.

Type Definitions

Result

Alias for Result<T, Error>.