@@ -30,7 +30,7 @@ use crate::ops;
3030use crate :: ops:: Packages ;
3131use crate :: sources:: { RegistrySource , SourceConfigMap , CRATES_IO_DOMAIN , CRATES_IO_REGISTRY } ;
3232use crate :: util:: auth:: {
33- paserk_public_from_paserk_secret, { self , AuthorizationError } ,
33+ paserk_public_from_paserk_secret, Secret , { self , AuthorizationError } ,
3434} ;
3535use crate :: util:: config:: { Config , SslVersionConfig , SslVersionConfigRange } ;
3636use crate :: util:: errors:: CargoResult ;
@@ -45,11 +45,11 @@ use crate::{drop_print, drop_println, version};
4545pub enum RegistryCredentialConfig {
4646 None ,
4747 /// The authentication token.
48- Token ( String ) ,
48+ Token ( Secret < String > ) ,
4949 /// Process used for fetching a token.
5050 Process ( ( PathBuf , Vec < String > ) ) ,
5151 /// Secret Key and subject for Asymmetric tokens.
52- AsymmetricKey ( ( String , Option < String > ) ) ,
52+ AsymmetricKey ( ( Secret < String > , Option < String > ) ) ,
5353}
5454
5555impl RegistryCredentialConfig {
@@ -71,9 +71,9 @@ impl RegistryCredentialConfig {
7171 pub fn is_asymmetric_key ( & self ) -> bool {
7272 matches ! ( self , Self :: AsymmetricKey ( ..) )
7373 }
74- pub fn as_token ( & self ) -> Option < & str > {
74+ pub fn as_token ( & self ) -> Option < Secret < & str > > {
7575 if let Self :: Token ( v) = self {
76- Some ( & * v )
76+ Some ( v . as_deref ( ) )
7777 } else {
7878 None
7979 }
@@ -85,7 +85,7 @@ impl RegistryCredentialConfig {
8585 None
8686 }
8787 }
88- pub fn as_asymmetric_key ( & self ) -> Option < & ( String , Option < String > ) > {
88+ pub fn as_asymmetric_key ( & self ) -> Option < & ( Secret < String > , Option < String > ) > {
8989 if let Self :: AsymmetricKey ( v) = self {
9090 Some ( v)
9191 } else {
@@ -830,13 +830,13 @@ pub fn registry_login(
830830 }
831831 _ => ( None , None ) ,
832832 } ;
833- let secret_key: String ;
833+ let secret_key: Secret < String > ;
834834 if generate_keypair {
835835 assert ! ( !secret_key_required) ;
836836 let kp = AsymmetricKeyPair :: < pasetors:: version3:: V3 > :: generate ( ) . unwrap ( ) ;
837837 let mut key = String :: new ( ) ;
838838 FormatAsPaserk :: fmt ( & kp. secret , & mut key) . unwrap ( ) ;
839- secret_key = key;
839+ secret_key = Secret :: from ( key) ;
840840 } else if secret_key_required {
841841 assert ! ( !generate_keypair) ;
842842 drop_println ! ( config, "please paste the API secret key below" ) ;
@@ -846,13 +846,13 @@ pub fn registry_login(
846846 . lock ( )
847847 . read_line ( & mut line)
848848 . with_context ( || "failed to read stdin" ) ?;
849- secret_key = line. trim ( ) . to_string ( ) ;
849+ secret_key = Secret :: from ( line. trim ( ) . to_string ( ) ) ;
850850 } else {
851851 secret_key = old_secret_key
852852 . cloned ( )
853853 . ok_or_else ( || anyhow ! ( "need a secret_key to set a key_subject" ) ) ?;
854854 }
855- if let Some ( p) = paserk_public_from_paserk_secret ( & secret_key) {
855+ if let Some ( p) = paserk_public_from_paserk_secret ( secret_key. as_deref ( ) ) {
856856 drop_println ! ( config, "{}" , & p) ;
857857 } else {
858858 bail ! ( "not a validly formated PASERK secret key" ) ;
@@ -866,7 +866,7 @@ pub fn registry_login(
866866 ) ) ;
867867 } else {
868868 new_token = RegistryCredentialConfig :: Token ( match token {
869- Some ( token) => token. to_string ( ) ,
869+ Some ( token) => Secret :: from ( token. to_string ( ) ) ,
870870 None => {
871871 if let Some ( login_url) = login_url {
872872 drop_println ! (
@@ -890,7 +890,7 @@ pub fn registry_login(
890890 . with_context ( || "failed to read stdin" ) ?;
891891 // Automatically remove `cargo login` from an inputted token to
892892 // allow direct pastes from `registry.host()`/me.
893- line. replace ( "cargo login" , "" ) . trim ( ) . to_string ( )
893+ Secret :: from ( line. replace ( "cargo login" , "" ) . trim ( ) . to_string ( ) )
894894 }
895895 } ) ;
896896
0 commit comments