@@ -336,12 +336,11 @@ impl Account {
336336 ///
337337 /// This is useful if you want to change the ACME account key of an existing account, e.g.
338338 /// to mitigate the risk of a key compromise. This method creates a new client key and changes
339- /// the key associated with the existing account. In case the key rollover succeeds the new
340- /// account credentials are returned for further usage. After that a new Account object with
341- /// the updated client key needs to be crated for further interaction with the ACME account.
339+ /// the key associated with the existing account. `self` will be updated with the new key,
340+ /// and a fresh set of [`AccountCredentials`] will be returned to update stored credentials.
342341 ///
343342 /// See <https://datatracker.ietf.org/doc/html/rfc8555#section-7.3.5> for more information.
344- pub async fn change_key ( & self , server_url : & str ) -> Result < AccountCredentials , Error > {
343+ pub async fn change_key ( & mut self ) -> Result < AccountCredentials , Error > {
345344 let new_key_url = match self . inner . client . directory . key_change . as_deref ( ) {
346345 Some ( url) => url,
347346 None => return Err ( "Account key rollover not supported by ACME CA" . into ( ) ) ,
@@ -366,11 +365,22 @@ impl Account {
366365 let rsp = self . inner . post ( Some ( & body) , None , new_key_url) . await ?;
367366 let _ = Problem :: from_response ( rsp) . await ?;
368367
368+ self . inner = Arc :: new ( AccountInner {
369+ client : self . inner . client . clone ( ) ,
370+ key : new_key,
371+ id : self . inner . id . clone ( ) ,
372+ } ) ;
373+
374+ let ( directory, urls) = match & self . inner . client . server_url {
375+ Some ( server_url) => ( Some ( server_url. clone ( ) ) , None ) ,
376+ None => ( None , Some ( self . inner . client . directory . clone ( ) ) ) ,
377+ } ;
378+
369379 Ok ( AccountCredentials {
370380 id : self . inner . id . clone ( ) ,
371381 key_pkcs8 : new_key_pkcs8. as_ref ( ) . to_vec ( ) ,
372- directory : Some ( server_url . to_owned ( ) ) ,
373- urls : None ,
382+ directory,
383+ urls,
374384 } )
375385 }
376386
0 commit comments