File tree Expand file tree Collapse file tree 4 files changed +38
-19
lines changed
Expand file tree Collapse file tree 4 files changed +38
-19
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,9 @@ use zeroize::Zeroize;
1010pub fn import ( matches : & ArgMatches , database : & mut OTPDatabase ) -> Result < String , String > {
1111 let path = matches. get_one :: < String > ( "path" ) . unwrap ( ) ;
1212
13- let result = if matches. get_flag ( "cotp" ) || matches. get_flag ( "andotp" ) {
13+ let result = if matches. get_flag ( "cotp" ) {
14+ importers:: cotp:: import ( path)
15+ } else if matches. get_flag ( "andotp" ) {
1416 importers:: and_otp:: import ( path)
1517 } else if matches. get_flag ( "aegis" ) {
1618 importers:: aegis:: import ( path)
Original file line number Diff line number Diff line change 1- use std:: fs:: read_to_string;
2-
3- use crate :: otp:: otp_element:: OTPElement ;
4-
5- //no need to declare andOTP json struct cause it's the same as OTP element
6-
7- pub fn import ( filepath : & str ) -> Result < Vec < OTPElement > , String > {
8- let file_to_import_contents = match read_to_string ( filepath) {
9- Ok ( result) => result,
10- Err ( e) => return Err ( format ! ( "Error during file reading: {:?}" , e) ) ,
11- } ;
12- let result: Result < Vec < OTPElement > , serde_json:: Error > =
13- serde_json:: from_str ( & file_to_import_contents) ;
14- match result {
15- Ok ( element) => Ok ( element) ,
16- Err ( e) => Err ( format ! ( "Failed to serialize file: {}" , e) ) ,
17- }
18- }
1+ use std:: fs:: read_to_string;
2+
3+ use crate :: otp:: otp_element:: OTPElement ;
4+
5+ //no need to declare andOTP json struct cause it's the same as OTP element
6+ pub fn import ( filepath : & str ) -> Result < Vec < OTPElement > , String > {
7+ let file_to_import_contents = match read_to_string ( filepath) {
8+ Ok ( result) => result,
9+ Err ( e) => return Err ( format ! ( "Error during file reading: {:?}" , e) ) ,
10+ } ;
11+
12+ match serde_json:: from_str :: < Vec < OTPElement > > ( & file_to_import_contents) {
13+ Ok ( elements) => Ok ( elements) ,
14+ Err ( e) => Err ( format ! ( "Failed to serialize file: {}" , e) ) ,
15+ }
16+ }
Original file line number Diff line number Diff line change 1+ use std:: fs:: read_to_string;
2+
3+ use crate :: otp:: otp_element:: { OTPDatabase , OTPElement } ;
4+
5+ pub fn import ( filepath : & str ) -> Result < Vec < OTPElement > , String > {
6+ let file_to_import_contents = match read_to_string ( filepath) {
7+ Ok ( result) => result,
8+ Err ( e) => return Err ( format ! ( "Error during file reading: {:?}" , e) ) ,
9+ } ;
10+
11+ match serde_json:: from_str :: < OTPDatabase > ( & file_to_import_contents) {
12+ Ok ( database) => Ok ( database. elements ) ,
13+ Err ( _e) => match serde_json:: from_str :: < Vec < OTPElement > > ( & file_to_import_contents) {
14+ Ok ( elements) => Ok ( elements) ,
15+ Err ( e) => Err ( format ! ( "Failed to serialize file: {}" , e) ) ,
16+ } ,
17+ }
18+ }
Original file line number Diff line number Diff line change @@ -3,4 +3,5 @@ pub mod aegis_encrypted;
33pub mod and_otp;
44pub mod authy_remote_debug;
55pub mod converted;
6+ pub mod cotp;
67pub mod freeotp_plus;
You can’t perform that action at this time.
0 commit comments