@@ -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 :: Credential } ,
1717} ;
1818
1919/// Initialize a new repository.
@@ -39,10 +39,10 @@ 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 : & Credential ,
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 ( ) ?;
@@ -54,7 +54,7 @@ pub(crate) fn init<P, S>(
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 : & Credential ,
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+ Credential :: Password ( password) => {
89+ let ( key, id) = init_key ( repo, key_opts, password) ?;
90+ info ! ( "key {id} successfully added." ) ;
91+ ( key, Some ( id) )
92+ }
93+ Credential :: Masterkey ( key) => ( key. key ( ) , None ) ,
94+ } ;
8995 save_config ( repo, config. clone ( ) , key) ?;
9096
9197 Ok ( ( key, id) )
0 commit comments