@@ -158,35 +158,39 @@ impl SignBuilder {
158
158
let program = config
159
159
. get_string ( "gpg.ssh.program" )
160
160
. unwrap_or_else ( |_| "ssh-keygen" . to_string ( ) ) ;
161
- let ssh_signer = config
161
+
162
+ let signing_key = config
162
163
. get_string ( "user.signingKey" )
163
- . ok ( )
164
- . and_then ( |key_path| {
165
- key_path. strip_prefix ( '~' ) . map_or_else (
166
- || Some ( PathBuf :: from ( & key_path) ) ,
167
- |ssh_key_path| {
168
- dirs:: home_dir ( ) . map ( |home| {
169
- home. join (
170
- ssh_key_path
171
- . strip_prefix ( '/' )
172
- . unwrap_or ( ssh_key_path) ,
173
- )
174
- } )
175
- } ,
164
+ . map_err ( |err| {
165
+ SignBuilderError :: SSHSigningKey (
166
+ err. to_string ( ) ,
176
167
)
177
168
} )
178
- . ok_or_else ( || {
179
- SignBuilderError :: SSHSigningKey ( String :: from (
180
- "ssh key setting absent" ,
181
- ) )
182
- } )
183
- . and_then ( |key_path| Ok ( SSHSign { program, signing_key : key_path} ) ) ?;
184
- let signer: Box < dyn Sign > = Box :: new ( ssh_signer) ;
185
- Ok ( signer)
169
+ . and_then ( |signing_key| { SignBuilder :: signing_key_into_path ( & signing_key) } ) ?;
170
+
171
+ Ok ( Box :: new ( SSHSign {
172
+ program,
173
+ signing_key,
174
+ } ) )
186
175
}
187
176
_ => Err ( SignBuilderError :: InvalidFormat ( format) ) ,
188
177
}
189
178
}
179
+
180
+ fn signing_key_into_path ( signing_key : & str ) -> Result < PathBuf , SignBuilderError > {
181
+ let key_path = PathBuf :: from ( signing_key) ;
182
+ if key_path. is_file ( ) {
183
+ Ok ( key_path)
184
+ } else {
185
+ if signing_key. starts_with ( "ssh-" ) {
186
+ Ok ( key_path) //TODO: write key to temp file
187
+ } else {
188
+ Err ( SignBuilderError :: SSHSigningKey ( String :: from (
189
+ "ssh key could not be resolve. Either the key is not a file or the key is not a valid public ssh key" ,
190
+ ) ) )
191
+ }
192
+ }
193
+ }
190
194
}
191
195
192
196
/// Sign commit data using `OpenPGP`
0 commit comments