Skip to content

Commit 9abc8c0

Browse files
committed
(chocolateyGH-1949) Use only official/unofficial on resolve
Previously, there was an attempt to use an either or key check when attempting to find the right assemblies to resolve. Unfortunately that was a bit optimistic as there is a strong tie in for using one type of key all the way through to other assemblies. Only check against one type of key for resolution to allow things to resolve appropriately. This removes a mix and match thought process that was optimistic.
1 parent d5abb13 commit 9abc8c0

File tree

3 files changed

+20
-25
lines changed

3 files changed

+20
-25
lines changed

src/chocolatey.console/Program.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,15 @@ private static void add_assembly_resolver()
189189
{
190190
var requestedAssembly = new AssemblyName(args.Name);
191191

192+
#if FORCE_CHOCOLATEY_OFFICIAL_KEY
193+
var chocolateyPublicKey = ApplicationParameters.OfficialChocolateyPublicKey;
194+
#else
195+
var chocolateyPublicKey = ApplicationParameters.UnofficialChocolateyPublicKey;
196+
#endif
197+
192198
// There are things that are ILMerged into Chocolatey. Anything with
193199
// the right public key except licensed should use the choco/chocolatey assembly
194-
if ((requestedAssembly.get_public_key_token().is_equal_to(ApplicationParameters.OfficialChocolateyPublicKey)
195-
#if !FORCE_CHOCOLATEY_OFFICIAL_KEY
196-
|| requestedAssembly.get_public_key_token().is_equal_to(ApplicationParameters.UnofficialChocolateyPublicKey)
197-
#endif
198-
)
200+
if (requestedAssembly.get_public_key_token().is_equal_to(chocolateyPublicKey)
199201
&& !requestedAssembly.Name.is_equal_to(ApplicationParameters.LicensedChocolateyAssemblySimpleName)
200202
&& !requestedAssembly.Name.EndsWith(".resources", StringComparison.OrdinalIgnoreCase))
201203
{
@@ -204,11 +206,7 @@ private static void add_assembly_resolver()
204206

205207
try
206208
{
207-
if ((requestedAssembly.get_public_key_token().is_equal_to(ApplicationParameters.OfficialChocolateyPublicKey)
208-
#if !FORCE_CHOCOLATEY_OFFICIAL_KEY
209-
|| requestedAssembly.get_public_key_token().is_equal_to(ApplicationParameters.UnofficialChocolateyPublicKey)
210-
#endif
211-
)
209+
if (requestedAssembly.get_public_key_token().is_equal_to(chocolateyPublicKey)
212210
&& requestedAssembly.Name.is_equal_to(ApplicationParameters.LicensedChocolateyAssemblySimpleName))
213211
{
214212
"chocolatey".Log().Debug(() => "Resolving reference to chocolatey.licensed...");

src/chocolatey/GetChocolatey.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,12 @@ private static void add_assembly_resolver()
6868

6969
// There are things that are ILMerged into Chocolatey. Anything with
7070
// the right public key except licensed should use the choco/chocolatey assembly
71-
if ((requestedAssembly.get_public_key_token().is_equal_to(ApplicationParameters.OfficialChocolateyPublicKey)
72-
#if !FORCE_CHOCOLATEY_OFFICIAL_KEY
73-
|| requestedAssembly.get_public_key_token().is_equal_to(ApplicationParameters.UnofficialChocolateyPublicKey)
71+
#if FORCE_CHOCOLATEY_OFFICIAL_KEY
72+
var chocolateyPublicKey = ApplicationParameters.OfficialChocolateyPublicKey;
73+
#else
74+
var chocolateyPublicKey = ApplicationParameters.UnofficialChocolateyPublicKey;
7475
#endif
75-
)
76+
if (requestedAssembly.get_public_key_token().is_equal_to(chocolateyPublicKey)
7677
&& !requestedAssembly.Name.is_equal_to(ApplicationParameters.LicensedChocolateyAssemblySimpleName)
7778
&& !requestedAssembly.Name.EndsWith(".resources", StringComparison.OrdinalIgnoreCase))
7879
{
@@ -81,11 +82,7 @@ private static void add_assembly_resolver()
8182

8283
try
8384
{
84-
if ((requestedAssembly.get_public_key_token().is_equal_to(ApplicationParameters.OfficialChocolateyPublicKey)
85-
#if !FORCE_CHOCOLATEY_OFFICIAL_KEY
86-
|| requestedAssembly.get_public_key_token().is_equal_to(ApplicationParameters.UnofficialChocolateyPublicKey)
87-
#endif
88-
)
85+
if (requestedAssembly.get_public_key_token().is_equal_to(chocolateyPublicKey)
8986
&& requestedAssembly.Name.is_equal_to(ApplicationParameters.LicensedChocolateyAssemblySimpleName))
9087
{
9188
_logger.Debug("Resolving reference to chocolatey.licensed...");

src/chocolatey/infrastructure/licensing/License.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ public static ChocolateyLicense validate_license()
3232
{
3333
try
3434
{
35-
var licensedAssembly = AssemblyResolution.resolve_or_load_assembly(ApplicationParameters.LicensedChocolateyAssemblySimpleName, ApplicationParameters.OfficialChocolateyPublicKey, ApplicationParameters.LicensedAssemblyLocation);
3635

37-
#if !FORCE_CHOCOLATEY_OFFICIAL_KEY
38-
if (licensedAssembly == null)
39-
{
40-
licensedAssembly = AssemblyResolution.resolve_or_load_assembly(ApplicationParameters.LicensedChocolateyAssemblySimpleName, ApplicationParameters.UnofficialChocolateyPublicKey, ApplicationParameters.LicensedAssemblyLocation);
41-
}
36+
#if FORCE_CHOCOLATEY_OFFICIAL_KEY
37+
var chocolateyPublicKey = ApplicationParameters.OfficialChocolateyPublicKey;
38+
#else
39+
var chocolateyPublicKey = ApplicationParameters.UnofficialChocolateyPublicKey;
4240
#endif
41+
var licensedAssembly = AssemblyResolution.resolve_or_load_assembly(ApplicationParameters.LicensedChocolateyAssemblySimpleName, chocolateyPublicKey, ApplicationParameters.LicensedAssemblyLocation);
42+
4343
if (licensedAssembly == null) throw new ApplicationException("Unable to load licensed assembly.");
4444
license.AssemblyLoaded = true;
4545
license.Assembly = licensedAssembly;

0 commit comments

Comments
 (0)