Trait confitul::Host

source ·
pub trait Host {
    fn info(&self) -> &HostInfo;
    fn verify_msg(&self, msg: &[u8], sig: &[u8]) -> Result<(), Error>;

    fn id(&self) -> HostId { ... }
    fn name(&self) -> &String { ... }
    fn description(&self) -> &String { ... }
    fn urls(&self) -> &Vec<Url>  { ... }
    fn sig(&self) -> &Vec<u8>  { ... }
    fn verify_self(&self) -> Result<(), Error> { ... }
}

Required Methods§

Informations about the host.

This returns the information that is common to all hosts, and is easy to marshal to dump/restore.

Verify a message signature.

Useful to check incoming messages, check they come from the right host and have been correctly signed.

Examples
use confitul::LocalHost;
use confitul::Host;

let local_host = LocalHost::new(None).unwrap();
let msg = "a message".as_bytes();
let sig = local_host.sign_msg(msg);
assert!(matches!(local_host.verify_msg(msg, &sig), Ok(())));
assert!(matches!(local_host.verify_msg(msg, msg), Err(_)));

Provided Methods§

ID of the host.

Helper method to access directly the ID of the host.

Examples
use confitul::LocalHost;
use confitul::Host;

let local_host = LocalHost::new(None).unwrap();
let info = local_host.info();
assert_eq!(info.id, local_host.id());

Name of the host.

Helper method to access directly the name of the host.

Examples
use confitul::LocalHost;
use confitul::Host;
use confitul::LocalHostOptions;

let local_host = LocalHost::new(Some(LocalHostOptions::new().with_name("my-computer"))).unwrap();
assert_eq!("my-computer", local_host.name());

Description of the host.

Helper method to access directly the description of the host.

Examples
use confitul::LocalHost;
use confitul::Host;
use confitul::LocalHostOptions;

let local_host = LocalHost::new(Some(LocalHostOptions::new().with_description("a test"))).unwrap();
assert_eq!("a test", local_host.description());

URLs of the host.

Helper method to access directly the URLs of the host.

Examples
use confitul::LocalHost;
use confitul::Host;

let local_host = LocalHost::new(None).unwrap();
let info = local_host.info();
assert_eq!(&info.urls, local_host.urls());

Signature of the host.

Helper method to access directly the signature of the host.

Examples
use confitul::LocalHost;
use confitul::Host;

let local_host = LocalHost::new(None).unwrap();
let info = local_host.info();
assert_eq!(info.sig.as_ref().unwrap(), local_host.sig());
Examples found in repository?
src/host.rs (line 130)
129
130
131
    fn verify_self(&self) -> Result<(), signature::Error> {
        self.verify_msg(&self.info().content_to_verify(), &self.sig())
    }

Verify this host signature.

This can be used when de-serializing content from external sources -> is that host legit or not ?

Examples
use confitul::LocalHost;
use confitul::Host;

let local_host = LocalHost::new(None).unwrap();
assert!(matches!(local_host.verify_self(), Ok(())));
Examples found in repository?
src/remote_host.rs (line 51)
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
    pub fn new(info: &HostInfo) -> Result<RemoteHost, signature::Error> {
        let pubkey = ed25519_dalek::PublicKey::try_from(info.id)?;
        let remote_host = RemoteHost {
            info: info.clone(),
            pubkey,
        };
        match &info.sig {
            Some(_) => {}
            None => return Err(signature::Error::new()),
        }
        print!("{:?}\n", remote_host.info.sig.as_ref().unwrap());
        print!("{:?}\n", info.sig.as_ref().unwrap());
        remote_host.verify_self()?;
        Ok(remote_host)
    }

Implementors§