summaryrefslogtreecommitdiff
path: root/src/mscorlib/src/System/Reflection/StrongNameKeyPair.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/mscorlib/src/System/Reflection/StrongNameKeyPair.cs')
-rw-r--r--src/mscorlib/src/System/Reflection/StrongNameKeyPair.cs115
1 files changed, 9 insertions, 106 deletions
diff --git a/src/mscorlib/src/System/Reflection/StrongNameKeyPair.cs b/src/mscorlib/src/System/Reflection/StrongNameKeyPair.cs
index e8a441ca8f..8107cf4159 100644
--- a/src/mscorlib/src/System/Reflection/StrongNameKeyPair.cs
+++ b/src/mscorlib/src/System/Reflection/StrongNameKeyPair.cs
@@ -26,20 +26,7 @@ namespace System.Reflection
using System.Runtime.Versioning;
using Microsoft.Win32;
using System.Diagnostics.Contracts;
-#if !FEATURE_CORECLR
- using Microsoft.Runtime.Hosting;
-#endif
-#if FEATURE_CORECLR
- // Dummy type to avoid ifdefs in signature definitions
- public class StrongNameKeyPair
- {
- private StrongNameKeyPair()
- {
- throw new NotSupportedException();
- }
- }
-#else
[Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class StrongNameKeyPair : IDeserializationCallback, ISerializable
@@ -50,14 +37,10 @@ namespace System.Reflection
private byte[] _publicKey;
// Build key pair from file.
- [System.Security.SecuritySafeCritical] // auto-generated
-#pragma warning disable 618
- [SecurityPermissionAttribute(SecurityAction.Demand, Flags=SecurityPermissionFlag.UnmanagedCode)]
-#pragma warning restore 618
public StrongNameKeyPair(FileStream keyPairFile)
{
if (keyPairFile == null)
- throw new ArgumentNullException("keyPairFile");
+ throw new ArgumentNullException(nameof(keyPairFile));
Contract.EndContractBlock();
int length = (int)keyPairFile.Length;
@@ -68,14 +51,10 @@ namespace System.Reflection
}
// Build key pair from byte array in memory.
- [System.Security.SecuritySafeCritical] // auto-generated
-#pragma warning disable 618
- [SecurityPermissionAttribute(SecurityAction.Demand, Flags=SecurityPermissionFlag.UnmanagedCode)]
-#pragma warning restore 618
public StrongNameKeyPair(byte[] keyPairArray)
{
if (keyPairArray == null)
- throw new ArgumentNullException("keyPairArray");
+ throw new ArgumentNullException(nameof(keyPairArray));
Contract.EndContractBlock();
_keyPairArray = new byte[keyPairArray.Length];
@@ -83,27 +62,7 @@ namespace System.Reflection
_keyPairExported = true;
}
-
- // Reference key pair in named key container.
- [System.Security.SecuritySafeCritical] // auto-generated
-#pragma warning disable 618
- [SecurityPermissionAttribute(SecurityAction.Demand, Flags=SecurityPermissionFlag.UnmanagedCode)]
-#pragma warning restore 618
- public StrongNameKeyPair(String keyPairContainer)
- {
- if (keyPairContainer == null)
- throw new ArgumentNullException("keyPairContainer");
- Contract.EndContractBlock();
-
- _keyPairContainer = keyPairContainer;
-
- _keyPairExported = false;
- }
-
- [System.Security.SecuritySafeCritical] // auto-generated
-#pragma warning disable 618
- [SecurityPermissionAttribute(SecurityAction.Demand, Flags=SecurityPermissionFlag.UnmanagedCode)]
-#pragma warning restore 618
+
protected StrongNameKeyPair (SerializationInfo info, StreamingContext context) {
_keyPairExported = (bool) info.GetValue("_keyPairExported", typeof(bool));
_keyPairArray = (byte[]) info.GetValue("_keyPairArray", typeof(byte[]));
@@ -111,68 +70,20 @@ namespace System.Reflection
_publicKey = (byte[]) info.GetValue("_publicKey", typeof(byte[]));
}
- // Get the public portion of the key pair.
- public byte[] PublicKey
+ public StrongNameKeyPair(String keyPairContainer)
{
- [System.Security.SecuritySafeCritical] // auto-generated
- get
- {
- if (_publicKey == null)
- {
- _publicKey = ComputePublicKey();
- }
-
- byte[] publicKey = new byte[_publicKey.Length];
- Array.Copy(_publicKey, publicKey, _publicKey.Length);
-
- return publicKey;
- }
+ throw new PlatformNotSupportedException();
}
-
- [System.Security.SecurityCritical] // auto-generated
- private unsafe byte[] ComputePublicKey()
+
+ public byte[] PublicKey
{
- byte[] publicKey = null;
-
- // Make sure pbPublicKey is not leaked with async exceptions
- RuntimeHelpers.PrepareConstrainedRegions();
- try {
- }
- finally
+ get
{
- IntPtr pbPublicKey = IntPtr.Zero;
- int cbPublicKey = 0;
-
- try
- {
- bool result;
- if (_keyPairExported)
- {
- result = StrongNameHelpers.StrongNameGetPublicKey(null, _keyPairArray, _keyPairArray.Length,
- out pbPublicKey, out cbPublicKey);
- }
- else
- {
- result = StrongNameHelpers.StrongNameGetPublicKey(_keyPairContainer, null, 0,
- out pbPublicKey, out cbPublicKey);
- }
- if (!result)
- throw new ArgumentException(Environment.GetResourceString("Argument_StrongNameGetPublicKey"));
-
- publicKey = new byte[cbPublicKey];
- Buffer.Memcpy(publicKey, 0, (byte*)(pbPublicKey.ToPointer()), 0, cbPublicKey);
- }
- finally
- {
- if (pbPublicKey != IntPtr.Zero)
- StrongNameHelpers.StrongNameFreeBuffer(pbPublicKey);
- }
+ throw new PlatformNotSupportedException();
}
- return publicKey;
}
/// <internalonly/>
- [System.Security.SecurityCritical]
void ISerializable.GetObjectData (SerializationInfo info, StreamingContext context) {
info.AddValue("_keyPairExported", _keyPairExported);
info.AddValue("_keyPairArray", _keyPairArray);
@@ -182,13 +93,5 @@ namespace System.Reflection
/// <internalonly/>
void IDeserializationCallback.OnDeserialization (Object sender) {}
-
- // Internal routine used to retrieve key pair info from unmanaged code.
- private bool GetKeyPair(out Object arrayOrContainer)
- {
- arrayOrContainer = _keyPairExported ? (Object)_keyPairArray : (Object)_keyPairContainer;
- return _keyPairExported;
- }
}
-#endif // FEATURE_CORECLR
}