2021-02-12 14:42:51 +03:00
|
|
|
use crate::dto::Certificate;
|
2021-02-10 15:26:26 +03:00
|
|
|
use crate::results::{AllCertsResult, InsertResult, WeightResult};
|
2021-02-12 14:42:51 +03:00
|
|
|
use crate::service_impl::{
|
|
|
|
get_all_certs_impl, get_weight_impl, insert_cert_impl, insert_cert_impl_raw,
|
|
|
|
};
|
2021-01-25 15:32:43 +03:00
|
|
|
use fluence::fce;
|
2021-02-12 14:34:23 +03:00
|
|
|
|
2021-02-10 15:23:51 +03:00
|
|
|
#[fce]
|
2021-02-12 14:27:22 +03:00
|
|
|
/// add a certificate in string representation to trust graph if it is valid
|
2021-02-12 14:34:23 +03:00
|
|
|
/// see `trust_graph::Certificate` class for string encoding/decoding
|
2021-02-12 14:27:22 +03:00
|
|
|
// TODO change `current_time` to time service
|
2021-02-12 14:34:23 +03:00
|
|
|
fn insert_cert_raw(certificate: String, current_time: u64) -> InsertResult {
|
|
|
|
insert_cert_impl_raw(certificate, current_time).into()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[fce]
|
|
|
|
/// add a certificate in JSON representation to trust graph if it is valid
|
|
|
|
/// see `dto::Certificate` class for structure
|
|
|
|
fn insert_cert(certificate: Certificate, current_time: u64) -> InsertResult {
|
2021-02-12 14:27:22 +03:00
|
|
|
insert_cert_impl(certificate, current_time).into()
|
2021-01-27 12:57:19 +03:00
|
|
|
}
|
|
|
|
|
2021-02-10 15:23:51 +03:00
|
|
|
#[fce]
|
|
|
|
fn get_weight(public_key: String) -> WeightResult {
|
|
|
|
get_weight_impl(public_key).into()
|
|
|
|
}
|
|
|
|
|
2021-02-11 15:10:18 +03:00
|
|
|
#[fce]
|
2021-02-10 15:23:51 +03:00
|
|
|
fn get_all_certs(issued_for: String) -> AllCertsResult {
|
|
|
|
get_all_certs_impl(issued_for).into()
|
|
|
|
}
|
|
|
|
|
2021-02-12 14:42:51 +03:00
|
|
|
// TODO rewrite test after #[fce_test] will be implemented
|
|
|
|
// #[fce]
|
|
|
|
// fn test() -> String {
|
|
|
|
// let mut tg = get_data().lock();
|
|
|
|
//
|
|
|
|
// let root_kp = KeyPair::generate();
|
|
|
|
// let root_kp2 = KeyPair::generate();
|
|
|
|
// let second_kp = KeyPair::generate();
|
|
|
|
//
|
|
|
|
// let expires_at = Duration::new(15, 15);
|
|
|
|
// let issued_at = Duration::new(5, 5);
|
|
|
|
//
|
|
|
|
// let cert = trust_graph::Certificate::issue_root(
|
|
|
|
// &root_kp,
|
|
|
|
// second_kp.public_key(),
|
|
|
|
// expires_at,
|
|
|
|
// issued_at,
|
|
|
|
// );
|
|
|
|
// tg.add_root_weight(root_kp.public().into(), 0).unwrap();
|
|
|
|
// tg.add_root_weight(root_kp2.public().into(), 1).unwrap();
|
|
|
|
// tg.add(cert, Duration::new(10, 10)).unwrap();
|
|
|
|
//
|
|
|
|
// let a = tg.get(second_kp.public_key()).unwrap();
|
|
|
|
// let str = format!("{:?}", a);
|
|
|
|
// log::info!("{}", &str);
|
|
|
|
//
|
|
|
|
// str
|
|
|
|
// }
|