@@ -37,17 +37,17 @@ fn main() -> Result<(), Error> {
3737 // Check for force flag
3838 let mut force = false ;
3939 let mut remaining_args = Vec :: new ( ) ;
40-
40+
4141 for arg in args {
4242 if arg == "-f" || arg == "--force" {
4343 force = true ;
4444 } else {
4545 remaining_args. push ( arg) ;
4646 }
4747 }
48-
48+
4949 let mut remaining_iter = remaining_args. into_iter ( ) ;
50-
50+
5151 if let Some ( private_key) = remaining_iter. next ( ) {
5252 if let Some ( user_id) = remaining_iter. next ( ) {
5353 let timestamp_str = remaining_iter. next ( ) ;
@@ -272,7 +272,7 @@ fn to_32_bytes(slice: &String) -> Result<[u8; 32], Error> {
272272fn restore_from_private_key ( private_key : String , user_id : String , timestamp_opt : Option < u64 > , force : bool ) -> Result < ( ) , Error > {
273273 // Check for existing configuration and handle force flag
274274 let existing_config = Config :: load ( ) . ok ( ) ;
275-
275+
276276 if let Some ( config) = & existing_config {
277277 if !force {
278278 let config_path = config:: keys_file ( ) ;
@@ -285,16 +285,16 @@ fn restore_from_private_key(private_key: String, user_id: String, timestamp_opt:
285285 } else {
286286 // Force flag is set, we'll remove existing config and keychain entry
287287 println ! ( "Force flag set: overriding existing key" ) ;
288-
288+
289289 // 1. Remove keychain entry
290290 let service = config. service ( ) ;
291291 let account = config. user_id ( ) ;
292292 println ! ( "Removing existing keychain entry for service: {}, account: {}" , service, account) ;
293-
293+
294294 let _ = std:: process:: Command :: new ( "security" )
295295 . args ( [ "delete-generic-password" , "-s" , service] )
296296 . output ( ) ;
297-
297+
298298 // 2. Delete config file
299299 let config_path = config:: keys_file ( ) ;
300300 if config_path. exists ( ) {
@@ -306,12 +306,12 @@ fn restore_from_private_key(private_key: String, user_id: String, timestamp_opt:
306306
307307 // Trim whitespace and newlines from the private key
308308 let private_key = private_key. trim ( ) ;
309-
309+
310310 // Validate the private key format
311311 if private_key. len ( ) != 64 {
312312 bail ! ( "Invalid private key length: expected 64 characters, got {}" , private_key. len( ) ) ;
313313 }
314-
314+
315315 // Try to decode the hex string to get the private key bytes
316316 let secret_bytes = match hex:: decode ( private_key) {
317317 Ok ( bytes) => {
@@ -322,14 +322,14 @@ fn restore_from_private_key(private_key: String, user_id: String, timestamp_opt:
322322 }
323323 Err ( _) => bail ! ( "Failed to decode private key. It should be a valid hex string." )
324324 } ;
325-
325+
326326 // Convert to 32-byte array
327327 let mut secret = [ 0u8 ; 32 ] ;
328328 secret. copy_from_slice ( & secret_bytes) ;
329-
329+
330330 // Create keypair from private key
331331 let keypair = ed25519:: SigningKey :: from_bytes ( & secret) ;
332-
332+
333333 // Get or use provided timestamp
334334 let timestamp = if let Some ( ts) = timestamp_opt {
335335 println ! ( "Using provided timestamp: {}" , ts) ;
@@ -341,42 +341,42 @@ fn restore_from_private_key(private_key: String, user_id: String, timestamp_opt:
341341 println ! ( "Using current timestamp: {}" , current_ts) ;
342342 current_ts
343343 } ;
344-
344+
345345 // Validate user ID
346346 if user_id. is_empty ( ) {
347347 bail ! ( "User ID cannot be empty" ) ;
348348 }
349-
349+
350350 // Get public key from keypair
351351 let public_key = hex:: encode ( keypair. verifying_key ( ) . as_bytes ( ) ) ;
352-
352+
353353 // Create and save config
354354 let config = Config :: create ( public_key, user_id, timestamp) ?;
355355 config. write ( ) ?;
356-
356+
357357 // Store private key in keychain
358358 let service = config. service ( ) ;
359359 let account = config. user_id ( ) ;
360360 let hex = hex:: encode ( keypair. to_bytes ( ) ) ;
361361 add_keychain_item ( service, account, & hex) ?;
362-
362+
363363 // Print the public key
364364 let keydata = KeyData :: load ( & config, keypair. to_bytes ( ) ) ?;
365365 println ! ( "Key has been successfully restored." ) ;
366366 println ! ( "{}" , keydata. public( ) ) ;
367-
367+
368368 Ok ( ( ) )
369369}
370370
371371fn print_timestamp ( ) -> Result < ( ) , Error > {
372372 // Load the configuration file
373373 let config = Config :: load ( ) ?;
374-
374+
375375 // Get the timestamp
376376 let timestamp = config. timestamp ( ) ;
377-
377+
378378 println ! ( "{}" , timestamp) ;
379-
379+
380380 Ok ( ( ) )
381381}
382382
0 commit comments