cred_store_testing_ext.rs 795 B

123456789101112131415161718192021
  1. use std::time::Duration;
  2. use btlib::{
  3. crypto::{CredStoreMut, Creds},
  4. Epoch, Principaled, Result,
  5. };
  6. pub trait CredStoreTestingExt: CredStoreMut {
  7. /// Generates new root credentials and issues the node credentials a writecap using them. The
  8. /// given password is used to secure the root credentials.
  9. fn provision(&self, root_password: &str) -> Result<()> {
  10. let root_creds = self.gen_root_creds(root_password)?;
  11. let mut node_creds = self.node_creds()?;
  12. let expires = Epoch::now() + Duration::from_secs(3600);
  13. let writecap =
  14. root_creds.issue_writecap(node_creds.principal(), &mut std::iter::empty(), expires)?;
  15. self.assign_node_writecap(&mut node_creds, writecap)
  16. }
  17. }
  18. impl<T: CredStoreMut> CredStoreTestingExt for T {}