Esempio n. 1
0
        // Note: Errors are reported by throwing an IOException
        internal static StrongNameKeys CreateHelper(ImmutableArray <byte> keyFileContent, string keyFilePath, bool hasCounterSignature)
        {
            ImmutableArray <byte> keyPair;
            ImmutableArray <byte> publicKey;
            RSAParameters?        privateKey = null;

            // Check the key pair cache
            var cachedKeyPair = s_lastSeenKeyPair;

            if (cachedKeyPair != null && keyFileContent == cachedKeyPair.Item1)
            {
                keyPair    = cachedKeyPair.Item1;
                publicKey  = cachedKeyPair.Item2;
                privateKey = cachedKeyPair.Item3;
            }
            else
            {
                if (MetadataHelpers.IsValidPublicKey(keyFileContent))
                {
                    publicKey = keyFileContent;
                    keyPair   = default(ImmutableArray <byte>);
                }
                else if (CryptoBlobParser.TryParseKey(keyFileContent, out publicKey, out privateKey))
                {
                    keyPair = keyFileContent;
                }
                else
                {
                    throw new IOException(CodeAnalysisResources.InvalidPublicKey);
                }

                // Cache the key pair
                cachedKeyPair = new Tuple <ImmutableArray <byte>, ImmutableArray <byte>, RSAParameters?>(keyPair, publicKey, privateKey);
                Interlocked.Exchange(ref s_lastSeenKeyPair, cachedKeyPair);
            }

            return(new StrongNameKeys(keyPair, publicKey, privateKey, null, keyFilePath, hasCounterSignature));
        }
Esempio n. 2
0
 internal static bool IsValidPublicKey(ImmutableArray <byte> bytes) => CryptoBlobParser.IsValidPublicKey(bytes);