@@ -151,3 +151,88 @@ impl AsRef<str> for CredentialType {
151151 }
152152 }
153153}
154+
155+ impl CredentialType {
156+ pub fn hide_pass ( & mut self ) -> Self {
157+ match self {
158+ CredentialType :: UP {
159+ username,
160+ privilege,
161+ ..
162+ } => {
163+ let pr = match privilege {
164+ Some ( x) => Some ( PrivilegeInformation {
165+ username : x. username . clone ( ) ,
166+ password : "" . to_string ( ) ,
167+ } ) ,
168+ None => None ,
169+ } ;
170+
171+ Self :: UP {
172+ username : username. to_string ( ) ,
173+ password : "" . to_string ( ) ,
174+ privilege : pr,
175+ }
176+ }
177+ CredentialType :: USK {
178+ username,
179+ password,
180+ privilege,
181+ private_key,
182+ } => {
183+ let pr = match privilege {
184+ Some ( x) => Some ( PrivilegeInformation {
185+ username : x. username . clone ( ) ,
186+ password : "" . to_string ( ) ,
187+ } ) ,
188+ None => None ,
189+ } ;
190+ if let Some ( p) = password. as_mut ( ) {
191+ p. clear ( ) ;
192+ } ;
193+
194+ CredentialType :: USK {
195+ username : username. to_string ( ) ,
196+ password : password. clone ( ) ,
197+ privilege : pr,
198+ private_key : private_key. to_string ( ) ,
199+ }
200+ }
201+ CredentialType :: SNMP {
202+ username,
203+ auth_algorithm,
204+ privacy_algorithm,
205+ community,
206+ ..
207+ } => CredentialType :: SNMP {
208+ username : username. to_string ( ) ,
209+ password : "" . to_string ( ) ,
210+ privacy_password : "" . to_string ( ) ,
211+ privacy_algorithm : privacy_algorithm. to_string ( ) ,
212+ auth_algorithm : auth_algorithm. to_string ( ) ,
213+ community : community. to_string ( ) ,
214+ } ,
215+
216+ CredentialType :: KRB5 {
217+ username,
218+ realm,
219+ kdc,
220+ ..
221+ } => CredentialType :: KRB5 {
222+ username : username. to_string ( ) ,
223+ password : String :: new ( ) ,
224+ realm : realm. to_string ( ) ,
225+ kdc : kdc. to_string ( ) ,
226+ } ,
227+ }
228+ }
229+ }
230+
231+ impl Credential {
232+ pub fn hide_pass ( mut self ) -> Self {
233+ Self {
234+ credential_type : self . credential_type . hide_pass ( ) ,
235+ ..self
236+ }
237+ }
238+ }
0 commit comments