1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
use ;
use decrypt_password_from_file;
use encrypt_password_to_file;
use *;
use *;
use Status;
/// Returns the status of the NFe service
///
/// # Arguments
/// `use` - Specifies how to use the service, either `Use::FileConfig` or `Use::ManualConfig`.
/// Where `Use::FileConfig` reads the configurations from a file at the root of the project named `nfe_config.json`
/// and `Use::ManualConfig`
/// receives the configurations as parameters:
///
/// Fields {
/// cert_path: String,
/// cert_pass: Password,
/// federative_unit: String,
/// environment: Environment,
/// svc: bool,
/// }
///
/// Where `Password` is an enum that can be:
///
/// `Password::File(PassFile)` or `Password::Phrase(String)`
///
/// And `PassFile` is a struct with the fields:
///
/// PassFile {
/// encrypted_password: String,
/// key: String,
/// iv: String,
/// }
/// To generate the encrypted password file use the dfe::nfe::crypt() function. (not secure enough)
///
/// # Example
///
/// ```rust
/// use dfe::nfe::service_status;
/// use dfe::nfe::types::service_status::Use;
/// use dfe::nfe::types::service_status::Status;
///
/// let status = service_status(Use::FileConfig);
/// ```
///
/// # Returns
/// The status of the NFe service.
pub async
/// Encrypt the password, key, and iv to a file using the certificate.pfx file and password
/// specified in the function.
/// The encrypted password, key, and iv are saved to a file named `cert_pass.txt` at the root of the project.
/// The password is encrypted using the `aes_256_cbc` cipher.
/// The key and iv are encoded using the `base64` encoding.
/// The encrypted password is encoded using the `base64` encoding.
/// The password, key, and iv are saved in the following format:
/// ```
/// encrypted_password
/// key
/// iv
/// ```
/// # Example
/// ```rust
/// use dfe::nfe::crypt;
/// crypt("password");
/// ```
/// # Returns
///
/// The encrypted password, key, and iv are saved to a file named `cert_pass.txt` at the root of the project.
/// Decrypt the password from the file `cert_pass.txt` at the
/// root of the project.
/// The password is decrypted using the `aes_256_cbc` cipher.
/// The key and iv are decoded using the `base64` encoding.
/// The encrypted password is decoded using the `base64` encoding.
/// The password, key, and iv are read from the file in the following format:
/// ```
/// encrypted_password
/// key
/// iv
/// ```
/// # Example
/// ```rust
/// use dfe::nfe::decrypt;
/// let password = decrypt()?;
/// ```
/// # Returns
/// The decrypted password as a `String`.
/// # Errors
/// Returns an error if the file `cert_pass.txt` does not exist or if there is an error reading the file.