@@ -30,7 +30,7 @@ use crate::ops;
30
30
use crate :: ops:: Packages ;
31
31
use crate :: sources:: { RegistrySource , SourceConfigMap , CRATES_IO_DOMAIN , CRATES_IO_REGISTRY } ;
32
32
use crate :: util:: auth:: {
33
- paserk_public_from_paserk_secret, { self , AuthorizationError } ,
33
+ paserk_public_from_paserk_secret, Secret , { self , AuthorizationError } ,
34
34
} ;
35
35
use crate :: util:: config:: { Config , SslVersionConfig , SslVersionConfigRange } ;
36
36
use crate :: util:: errors:: CargoResult ;
@@ -45,11 +45,11 @@ use crate::{drop_print, drop_println, version};
45
45
pub enum RegistryCredentialConfig {
46
46
None ,
47
47
/// The authentication token.
48
- Token ( String ) ,
48
+ Token ( Secret < String > ) ,
49
49
/// Process used for fetching a token.
50
50
Process ( ( PathBuf , Vec < String > ) ) ,
51
51
/// Secret Key and subject for Asymmetric tokens.
52
- AsymmetricKey ( ( String , Option < String > ) ) ,
52
+ AsymmetricKey ( ( Secret < String > , Option < String > ) ) ,
53
53
}
54
54
55
55
impl RegistryCredentialConfig {
@@ -71,9 +71,9 @@ impl RegistryCredentialConfig {
71
71
pub fn is_asymmetric_key ( & self ) -> bool {
72
72
matches ! ( self , Self :: AsymmetricKey ( ..) )
73
73
}
74
- pub fn as_token ( & self ) -> Option < & str > {
74
+ pub fn as_token ( & self ) -> Option < Secret < & str > > {
75
75
if let Self :: Token ( v) = self {
76
- Some ( & * v )
76
+ Some ( v . as_deref ( ) )
77
77
} else {
78
78
None
79
79
}
@@ -85,7 +85,7 @@ impl RegistryCredentialConfig {
85
85
None
86
86
}
87
87
}
88
- pub fn as_asymmetric_key ( & self ) -> Option < & ( String , Option < String > ) > {
88
+ pub fn as_asymmetric_key ( & self ) -> Option < & ( Secret < String > , Option < String > ) > {
89
89
if let Self :: AsymmetricKey ( v) = self {
90
90
Some ( v)
91
91
} else {
@@ -830,13 +830,13 @@ pub fn registry_login(
830
830
}
831
831
_ => ( None , None ) ,
832
832
} ;
833
- let secret_key: String ;
833
+ let secret_key: Secret < String > ;
834
834
if generate_keypair {
835
835
assert ! ( !secret_key_required) ;
836
836
let kp = AsymmetricKeyPair :: < pasetors:: version3:: V3 > :: generate ( ) . unwrap ( ) ;
837
837
let mut key = String :: new ( ) ;
838
838
FormatAsPaserk :: fmt ( & kp. secret , & mut key) . unwrap ( ) ;
839
- secret_key = key;
839
+ secret_key = Secret :: from ( key) ;
840
840
} else if secret_key_required {
841
841
assert ! ( !generate_keypair) ;
842
842
drop_println ! ( config, "please paste the API secret key below" ) ;
@@ -846,13 +846,13 @@ pub fn registry_login(
846
846
. lock ( )
847
847
. read_line ( & mut line)
848
848
. with_context ( || "failed to read stdin" ) ?;
849
- secret_key = line. trim ( ) . to_string ( ) ;
849
+ secret_key = Secret :: from ( line. trim ( ) . to_string ( ) ) ;
850
850
} else {
851
851
secret_key = old_secret_key
852
852
. cloned ( )
853
853
. ok_or_else ( || anyhow ! ( "need a secret_key to set a key_subject" ) ) ?;
854
854
}
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 ( ) ) {
856
856
drop_println ! ( config, "{}" , & p) ;
857
857
} else {
858
858
bail ! ( "not a validly formated PASERK secret key" ) ;
@@ -866,7 +866,7 @@ pub fn registry_login(
866
866
) ) ;
867
867
} else {
868
868
new_token = RegistryCredentialConfig :: Token ( match token {
869
- Some ( token) => token. to_string ( ) ,
869
+ Some ( token) => Secret :: from ( token. to_string ( ) ) ,
870
870
None => {
871
871
if let Some ( login_url) = login_url {
872
872
drop_println ! (
@@ -890,7 +890,7 @@ pub fn registry_login(
890
890
. with_context ( || "failed to read stdin" ) ?;
891
891
// Automatically remove `cargo login` from an inputted token to
892
892
// 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 ( ) )
894
894
}
895
895
} ) ;
896
896
0 commit comments