@@ -33,6 +33,41 @@ impl Display for OverrideReason {
3333 }
3434}
3535
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+
3671pub struct Cfg {
3772 pub profile_override : Option < dist:: Profile > ,
3873 pub rustup_dir : PathBuf ,
@@ -41,7 +76,7 @@ pub struct Cfg {
4176 pub update_hash_dir : PathBuf ,
4277 pub download_dir : PathBuf ,
4378 pub temp_cfg : temp:: Cfg ,
44- pub gpg_key : Cow < ' static , str > ,
79+ pgp_keys : Vec < PgpPublicKey > ,
4580 pub toolchain_override : Option < String > ,
4681 pub env_override : Option < String > ,
4782 pub dist_root_url : String ,
@@ -62,13 +97,22 @@ impl Cfg {
6297 let update_hash_dir = rustup_dir. join ( "update-hashes" ) ;
6398 let download_dir = rustup_dir. join ( "downloads" ) ;
6499
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+ } ) ?;
72116
73117 // Environment override
74118 let env_override = env:: var ( "RUSTUP_TOOLCHAIN" )
@@ -105,7 +149,7 @@ impl Cfg {
105149 update_hash_dir,
106150 download_dir,
107151 temp_cfg,
108- gpg_key ,
152+ pgp_keys ,
109153 notify_handler,
110154 toolchain_override : None ,
111155 env_override,
@@ -122,6 +166,10 @@ impl Cfg {
122166 Ok ( cfg)
123167 }
124168
169+ pub fn get_pgp_keys ( & self ) -> & [ PgpPublicKey ] {
170+ & self . pgp_keys
171+ }
172+
125173 pub fn set_profile_override ( & mut self , profile : dist:: Profile ) {
126174 self . profile_override = Some ( profile) ;
127175 }
0 commit comments