@@ -13,7 +13,7 @@ use crate::{
1313 error:: RusticResult ,
1414 id:: Id ,
1515 repofile:: { ConfigFile , KeyId , configfile:: RepositoryId } ,
16- repository:: Repository ,
16+ repository:: { Repository , credentials :: Credentials } ,
1717} ;
1818
1919/// Initialize a new repository.
@@ -26,7 +26,7 @@ use crate::{
2626/// # Arguments
2727///
2828/// * `repo` - The repository to initialize.
29- /// * `pass ` - The password to encrypt the key with .
29+ /// * `credentials ` - The credentials to use .
3030/// * `key_opts` - The options to create the key with.
3131/// * `config_opts` - The options to create the config with.
3232///
@@ -39,22 +39,22 @@ use crate::{
3939/// A tuple of the key and the config file.
4040pub ( crate ) fn init < P , S > (
4141 repo : & Repository < P , S > ,
42- pass : & str ,
42+ credentials : & Credentials ,
4343 key_opts : & KeyOptions ,
4444 config_opts : & ConfigOptions ,
45- ) -> RusticResult < ( Key , KeyId , ConfigFile ) > {
45+ ) -> RusticResult < ( Key , Option < KeyId > , ConfigFile ) > {
4646 // Create config first to allow catching errors from here without writing anything
4747 let repo_id = RepositoryId :: from ( Id :: random ( ) ) ;
4848 let chunker_poly = random_poly ( ) ?;
4949 let mut config = ConfigFile :: new ( 2 , repo_id, chunker_poly) ;
5050 if repo. be_hot . is_some ( ) {
51- // for hot/cold repository, `config` must be identical to thee config file which is read by the backend, i.e. the one saved in the hot repo.
51+ // for hot/cold repository, `config` must be identical to the config file which is read by the backend, i.e. the one saved in the hot repo.
5252 // Note: init_with_config does handle the is_hot config correctly for the hot and the cold repo.
5353 config. is_hot = Some ( true ) ;
5454 }
5555 config_opts. apply ( & mut config) ?;
5656
57- let ( key, key_id) = init_with_config ( repo, pass , key_opts, & config) ?;
57+ let ( key, key_id) = init_with_config ( repo, credentials , key_opts, & config) ?;
5858 info ! ( "repository {repo_id} successfully created." ) ;
5959
6060 Ok ( ( key, key_id, config) )
@@ -79,13 +79,19 @@ pub(crate) fn init<P, S>(
7979/// The key used to encrypt the config.
8080pub ( crate ) fn init_with_config < P , S > (
8181 repo : & Repository < P , S > ,
82- pass : & str ,
82+ credentials : & Credentials ,
8383 key_opts : & KeyOptions ,
8484 config : & ConfigFile ,
85- ) -> RusticResult < ( Key , KeyId ) > {
85+ ) -> RusticResult < ( Key , Option < KeyId > ) > {
8686 repo. be . create ( ) ?;
87- let ( key, id) = init_key ( repo, key_opts, pass) ?;
88- info ! ( "key {id} successfully added." ) ;
87+ let ( key, id) = match credentials {
88+ Credentials :: Password ( password) => {
89+ let ( key, id) = init_key ( repo, key_opts, password) ?;
90+ info ! ( "key {id} successfully added." ) ;
91+ ( key, Some ( id) )
92+ }
93+ Credentials :: Masterkey ( key) => ( key. key ( ) , None ) ,
94+ } ;
8995 save_config ( repo, config. clone ( ) , key) ?;
9096
9197 Ok ( ( key, id) )
0 commit comments