@@ -45,9 +45,10 @@ pub struct AppCredentialMapping {
4545 pub target : AppCredential ,
4646}
4747
48- /// Cleartext credential wrapper used only for deserialization.
48+ /// Cleartext credential received from the API, used for deserialization only .
4949///
50- /// This type is converted to `AppCredential` (with encrypted password) immediately after deserialization.
50+ /// Passwords are encrypted and stored as [`AppCredential`] inside the credential store.
51+ /// This type is never stored directly — hand it to [`CredentialStoreHandle::insert`].
5152#[ derive( Debug , Deserialize ) ]
5253#[ serde( tag = "kind" ) ]
5354pub enum CleartextAppCredential {
@@ -59,8 +60,7 @@ pub enum CleartextAppCredential {
5960}
6061
6162impl CleartextAppCredential {
62- /// Encrypt the password and convert to storage-ready `AppCredential`.
63- pub fn encrypt ( self ) -> anyhow:: Result < AppCredential > {
63+ fn encrypt ( self ) -> anyhow:: Result < AppCredential > {
6464 match self {
6565 CleartextAppCredential :: UsernamePassword { username, password } => {
6666 let encrypted = MASTER_KEY . lock ( ) . encrypt ( password. expose_secret ( ) ) ?;
@@ -73,9 +73,9 @@ impl CleartextAppCredential {
7373 }
7474}
7575
76- /// Cleartext credential mapping wrapper used only for deserialization.
76+ /// Cleartext credential mapping received from the API, used for deserialization only .
7777///
78- /// This type is converted to `AppCredentialMapping` (with encrypted passwords) immediately after deserialization .
78+ /// Passwords are encrypted on write. Hand this directly to [`CredentialStoreHandle::insert`] .
7979#[ derive( Debug , Deserialize ) ]
8080pub struct CleartextAppCredentialMapping {
8181 #[ serde( rename = "proxy_credential" ) ]
@@ -85,8 +85,7 @@ pub struct CleartextAppCredentialMapping {
8585}
8686
8787impl CleartextAppCredentialMapping {
88- /// Encrypt passwords and convert to storage-ready `AppCredentialMapping`.
89- pub fn encrypt ( self ) -> anyhow:: Result < AppCredentialMapping > {
88+ fn encrypt ( self ) -> anyhow:: Result < AppCredentialMapping > {
9089 Ok ( AppCredentialMapping {
9190 proxy : self . proxy . encrypt ( ) ?,
9291 target : self . target . encrypt ( ) ?,
@@ -111,9 +110,10 @@ impl CredentialStoreHandle {
111110 pub fn insert (
112111 & self ,
113112 token : String ,
114- mapping : Option < AppCredentialMapping > ,
113+ mapping : Option < CleartextAppCredentialMapping > ,
115114 time_to_live : time:: Duration ,
116115 ) -> anyhow:: Result < Option < ArcCredentialEntry > > {
116+ let mapping = mapping. map ( CleartextAppCredentialMapping :: encrypt) . transpose ( ) ?;
117117 self . 0 . lock ( ) . insert ( token, mapping, time_to_live)
118118 }
119119
0 commit comments