Imported Upstream version 5.10.0.47

Former-commit-id: d0813289fa2d35e1f8ed77530acb4fb1df441bc0
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-01-24 17:04:36 +00:00
parent 88ff76fe28
commit e46a49ecf1
5927 changed files with 226314 additions and 129848 deletions

View File

@@ -846,5 +846,16 @@ namespace System.Activities.Core.Presentation {
return ResourceManager.GetString("WrongNumberOfArgumentsForActivityDelegate", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string for the automation name of ParallelSeparator
/// </summary>
internal static string ParallelSeparatorAutomationName
{
get
{
return ResourceManager.GetString("ParallelSeparatorAutomationName", resourceCulture);
}
}
}
}

View File

@@ -7,6 +7,7 @@ namespace System.Activities.Core.Presentation
using System;
using System.Activities.Presentation;
using System.Windows;
using System.Windows.Automation;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
@@ -25,7 +26,13 @@ namespace System.Activities.Core.Presentation
public static readonly DependencyProperty ValueTypeProperty =
DependencyProperty.Register("ValueType", typeof(Type), typeof(CaseKeyBox), new PropertyMetadata(OnValueTypeChanged));
public static readonly DependencyProperty EditorAutomationNameProperty =
DependencyProperty.Register("EditorAutomationName", typeof(string), typeof(CaseKeyBox));
public static readonly DependencyProperty ComboBoxAutomationNameProperty =
DependencyProperty.Register("ComboBoxAutomationName", typeof(string), typeof(CaseKeyBox));
public static RoutedEvent ValueCommittedEvent =
EventManager.RegisterRoutedEvent("ValueCommitted", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(CaseKeyBox));
@@ -174,6 +181,18 @@ namespace System.Activities.Core.Presentation
set { SetValue(ValueTypeProperty, value); }
}
public string ComboBoxAutomationName
{
get { return (string)GetValue(ComboBoxAutomationNameProperty); }
set { SetValue(ComboBoxAutomationNameProperty, value); }
}
public string EditorAutomationName
{
get { return (string)GetValue(EditorAutomationNameProperty); }
set { SetValue(EditorAutomationNameProperty, value); }
}
public void RegainFocus()
{
if (this.visibleBox != null)
@@ -249,10 +268,39 @@ namespace System.Activities.Core.Presentation
{
UIElement box = (UIElement)sender;
ComboBox comboBox = box as ComboBox;
if (comboBox != null && comboBox.IsVisible)
if (comboBox != null)
{
ComboBoxHelper.SynchronizeComboBoxSelection(comboBox, this.ViewModel.Text);
if (!LocalAppContextSwitches.UseLegacyAccessibilityFeatures)
{
if (!string.IsNullOrEmpty(ComboBoxAutomationName))
{
comboBox.SetValue(AutomationProperties.NameProperty, ComboBoxAutomationName);
}
if (comboBox.IsEditable && comboBox.Template != null)
{
var comboBoxTextBox = comboBox.Template.FindName("PART_EditableTextBox", comboBox) as TextBox;
if (comboBoxTextBox != null && !string.IsNullOrEmpty(EditorAutomationName))
{
comboBoxTextBox.SetValue(AutomationProperties.NameProperty, EditorAutomationName);
}
}
}
if (comboBox.IsVisible)
{
ComboBoxHelper.SynchronizeComboBoxSelection(comboBox, this.ViewModel.Text);
}
}
if (!LocalAppContextSwitches.UseLegacyAccessibilityFeatures)
{
TextBox textBox = box as TextBox;
if (textBox != null && !string.IsNullOrEmpty(EditorAutomationName))
{
textBox.SetValue(AutomationProperties.NameProperty, EditorAutomationName);
}
}
if (box.IsVisible)
{
box.Focus();

View File

@@ -7,6 +7,7 @@ namespace System.Activities.Core.Presentation
using System.Activities.Presentation;
using System.Activities.Presentation.Hosting;
using System.Windows;
using System.Windows.Automation;
using System.Windows.Media.Animation;
partial class ParallelSeparator
@@ -22,6 +23,10 @@ namespace System.Activities.Core.Presentation
public ParallelSeparator()
{
this.InitializeComponent();
if (!LocalAppContextSwitches.UseLegacyAccessibilityFeatures)
{
SetValue(AutomationProperties.NameProperty, SR.ParallelSeparatorAutomationName);
}
}
public Type AllowedItemType

View File

@@ -17,6 +17,8 @@ namespace System.Activities.Core.Presentation
using System.IO;
using System.Runtime;
using System.Windows;
using System.Windows.Automation;
using System.Windows.Automation.Peers;
using System.Windows.Input;
using System.Windows.Threading;
using System.Windows.Controls;
@@ -454,6 +456,18 @@ namespace System.Activities.Core.Presentation
}
}
void OnTryAddActivityKeyDown(object sender, KeyEventArgs e)
{
if (!LocalAppContextSwitches.UseLegacyAccessibilityFeatures)
{
if (sender == e.OriginalSource && (e.Key == Key.Space || e.Key == Key.Enter))
{
ExpandTryView();
e.Handled = true;
}
}
}
void OnFinallyViewKeyDown(object sender, KeyEventArgs e)
{
if (sender == e.OriginalSource && (e.Key == Key.Space || e.Key == Key.Enter))
@@ -463,6 +477,18 @@ namespace System.Activities.Core.Presentation
}
}
void OnFinallyAddActivityKeyDown(object sender, KeyEventArgs e)
{
if (!LocalAppContextSwitches.UseLegacyAccessibilityFeatures)
{
if (sender == e.OriginalSource && (e.Key == Key.Space || e.Key == Key.Enter))
{
ExpandFinallyView();
e.Handled = true;
}
}
}
#region AddCatch Label & TypePresenter
void OnAddCatchMouseDown(object sender, MouseButtonEventArgs e)
@@ -602,4 +628,29 @@ namespace System.Activities.Core.Presentation
return true;
}
}
internal class TextBlockWrapper : TextBlock
{
protected override AutomationPeer OnCreateAutomationPeer()
{
if (!LocalAppContextSwitches.UseLegacyAccessibilityFeatures)
{
return new TextBlockWrapperAutomationPeer(this);
}
return base.OnCreateAutomationPeer();
}
}
internal class TextBlockWrapperAutomationPeer : TextBlockAutomationPeer
{
public TextBlockWrapperAutomationPeer(TextBlockWrapper owner)
: base(owner)
{
}
protected override AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.Button;
}
}
}

View File

@@ -14,6 +14,7 @@ namespace System.ServiceModel.Activities.Presentation
using System.ServiceModel.Dispatcher;
using System.Text;
using System.Windows;
using System.Windows.Automation;
using System.Windows.Controls;
using System.Windows.Input;
using System.Xml;
@@ -100,6 +101,22 @@ namespace System.ServiceModel.Activities.Presentation
base.OnKeyDown(e);
}
private void OnLoaded(object sender, RoutedEventArgs e)
{
if (!LocalAppContextSwitches.UseLegacyAccessibilityFeatures)
{
this.SetValue(AutomationProperties.NameProperty, this.Resources["MessageQueryEditorAutomationName"]);
if (this.IsEditable && this.Template != null)
{
var textBox = this.Template.FindName("PART_EditableTextBox", this) as TextBox;
if (textBox != null)
{
textBox.SetValue(AutomationProperties.NameProperty, this.GetValue(AutomationProperties.NameProperty));
}
}
}
}
//user double clicked on the expanded type, create a xpath
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes",
Justification = "Propagating exceptions might lead to VS crash.")]

View File

@@ -1 +1 @@
4b30c4caffe091787335adcea178360bfdd89f5a
831c5ba22827b30e58d524a8eeb0afbb55fdee3b

View File

@@ -12,6 +12,7 @@ namespace System.Configuration.Internal {
using System.Threading;
using System.Security;
using System.CodeDom.Compiler;
using System.Xml;
//
// A public implementation of IInternalConfigHost that simply
@@ -30,15 +31,23 @@ namespace System.Configuration.Internal {
// * It allows straightforward chaining of host functionality,
// see UpdateConfigHost as an example.
//
public class DelegatingConfigHost : IInternalConfigHost {
public class DelegatingConfigHost : IInternalConfigHost, IInternalConfigurationBuilderHost {
IInternalConfigHost _host;
IInternalConfigurationBuilderHost _configBuilderHost;
protected DelegatingConfigHost() {}
// The host that is delegated to.
protected IInternalConfigHost Host {
get {return _host;}
set {_host = value;}
set {
_host = value;
_configBuilderHost = _host as IInternalConfigurationBuilderHost;
}
}
protected IInternalConfigurationBuilderHost ConfigBuilderHost {
get { return _configBuilderHost; }
}
public virtual void Init(IInternalConfigRoot configRoot, params object[] hostInitParams) {
@@ -226,6 +235,22 @@ namespace System.Configuration.Internal {
}
}
public virtual XmlNode ProcessRawXml(XmlNode rawXml, ConfigurationBuilder builder) {
if (ConfigBuilderHost != null) {
return ConfigBuilderHost.ProcessRawXml(rawXml, builder);
}
return rawXml;
}
public virtual ConfigurationSection ProcessConfigurationSection(ConfigurationSection configSection, ConfigurationBuilder builder) {
if (ConfigBuilderHost != null) {
return ConfigBuilderHost.ProcessConfigurationSection(configSection, builder);
}
return configSection;
}
}
}

View File

@@ -18,11 +18,12 @@ namespace System.Configuration.Internal {
using System.Security.Permissions;
using System.Security.Policy;
using System.Threading;
using System.Xml;
//
// An IInternalConfigHost with common implementations of some file functions.
//
internal sealed class InternalConfigHost : IInternalConfigHost {
internal sealed class InternalConfigHost : IInternalConfigHost, IInternalConfigurationBuilderHost {
private IInternalConfigRoot _configRoot;
internal InternalConfigHost() {
@@ -446,6 +447,21 @@ namespace System.Configuration.Internal {
}
}
XmlNode IInternalConfigurationBuilderHost.ProcessRawXml(XmlNode rawXml, ConfigurationBuilder builder) {
if (builder != null) {
return builder.ProcessRawXml(rawXml);
}
return rawXml;
}
ConfigurationSection IInternalConfigurationBuilderHost.ProcessConfigurationSection(ConfigurationSection configSection, ConfigurationBuilder builder) {
if (builder != null) {
return builder.ProcessConfigurationSection(configSection);
}
return configSection;
}
}
}

View File

@@ -28,11 +28,12 @@ namespace System.Configuration.Internal {
// taken begin with the prefix "hl", for example, "hlFindConfigRecord".
//
internal sealed class InternalConfigRoot : IInternalConfigRoot {
IInternalConfigHost _host; // host, need to create records
ReaderWriterLock _hierarchyLock; // lock to protect hierarchy
IInternalConfigHost _host; // host, need to create records
IInternalConfigurationBuilderHost _configBuilderHost; // _configBuilderHost, need to create records
ReaderWriterLock _hierarchyLock; // lock to protect hierarchy
BaseConfigurationRecord _rootConfigRecord; // root config record, one level above machine.config.
bool _isDesignTime; // Is the hierarchy for runtime or designtime?
private Configuration _CurrentConfiguration = null;
private Configuration _CurrentConfiguration = null;
public event InternalConfigEventHandler ConfigChanged;
public event InternalConfigEventHandler ConfigRemoved;
@@ -45,6 +46,7 @@ namespace System.Configuration.Internal {
void IInternalConfigRoot.Init(IInternalConfigHost host, bool isDesignTime) {
_host = host;
_configBuilderHost = host as IInternalConfigurationBuilderHost;
_isDesignTime = isDesignTime;
_hierarchyLock = new ReaderWriterLock();
@@ -61,6 +63,10 @@ namespace System.Configuration.Internal {
get {return _host;}
}
internal IInternalConfigurationBuilderHost ConfigBuilderHost {
get { return _configBuilderHost; }
}
internal BaseConfigurationRecord RootConfigRecord {
get {return _rootConfigRecord;}
}

View File

@@ -1 +1 @@
f3ec52b9de8334b4d7e7adc40b9aaf60dc3d3b35
f694686b8988e10f7079f698a90c2e51a2f86158

View File

@@ -53,12 +53,12 @@ namespace System.Configuration {
}
// parentConfig contains the config that we'd merge with.
override protected object CreateSection(bool inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, object parentConfig, ConfigXmlReader reader) {
override protected object CreateSection(bool inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, SectionInput sectionInput, object parentConfig, ConfigXmlReader reader) {
// Get the factory used to create a section.
RuntimeConfigurationFactory factory = (RuntimeConfigurationFactory) factoryRecord.Factory;
// Use the factory to create a section.
object config = factory.CreateSection(inputIsTrusted, this, factoryRecord, sectionRecord, parentConfig, reader);
object config = factory.CreateSection(inputIsTrusted, this, factoryRecord, sectionRecord, sectionInput, parentConfig, reader);
return config;
}
@@ -215,7 +215,7 @@ namespace System.Configuration {
private object CreateSectionImpl(
RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord,
object parentConfig, ConfigXmlReader reader) {
SectionInput sectionInput, object parentConfig, ConfigXmlReader reader) {
object config;
@@ -233,6 +233,10 @@ namespace System.Configuration {
configSection.DeserializeSection(reader);
}
if (configRecord != null && sectionInput != null && sectionInput.ConfigBuilder != null) {
configSection = configRecord.CallHostProcessConfigurationSection(configSection, sectionInput.ConfigBuilder);
}
// throw if there are any cached errors
ConfigurationErrorsException errors = configSection.GetErrors();
if (errors != null) {
@@ -270,15 +274,15 @@ namespace System.Configuration {
[PermissionSet(SecurityAction.Assert, Unrestricted=true)]
private object CreateSectionWithFullTrust(
RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord,
object parentConfig, ConfigXmlReader reader) {
SectionInput sectionInput, object parentConfig, ConfigXmlReader reader) {
return CreateSectionImpl(configRecord, factoryRecord, sectionRecord, parentConfig, reader);
return CreateSectionImpl(configRecord, factoryRecord, sectionRecord, sectionInput, parentConfig, reader);
}
[SuppressMessage("Microsoft.Security", "CA2107:ReviewDenyAndPermitOnlyUsage", Justification = "This PermitOnly is meant to protect unassuming handlers from malicious callers by undoing any asserts we have put on the stack.")]
private object CreateSectionWithRestrictedPermissions(
RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord,
object parentConfig, ConfigXmlReader reader) {
RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord,
SectionInput sectionInput, object parentConfig, ConfigXmlReader reader) {
// run configuration section handlers as if user code was on the stack
bool revertPermitOnly = false;
@@ -289,7 +293,7 @@ namespace System.Configuration {
revertPermitOnly = true;
}
return CreateSectionImpl(configRecord, factoryRecord, sectionRecord, parentConfig, reader);
return CreateSectionImpl(configRecord, factoryRecord, sectionRecord, sectionInput, parentConfig, reader);
}
finally {
if (revertPermitOnly) {
@@ -299,13 +303,13 @@ namespace System.Configuration {
}
internal object CreateSection(bool inputIsTrusted, RuntimeConfigurationRecord configRecord,
FactoryRecord factoryRecord, SectionRecord sectionRecord, object parentConfig, ConfigXmlReader reader) {
FactoryRecord factoryRecord, SectionRecord sectionRecord, SectionInput sectionInput, object parentConfig, ConfigXmlReader reader) {
if (inputIsTrusted) {
return CreateSectionWithFullTrust(configRecord, factoryRecord, sectionRecord, parentConfig, reader);
return CreateSectionWithFullTrust(configRecord, factoryRecord, sectionRecord, sectionInput, parentConfig, reader);
}
else {
return CreateSectionWithRestrictedPermissions(configRecord, factoryRecord, sectionRecord, parentConfig, reader);
return CreateSectionWithRestrictedPermissions(configRecord, factoryRecord, sectionRecord, sectionInput, parentConfig, reader);
}
}
}

View File

@@ -39,6 +39,8 @@ namespace System.Configuration {
private const int Flag_ProtectionProviderModified = 0x00080000;
private const int Flag_OverrideModeDefaultModified = 0x00100000;
private const int Flag_OverrideModeModified = 0x00200000; // Used only for modified tracking
private const int Flag_ConfigBuilderDetermined = 0x00400000;
private const int Flag_ConfigBuilderModified = 0x00800000;
private ConfigurationSection _configurationSection;
private SafeBitVector32 _flags;
@@ -55,6 +57,8 @@ namespace System.Configuration {
private string _configSourceStreamName;
private ProtectedConfigurationProvider _protectionProvider;
private string _protectionProviderName;
private ConfigurationBuilder _configBuilder;
private string _configBuilderName;
private OverrideModeSetting _overrideModeDefault; // The default mode for the section in _configurationSection
private OverrideModeSetting _overrideMode; // The override mode at the current config path
@@ -128,8 +132,10 @@ namespace System.Configuration {
if (sectionRecord.HasFileInput) {
SectionInput fileInput = sectionRecord.FileInput;
_flags[ Flag_ProtectionProviderDetermined ] = fileInput.IsProtectionProviderDetermined;
_protectionProvider = fileInput.ProtectionProvider;
_flags[Flag_ConfigBuilderDetermined] = fileInput.IsConfigBuilderDetermined;
_configBuilder = fileInput.ConfigBuilder;
_flags[Flag_ProtectionProviderDetermined] = fileInput.IsProtectionProviderDetermined;
_protectionProvider = fileInput.ProtectionProvider;
SectionXmlInfo sectionXmlInfo = fileInput.SectionXmlInfo;
@@ -137,10 +143,13 @@ namespace System.Configuration {
_configSourceStreamName = sectionXmlInfo.ConfigSourceStreamName;
_overrideMode = sectionXmlInfo.OverrideModeSetting;
_flags[ Flag_InheritInChildApps ] = !sectionXmlInfo.SkipInChildApps;
_configBuilderName = sectionXmlInfo.ConfigBuilderName;
_protectionProviderName = sectionXmlInfo.ProtectionProviderName;
}
else {
_flags[ Flag_ProtectionProviderDetermined ] = false;
_flags[Flag_ConfigBuilderDetermined] = false;
_configBuilder = null;
_flags[Flag_ProtectionProviderDetermined] = false;
_protectionProvider = null;
}
@@ -599,6 +608,21 @@ namespace System.Configuration {
get {return (ProtectionProvider != null);}
}
internal string ConfigBuilderName {
get { return _configBuilderName; }
}
public ConfigurationBuilder ConfigurationBuilder {
get {
if (!_flags[Flag_ConfigBuilderDetermined] && _configRecord != null) {
_configBuilder = _configRecord.GetConfigBuilderFromName(_configBuilderName);
_flags[Flag_ConfigBuilderDetermined] = true;
}
return _configBuilder;
}
}
public ProtectedConfigurationProvider ProtectionProvider {
get {
if (!_flags[ Flag_ProtectionProviderDetermined] && _configRecord != null) {

View File

@@ -15,8 +15,14 @@ namespace System.Configuration {
private static object s_unevaluated = new object();
// input from the XML file
private SectionXmlInfo _sectionXmlInfo;
private SectionXmlInfo _sectionXmlInfo;
// Provider to enhance config sources
private ConfigurationBuilder _configBuilder;
// Has the config provider been determined for this input?
private bool _isConfigBuilderDetermined;
// Provider to use for encryption
private ProtectedConfigurationProvider _protectionProvider;
@@ -79,6 +85,18 @@ namespace System.Configuration {
_resultRuntimeObject = s_unevaluated;
}
internal bool IsConfigBuilderDetermined {
get { return _isConfigBuilderDetermined; }
}
internal ConfigurationBuilder ConfigBuilder {
get { return _configBuilder; }
set {
_configBuilder = value;
_isConfigBuilderDetermined = true;
}
}
internal bool IsProtectionProviderDetermined {
get {return _isProtectionProviderDetermined;}
}

View File

@@ -28,6 +28,7 @@ namespace System.Configuration {
private object _configSourceStreamVersion; // version of the configSource filestream
private bool _skipInChildApps; // skip inheritence by child apps?
private string _rawXml; // raw xml input of the section
private string _configBuilderName; // name of the configuration provider
private string _protectionProviderName; // name of the protection provider
private OverrideModeSetting _overrideMode; // override mode for child config paths
@@ -36,7 +37,7 @@ namespace System.Configuration {
string configKey, string definitionConfigPath, string targetConfigPath, string subPath,
string filename, int lineNumber, object streamVersion,
string rawXml, string configSource, string configSourceStreamName, object configSourceStreamVersion,
string protectionProviderName, OverrideModeSetting overrideMode, bool skipInChildApps) {
string configBuilderName, string protectionProviderName, OverrideModeSetting overrideMode, bool skipInChildApps) {
_configKey = configKey;
_definitionConfigPath = definitionConfigPath;
@@ -49,6 +50,7 @@ namespace System.Configuration {
_configSource = configSource;
_configSourceStreamName = configSourceStreamName;
_configSourceStreamVersion = configSourceStreamVersion;
_configBuilderName = configBuilderName;
_protectionProviderName = protectionProviderName;
_overrideMode = overrideMode;
_skipInChildApps = skipInChildApps;
@@ -111,6 +113,11 @@ namespace System.Configuration {
set {_rawXml = value;}
}
internal string ConfigBuilderName {
get { return _configBuilderName; }
set { _configBuilderName = value; }
}
internal string ProtectionProviderName {
get {return _protectionProviderName;}
set {_protectionProviderName = value;}

View File

@@ -144,6 +144,16 @@ namespace System.Linq.Expressions {
return Compile();
}
/// <summary>
/// Produces a delegate that represents the lambda expression.
/// </summary>
/// <param name="preferInterpretation">A <see cref="bool"/> that indicates if the expression should be compiled to an interpreted form, if available.</param>
/// <returns>A delegate containing the compiled version of the lambda.</returns>
public Delegate Compile(bool preferInterpretation)
{
return Compile();
}
/// <summary>
/// Compiles the lambda into a method definition.
/// </summary>
@@ -210,6 +220,11 @@ namespace System.Linq.Expressions {
return Compile();
}
public new TDelegate Compile(bool preferInterpretation)
{
return Compile();
}
/// <summary>
/// Creates a new expression that is like this one, but using the
/// supplied children. If all of the children are the same, it will

View File

@@ -1182,6 +1182,7 @@ namespace System.IO.Pipes {
// our WaitNamedPipe and CreateFile calls.
int startTime = Environment.TickCount;
int elapsed = 0;
var sw = new SpinWait();
do {
// Wait for pipe to become free (this will block unless the pipe does not exist).
if (!UnsafeNativeMethods.WaitNamedPipe(m_normalizedPipePath, timeout - elapsed)) {
@@ -1189,6 +1190,7 @@ namespace System.IO.Pipes {
// Server is not yet created so let's keep looping.
if (errorCode == UnsafeNativeMethods.ERROR_FILE_NOT_FOUND) {
sw.SpinOnce();
continue;
}
@@ -1215,6 +1217,7 @@ namespace System.IO.Pipes {
// Handle the possible race condition of someone else connecting to the server
// between our calls to WaitNamedPipe & CreateFile.
if (errorCode == UnsafeNativeMethods.ERROR_PIPE_BUSY) {
sw.SpinOnce();
continue;
}
@@ -1284,6 +1287,7 @@ namespace System.IO.Pipes {
// straight away in such cases), and 2) when another client connects to our server in between
// our WaitNamedPipe and CreateFile calls.
int elapsed = 0;
var sw = new SpinWait();
do {
// We want any other exception and and success to have priority over cancellation.
cancellationToken.ThrowIfCancellationRequested();
@@ -1303,6 +1307,7 @@ namespace System.IO.Pipes {
// Server is not yet created so let's keep looping.
if (errorCode == UnsafeNativeMethods.ERROR_FILE_NOT_FOUND) {
sw.SpinOnce();
continue;
}
@@ -1311,6 +1316,7 @@ namespace System.IO.Pipes {
if (cancellationToken.CanBeCanceled) {
// It may not be real timeout and only checking for cancellation
// let the while condition check it and decide
sw.SpinOnce();
continue;
}
else {
@@ -1336,6 +1342,7 @@ namespace System.IO.Pipes {
// Handle the possible race condition of someone else connecting to the server
// between our calls to WaitNamedPipe & CreateFile.
if (errorCode == UnsafeNativeMethods.ERROR_PIPE_BUSY) {
sw.SpinOnce();
continue;
}

View File

@@ -1 +1 @@
aef6a32d8ec54693b7c067fa73fbe8a7bc2d7a63
84a0435571889ce58bd34856be36335002eb5e30

View File

@@ -173,6 +173,17 @@ namespace System.Security.Cryptography {
internal int cbSalt;
}
[StructLayout(LayoutKind.Sequential)]
private struct BCRYPT_KEY_DATA_BLOB_HEADER
{
public uint dwMagic;
public uint dwVersion;
public uint cbKeyData;
public const uint BCRYPT_KEY_DATA_BLOB_MAGIC = 0x4d42444b;
public const uint BCRYPT_KEY_DATA_BLOB_VERSION1 = 0x1;
}
/// <summary>
/// Well known KDF names
/// </summary>
@@ -295,6 +306,120 @@ namespace System.Security.Cryptography {
[In] int dwFlags,
[In] IntPtr pvAuxInfo,
[Out] out SafeBCryptKeyHandle phKey);
[DllImport("bcrypt.dll", SetLastError = true, CharSet = CharSet.Unicode)]
internal static extern ErrorCode BCryptImportKey(
SafeBCryptAlgorithmHandle hAlgorithm,
IntPtr hImportKey,
string pszBlobType,
out SafeBCryptKeyHandle hKey,
IntPtr pbKeyObject,
int cbKeyObject,
byte[] pbInput,
int cbInput,
int dwFlags);
[DllImport("bcrypt.dll", SetLastError = true)]
public static extern unsafe ErrorCode BCryptEncrypt(
SafeBCryptKeyHandle hKey,
byte* pbInput,
int cbInput,
IntPtr paddingInfo,
[In, Out] byte[] pbIV,
int cbIV,
byte* pbOutput,
int cbOutput,
out int cbResult,
int dwFlags);
[DllImport("bcrypt.dll", SetLastError = true)]
public static extern unsafe ErrorCode BCryptDecrypt(
SafeBCryptKeyHandle hKey,
byte* pbInput,
int cbInput,
IntPtr paddingInfo,
[In, Out] byte[] pbIV,
int cbIV,
byte* pbOutput,
int cbOutput,
out int cbResult,
int dwFlags);
[DllImport("bcrypt.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern ErrorCode BCryptSetProperty(
SafeBCryptAlgorithmHandle hObject,
string pszProperty,
string pbInput,
int cbInput,
int dwFlags);
}
[SecuritySafeCritical]
internal static class AesBCryptModes
{
[SecurityCritical]
private static readonly SafeBCryptAlgorithmHandle s_hAlgCbc = OpenAesAlgorithm(Interop.BCrypt.BCRYPT_CHAIN_MODE_CBC);
[SecurityCritical]
private static readonly SafeBCryptAlgorithmHandle s_hAlgEcb = OpenAesAlgorithm(Interop.BCrypt.BCRYPT_CHAIN_MODE_ECB);
internal static SafeBCryptAlgorithmHandle GetSharedHandle(CipherMode cipherMode)
{
// Windows 8 added support to set the CipherMode value on a key,
// but Windows 7 requires that it be set on the algorithm before key creation.
switch (cipherMode)
{
case CipherMode.CBC:
return s_hAlgCbc;
case CipherMode.ECB:
return s_hAlgEcb;
default:
throw new NotSupportedException();
}
}
private static SafeBCryptAlgorithmHandle OpenAesAlgorithm(string cipherMode)
{
const string BCRYPT_AES_ALGORITHM = "AES";
SafeBCryptAlgorithmHandle hAlg = OpenAlgorithm(BCRYPT_AES_ALGORITHM, null);
SetCipherMode(hAlg, cipherMode);
return hAlg;
}
}
[SecuritySafeCritical]
internal static class TripleDesBCryptModes
{
[SecurityCritical]
private static readonly SafeBCryptAlgorithmHandle s_hAlgCbc = OpenAesAlgorithm(Interop.BCrypt.BCRYPT_CHAIN_MODE_CBC);
[SecurityCritical]
private static readonly SafeBCryptAlgorithmHandle s_hAlgEcb = OpenAesAlgorithm(Interop.BCrypt.BCRYPT_CHAIN_MODE_ECB);
internal static SafeBCryptAlgorithmHandle GetSharedHandle(CipherMode cipherMode)
{
// Windows 8 added support to set the CipherMode value on a key,
// but Windows 7 requires that it be set on the algorithm before key creation.
switch (cipherMode)
{
case CipherMode.CBC:
return s_hAlgCbc;
case CipherMode.ECB:
return s_hAlgEcb;
default:
throw new NotSupportedException();
}
}
private static SafeBCryptAlgorithmHandle OpenAesAlgorithm(string cipherMode)
{
const string BCRYPT_3DES_ALGORITHM = "3DES";
SafeBCryptAlgorithmHandle hAlg = OpenAlgorithm(BCRYPT_3DES_ALGORITHM, null);
SetCipherMode(hAlg, cipherMode);
return hAlg;
}
}
//
@@ -493,6 +618,163 @@ namespace System.Security.Cryptography {
}
return keyBlob;
}
[SecuritySafeCritical]
internal static SafeBCryptKeyHandle BCryptImportKey(SafeBCryptAlgorithmHandle hAlg, byte[] key)
{
unsafe
{
const String BCRYPT_KEY_DATA_BLOB = "KeyDataBlob";
int keySize = key.Length;
int blobSize = sizeof(BCRYPT_KEY_DATA_BLOB_HEADER) keySize;
byte[] blob = new byte[blobSize];
fixed (byte* pbBlob = blob)
{
BCRYPT_KEY_DATA_BLOB_HEADER* pBlob = (BCRYPT_KEY_DATA_BLOB_HEADER*)pbBlob;
pBlob->dwMagic = BCRYPT_KEY_DATA_BLOB_HEADER.BCRYPT_KEY_DATA_BLOB_MAGIC;
pBlob->dwVersion = BCRYPT_KEY_DATA_BLOB_HEADER.BCRYPT_KEY_DATA_BLOB_VERSION1;
pBlob->cbKeyData = (uint)keySize;
}
Buffer.BlockCopy(key, 0, blob, sizeof(BCRYPT_KEY_DATA_BLOB_HEADER), keySize);
SafeBCryptKeyHandle hKey;
ErrorCode error = UnsafeNativeMethods.BCryptImportKey(
hAlg,
IntPtr.Zero,
BCRYPT_KEY_DATA_BLOB,
out hKey,
IntPtr.Zero,
0,
blob,
blobSize,
0);
if (error != ErrorCode.Success)
throw new CryptographicException((int)error);
return hKey;
}
}
// Note: input and output are allowed to be the same buffer.
// BCryptEncrypt will correctly do the encryption in place according to CNG documentation.
[SecuritySafeCritical]
public static int BCryptEncrypt(
SafeBCryptKeyHandle hKey,
byte[] input,
int inputOffset,
int inputCount,
byte[] iv,
byte[] output,
int outputOffset,
int outputCount)
{
Debug.Assert(input != null);
Debug.Assert(inputOffset >= 0);
Debug.Assert(inputCount >= 0);
Debug.Assert(inputCount <= input.Length - inputOffset);
Debug.Assert(output != null);
Debug.Assert(outputOffset >= 0);
Debug.Assert(outputCount >= 0);
Debug.Assert(outputCount <= output.Length - outputOffset);
unsafe
{
fixed (byte* pbInput = input)
{
fixed (byte* pbOutput = output)
{
int cbResult;
ErrorCode error = UnsafeNativeMethods.BCryptEncrypt(
hKey,
pbInput inputOffset,
inputCount,
IntPtr.Zero,
iv,
iv == null ? 0 : iv.Length,
pbOutput outputOffset,
outputCount,
out cbResult,
0);
if (error != ErrorCode.Success)
throw new CryptographicException((int)error);
return cbResult;
}
}
}
}
// Note: input and output are allowed to be the same buffer.
// BCryptDecrypt will correctly do the decryption in place according to CNG documentation.
[SecuritySafeCritical]
public static int BCryptDecrypt(
SafeBCryptKeyHandle hKey,
byte[] input,
int inputOffset,
int inputCount,
byte[] iv,
byte[] output,
int outputOffset,
int outputCount)
{
Debug.Assert(input != null);
Debug.Assert(inputOffset >= 0);
Debug.Assert(inputCount >= 0);
Debug.Assert(inputCount <= input.Length - inputOffset);
Debug.Assert(output != null);
Debug.Assert(outputOffset >= 0);
Debug.Assert(outputCount >= 0);
Debug.Assert(outputCount <= output.Length - outputOffset);
unsafe
{
fixed (byte* pbInput = input)
{
fixed (byte* pbOutput = output)
{
int cbResult;
ErrorCode error = UnsafeNativeMethods.BCryptDecrypt(
hKey,
pbInput inputOffset,
inputCount,
IntPtr.Zero,
iv,
iv == null ? 0 : iv.Length,
pbOutput outputOffset,
outputCount,
out cbResult,
0);
if (error != ErrorCode.Success)
throw new CryptographicException((int)error);
return cbResult;
}
}
}
}
[SecurityCritical]
public static void SetCipherMode(SafeBCryptAlgorithmHandle hAlg, string cipherMode)
{
const string BCRYPT_CHAINING_MODE = "ChainingMode";
ErrorCode error = UnsafeNativeMethods.BCryptSetProperty(
hAlg,
BCRYPT_CHAINING_MODE,
cipherMode,
// Explicit \0 terminator, UCS-2
(cipherMode.Length 1) * 2,
0);
if (error != ErrorCode.Success)
{
throw new CryptographicException((int)error);
}
}
#endif
}
}

View File

@@ -976,7 +976,8 @@ namespace System.Security.Cryptography {
: base(true) {
}
[DllImport("kernel32.dll")]
[DllImport("kernel32.dll"), SuppressUnmanagedCodeSecurity]
[SecurityCritical]
private static extern IntPtr LocalFree(IntPtr hMem);
[SecuritySafeCritical]

View File

@@ -87,6 +87,7 @@ namespace System.Security.Cryptography
/// <exception cref="ArgumentException">if <paramref name="key" /> is not an RSA key</exception>
/// <exception cref="ArgumentNullException">if <paramref name="key" /> is null.</exception>
[SecuritySafeCritical]
[SecurityPermission(SecurityAction.Assert, UnmanagedCode = true)]
public RSACng(CngKey key)
{
if (key == null)
@@ -115,6 +116,7 @@ namespace System.Security.Cryptography
public CngKey Key
{
[SecuritySafeCritical]
[SecurityPermission(SecurityAction.Assert, UnmanagedCode = true)]
get
{
// If our key size was changed from the key we're using, we need to generate a new key
@@ -133,15 +135,15 @@ namespace System.Security.Cryptography
};
CngProperty keySizeProperty = new CngProperty(NCryptNative.KeyPropertyName.Length,
BitConverter.GetBytes(KeySize),
CngPropertyOptions.None);
BitConverter.GetBytes(KeySize),
CngPropertyOptions.None);
creationParameters.Parameters.Add(keySizeProperty);
_key = CngKey.Create(CngAlgorithm.Rsa, null, creationParameters);
}
return _key;
}
private set
{
Debug.Assert(value != null, "value != null");
@@ -181,6 +183,7 @@ namespace System.Security.Cryptography
private SafeNCryptKeyHandle KeyHandle
{
[SecuritySafeCritical]
[SecurityPermission(SecurityAction.Assert, UnmanagedCode = true)]
get { return Key.Handle; }
}
@@ -442,7 +445,7 @@ namespace System.Security.Cryptography
throw new ArgumentNullException("padding");
}
SafeNCryptKeyHandle keyHandle = Key.Handle;
SafeNCryptKeyHandle keyHandle = KeyHandle;
if (padding == RSAEncryptionPadding.Pkcs1)
{
@@ -492,6 +495,7 @@ namespace System.Security.Cryptography
//
[SecuritySafeCritical]
[SecurityPermission(SecurityAction.Assert, UnmanagedCode = true)]
public override byte[] SignHash(byte[] hash, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
{
if (hash == null)

Some files were not shown because too many files have changed in this diff Show More