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§
sourcefn info(&self) -> &HostInfo
fn info(&self) -> &HostInfo
Informations about the host.
This returns the information that is common to all hosts, and is easy to marshal to dump/restore.
sourcefn verify_msg(&self, msg: &[u8], sig: &[u8]) -> Result<(), Error>
fn verify_msg(&self, msg: &[u8], sig: &[u8]) -> Result<(), Error>
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§
sourcefn id(&self) -> HostId
fn id(&self) -> HostId
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());sourcefn name(&self) -> &String
fn name(&self) -> &String
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());sourcefn description(&self) -> &String
fn description(&self) -> &String
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());sourcefn urls(&self) -> &Vec<Url> ⓘ
fn urls(&self) -> &Vec<Url> ⓘ
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());sourcefn sig(&self) -> &Vec<u8> ⓘ
fn sig(&self) -> &Vec<u8> ⓘ
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());sourcefn verify_self(&self) -> Result<(), Error>
fn verify_self(&self) -> Result<(), Error>
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?
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)
}