@@ -17,25 +17,46 @@ mod write {
1717                out. write_all ( value) ?; 
1818                out. write_all ( b"\n " ) 
1919            } 
20-             for  ( key,  value)  in  [ ( "url" ,  & self . url ) ,  ( "path" ,  & self . path ) ]  { 
20+             let  Context  { 
21+                 protocol, 
22+                 host, 
23+                 path, 
24+                 username, 
25+                 password, 
26+                 oauth_refresh_token, 
27+                 password_expiry_utc, 
28+                 url, 
29+                 // We only decode quit and interpret it, but won't get to pass it on as it means to stop the 
30+                 // credential helper invocation chain. 
31+                 quit :  _, 
32+             }  = self ; 
33+             for  ( key,  value)  in  [ ( "url" ,  url) ,  ( "path" ,  path) ]  { 
2134                if  let  Some ( value)  = value { 
2235                    validate ( key,  value. as_slice ( ) . into ( ) ) 
2336                        . map_err ( |err| std:: io:: Error :: new ( std:: io:: ErrorKind :: Other ,  err) ) ?; 
2437                    write_key ( & mut  out,  key,  value. as_ref ( ) ) . ok ( ) ; 
2538                } 
2639            } 
2740            for  ( key,  value)  in  [ 
28-                 ( "protocol" ,  & self . protocol ) , 
29-                 ( "host" ,  & self . host ) , 
30-                 ( "username" ,  & self . username ) , 
31-                 ( "password" ,  & self . password ) , 
41+                 ( "protocol" ,  protocol) , 
42+                 ( "host" ,  host) , 
43+                 ( "username" ,  username) , 
44+                 ( "password" ,  password) , 
45+                 ( "oauth_refresh_token" ,  oauth_refresh_token) , 
3246            ]  { 
3347                if  let  Some ( value)  = value { 
3448                    validate ( key,  value. as_str ( ) . into ( ) ) 
3549                        . map_err ( |err| std:: io:: Error :: new ( std:: io:: ErrorKind :: Other ,  err) ) ?; 
3650                    write_key ( & mut  out,  key,  value. as_bytes ( ) . as_bstr ( ) ) . ok ( ) ; 
3751                } 
3852            } 
53+             if  let  Some ( value)  = password_expiry_utc { 
54+                 let  key = "password_expiry_utc" ; 
55+                 let  value = value. to_string ( ) ; 
56+                 validate ( key,  value. as_str ( ) . into ( ) ) 
57+                     . map_err ( |err| std:: io:: Error :: new ( std:: io:: ErrorKind :: Other ,  err) ) ?; 
58+                 write_key ( & mut  out,  key,  value. as_bytes ( ) . as_bstr ( ) ) . ok ( ) ; 
59+             } 
3960            Ok ( ( ) ) 
4061        } 
4162
@@ -70,6 +91,17 @@ pub mod decode {
7091        /// Decode ourselves from `input` which is the format written by [`write_to()`][Self::write_to()]. 
7192         pub  fn  from_bytes ( input :  & [ u8 ] )  -> Result < Self ,  Error >  { 
7293            let  mut  ctx = Context :: default ( ) ; 
94+             let  Context  { 
95+                 protocol, 
96+                 host, 
97+                 path, 
98+                 username, 
99+                 password, 
100+                 oauth_refresh_token, 
101+                 password_expiry_utc, 
102+                 url, 
103+                 quit, 
104+             }  = & mut  ctx; 
73105            for  res in  input. lines ( ) . take_while ( |line| !line. is_empty ( ) ) . map ( |line| { 
74106                let  mut  it = line. splitn ( 2 ,  |b| * b == b'=' ) ; 
75107                match  ( 
@@ -84,23 +116,27 @@ pub mod decode {
84116            } )  { 
85117                let  ( key,  value)  = res?; 
86118                match  key { 
87-                     "protocol"  | "host"  | "username"  | "password"  => { 
119+                     "protocol"  | "host"  | "username"  | "password"  |  "oauth_refresh_token"   => { 
88120                        if  !value. is_utf8 ( )  { 
89121                            return  Err ( Error :: IllformedUtf8InValue  {  key :  key. into ( ) ,  value } ) ; 
90122                        } 
91123                        let  value = value. to_string ( ) ; 
92124                        * match  key { 
93-                             "protocol"  => & mut  ctx. protocol , 
94-                             "host"  => & mut  ctx. host , 
95-                             "username"  => & mut  ctx. username , 
96-                             "password"  => & mut  ctx. password , 
125+                             "protocol"  => & mut  * protocol, 
126+                             "host"  => host, 
127+                             "username"  => username, 
128+                             "password"  => password, 
129+                             "oauth_refresh_token"  => oauth_refresh_token, 
97130                            _ => unreachable ! ( "checked field names in match above" ) , 
98131                        }  = Some ( value) ; 
99132                    } 
100-                     "url"  => ctx. url  = Some ( value) , 
101-                     "path"  => ctx. path  = Some ( value) , 
133+                     "password_expiry_utc"  => { 
134+                         * password_expiry_utc = value. to_str ( ) . ok ( ) . and_then ( |value| value. parse ( ) . ok ( ) ) ; 
135+                     } 
136+                     "url"  => * url = Some ( value) , 
137+                     "path"  => * path = Some ( value) , 
102138                    "quit"  => { 
103-                         ctx . quit  = gix_config_value:: Boolean :: try_from ( value. as_ref ( ) ) . ok ( ) . map ( Into :: into) ; 
139+                         * quit = gix_config_value:: Boolean :: try_from ( value. as_ref ( ) ) . ok ( ) . map ( Into :: into) ; 
104140                    } 
105141                    _ => { } 
106142                } 
0 commit comments