@@ -33,6 +33,41 @@ impl Display for OverrideReason {
33
33
}
34
34
}
35
35
36
+ #[ derive( Debug ) ]
37
+ pub enum PgpPublicKey {
38
+ Builtin ( & ' static [ u8 ] ) ,
39
+ FromEnvironment ( PathBuf , Vec < u8 > ) ,
40
+ FromConfiguration ( PathBuf , Vec < u8 > ) ,
41
+ }
42
+
43
+ impl PgpPublicKey {
44
+ /// Retrieve the key data for this key
45
+ ///
46
+ /// This key might be ASCII Armored or may not, we make no
47
+ /// guarantees.
48
+ pub fn key_data ( & self ) -> & [ u8 ] {
49
+ match self {
50
+ Self :: Builtin ( k) => k,
51
+ Self :: FromEnvironment ( _, k) => & k,
52
+ Self :: FromConfiguration ( _, k) => & k,
53
+ }
54
+ }
55
+ }
56
+
57
+ impl Display for PgpPublicKey {
58
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
59
+ match self {
60
+ Self :: Builtin ( _) => write ! ( f, "builtin Rust release key" ) ,
61
+ Self :: FromEnvironment ( p, _) => {
62
+ write ! ( f, "key specified in RUST_PGP_KEY ({})" , p. display( ) )
63
+ }
64
+ Self :: FromConfiguration ( p, _) => {
65
+ write ! ( f, "key specified in configuration file ({})" , p. display( ) )
66
+ }
67
+ }
68
+ }
69
+ }
70
+
36
71
pub struct Cfg {
37
72
pub profile_override : Option < dist:: Profile > ,
38
73
pub rustup_dir : PathBuf ,
@@ -41,7 +76,7 @@ pub struct Cfg {
41
76
pub update_hash_dir : PathBuf ,
42
77
pub download_dir : PathBuf ,
43
78
pub temp_cfg : temp:: Cfg ,
44
- pub gpg_key : Cow < ' static , str > ,
79
+ pgp_keys : Vec < PgpPublicKey > ,
45
80
pub toolchain_override : Option < String > ,
46
81
pub env_override : Option < String > ,
47
82
pub dist_root_url : String ,
@@ -62,13 +97,22 @@ impl Cfg {
62
97
let update_hash_dir = rustup_dir. join ( "update-hashes" ) ;
63
98
let download_dir = rustup_dir. join ( "downloads" ) ;
64
99
65
- // GPG key
66
- let gpg_key =
67
- if let Some ( path) = env:: var_os ( "RUSTUP_GPG_KEY" ) . and_then ( utils:: if_not_empty) {
68
- Cow :: Owned ( utils:: read_file ( "public key" , Path :: new ( & path) ) ?)
69
- } else {
70
- Cow :: Borrowed ( include_str ! ( "rust-key.gpg.ascii" ) )
71
- } ;
100
+ // PGP keys
101
+ let mut pgp_keys: Vec < PgpPublicKey > =
102
+ vec ! [ PgpPublicKey :: Builtin ( include_bytes!( "rust-key.pgp.ascii" ) ) ] ;
103
+ if let Some ( s_path) = env:: var_os ( "RUSTUP_PGP_KEY" ) {
104
+ let path = PathBuf :: from ( s_path) ;
105
+ let content = utils:: read_file_bytes ( "RUSTUP_PGP_KEY" , & path) ?;
106
+ pgp_keys. push ( PgpPublicKey :: FromEnvironment ( path, content) ) ;
107
+ }
108
+ settings_file. with ( |s| {
109
+ if let Some ( s) = & s. pgp_keys {
110
+ let path = PathBuf :: from ( s) ;
111
+ let content = utils:: read_file_bytes ( "PGP Key from config" , & path) ?;
112
+ pgp_keys. push ( PgpPublicKey :: FromConfiguration ( path, content) ) ;
113
+ }
114
+ Ok ( ( ) )
115
+ } ) ?;
72
116
73
117
// Environment override
74
118
let env_override = env:: var ( "RUSTUP_TOOLCHAIN" )
@@ -105,7 +149,7 @@ impl Cfg {
105
149
update_hash_dir,
106
150
download_dir,
107
151
temp_cfg,
108
- gpg_key ,
152
+ pgp_keys ,
109
153
notify_handler,
110
154
toolchain_override : None ,
111
155
env_override,
@@ -122,6 +166,10 @@ impl Cfg {
122
166
Ok ( cfg)
123
167
}
124
168
169
+ pub fn get_pgp_keys ( & self ) -> & [ PgpPublicKey ] {
170
+ & self . pgp_keys
171
+ }
172
+
125
173
pub fn set_profile_override ( & mut self , profile : dist:: Profile ) {
126
174
self . profile_override = Some ( profile) ;
127
175
}
0 commit comments