diff options
Diffstat (limited to 'src/DotNetOpenAuth.OpenId')
80 files changed, 92 insertions, 1568 deletions
diff --git a/src/DotNetOpenAuth.OpenId/Configuration/AssociationTypeCollection.cs b/src/DotNetOpenAuth.OpenId/Configuration/AssociationTypeCollection.cs index 419a76a..384497c 100644 --- a/src/DotNetOpenAuth.OpenId/Configuration/AssociationTypeCollection.cs +++ b/src/DotNetOpenAuth.OpenId/Configuration/AssociationTypeCollection.cs @@ -7,12 +7,10 @@ namespace DotNetOpenAuth.Configuration { using System.Collections.Generic; using System.Configuration; - using System.Diagnostics.Contracts; /// <summary> /// Describes a collection of association type sub-elements in a .config file. /// </summary> - [ContractVerification(true)] internal class AssociationTypeCollection : ConfigurationElementCollection, IEnumerable<AssociationTypeElement> { /// <summary> /// Initializes a new instance of the <see cref="AssociationTypeCollection"/> class. diff --git a/src/DotNetOpenAuth.OpenId/Configuration/AssociationTypeElement.cs b/src/DotNetOpenAuth.OpenId/Configuration/AssociationTypeElement.cs index 32c1cc9..c64913d 100644 --- a/src/DotNetOpenAuth.OpenId/Configuration/AssociationTypeElement.cs +++ b/src/DotNetOpenAuth.OpenId/Configuration/AssociationTypeElement.cs @@ -8,7 +8,6 @@ namespace DotNetOpenAuth.Configuration { using System; using System.Collections.Generic; using System.Configuration; - using System.Diagnostics.Contracts; using System.Linq; using System.Text; @@ -16,7 +15,6 @@ namespace DotNetOpenAuth.Configuration { /// Describes an association type and its maximum lifetime as an element /// in a .config file. /// </summary> - [ContractVerification(true)] internal class AssociationTypeElement : ConfigurationElement { /// <summary> /// The name of the attribute that stores the association type. diff --git a/src/DotNetOpenAuth.OpenId/Configuration/OpenIdElement.cs b/src/DotNetOpenAuth.OpenId/Configuration/OpenIdElement.cs index c43a3ad..6c6ad10 100644 --- a/src/DotNetOpenAuth.OpenId/Configuration/OpenIdElement.cs +++ b/src/DotNetOpenAuth.OpenId/Configuration/OpenIdElement.cs @@ -8,14 +8,13 @@ namespace DotNetOpenAuth.Configuration { using System; using System.Collections.Generic; using System.Configuration; - using System.Diagnostics.Contracts; using DotNetOpenAuth.OpenId.ChannelElements; using DotNetOpenAuth.OpenId.Messages; + using Validation; /// <summary> /// Represents the <openid> element in the host's .config file. /// </summary> - [ContractVerification(true)] internal class OpenIdElement : ConfigurationSection { /// <summary> /// The name of the section under which this library's settings must be found. @@ -63,7 +62,6 @@ namespace DotNetOpenAuth.Configuration { /// </summary> public static OpenIdElement Configuration { get { - Contract.Ensures(Contract.Result<OpenIdElement>() != null); return (OpenIdElement)ConfigurationManager.GetSection(SectionName) ?? new OpenIdElement(); } } @@ -80,14 +78,13 @@ namespace DotNetOpenAuth.Configuration { [PositiveTimeSpanValidator] internal TimeSpan MaxAuthenticationTime { get { - Contract.Ensures(Contract.Result<TimeSpan>() > TimeSpan.Zero); TimeSpan result = (TimeSpan)this[MaxAuthenticationTimePropertyName]; - Contract.Assume(result > TimeSpan.Zero); // our PositiveTimeSpanValidator should take care of this + Assumes.True(result > TimeSpan.Zero); // our PositiveTimeSpanValidator should take care of this return result; } set { - Requires.InRange(value > TimeSpan.Zero, "value"); + Requires.Range(value > TimeSpan.Zero, "value"); this[MaxAuthenticationTimePropertyName] = value; } } diff --git a/src/DotNetOpenAuth.OpenId/Configuration/OpenIdProviderElement.cs b/src/DotNetOpenAuth.OpenId/Configuration/OpenIdProviderElement.cs index df93d3b..dfa5a86 100644 --- a/src/DotNetOpenAuth.OpenId/Configuration/OpenIdProviderElement.cs +++ b/src/DotNetOpenAuth.OpenId/Configuration/OpenIdProviderElement.cs @@ -6,14 +6,12 @@ namespace DotNetOpenAuth.Configuration { using System.Configuration; - using System.Diagnostics.Contracts; using DotNetOpenAuth.OpenId; using DotNetOpenAuth.OpenId.Provider; /// <summary> /// The section in the .config file that allows customization of OpenID Provider behaviors. /// </summary> - [ContractVerification(true)] internal class OpenIdProviderElement : ConfigurationElement { /// <summary> /// The name of the <provider> sub-element. diff --git a/src/DotNetOpenAuth.OpenId/Configuration/OpenIdProviderSecuritySettingsElement.cs b/src/DotNetOpenAuth.OpenId/Configuration/OpenIdProviderSecuritySettingsElement.cs index f003900..3579faa 100644 --- a/src/DotNetOpenAuth.OpenId/Configuration/OpenIdProviderSecuritySettingsElement.cs +++ b/src/DotNetOpenAuth.OpenId/Configuration/OpenIdProviderSecuritySettingsElement.cs @@ -6,14 +6,12 @@ namespace DotNetOpenAuth.Configuration { using System.Configuration; - using System.Diagnostics.Contracts; using DotNetOpenAuth.OpenId; using DotNetOpenAuth.OpenId.Provider; /// <summary> /// Represents the .config file element that allows for setting the security policies of the Provider. /// </summary> - [ContractVerification(true)] internal class OpenIdProviderSecuritySettingsElement : ConfigurationElement { /// <summary> /// Gets the name of the @protectDownlevelReplayAttacks attribute. @@ -111,7 +109,6 @@ namespace DotNetOpenAuth.Configuration { [ConfigurationCollection(typeof(AssociationTypeCollection))] public AssociationTypeCollection AssociationLifetimes { get { - Contract.Ensures(Contract.Result<AssociationTypeCollection>() != null); return (AssociationTypeCollection)this[AssociationsConfigName] ?? new AssociationTypeCollection(); } @@ -144,7 +141,7 @@ namespace DotNetOpenAuth.Configuration { settings.UnsolicitedAssertionVerification = this.UnsolicitedAssertionVerification; settings.EncodeAssociationSecretsInHandles = this.EncodeAssociationSecretsInHandles; foreach (AssociationTypeElement element in this.AssociationLifetimes) { - Contract.Assume(element != null); + Assumes.True(element != null); settings.AssociationLifetimes.Add(element.AssociationType, element.MaximumLifetime); } diff --git a/src/DotNetOpenAuth.OpenId/Configuration/OpenIdRelyingPartyElement.cs b/src/DotNetOpenAuth.OpenId/Configuration/OpenIdRelyingPartyElement.cs index 8af1129..681ba38 100644 --- a/src/DotNetOpenAuth.OpenId/Configuration/OpenIdRelyingPartyElement.cs +++ b/src/DotNetOpenAuth.OpenId/Configuration/OpenIdRelyingPartyElement.cs @@ -7,14 +7,12 @@ namespace DotNetOpenAuth.Configuration { using System; using System.Configuration; - using System.Diagnostics.Contracts; using DotNetOpenAuth.OpenId; using DotNetOpenAuth.OpenId.RelyingParty; /// <summary> /// The section in the .config file that allows customization of OpenID Relying Party behaviors. /// </summary> - [ContractVerification(true)] internal class OpenIdRelyingPartyElement : ConfigurationElement { /// <summary> /// The name of the custom store sub-element. diff --git a/src/DotNetOpenAuth.OpenId/Configuration/OpenIdRelyingPartySecuritySettingsElement.cs b/src/DotNetOpenAuth.OpenId/Configuration/OpenIdRelyingPartySecuritySettingsElement.cs index f0d8942..a2e2c34 100644 --- a/src/DotNetOpenAuth.OpenId/Configuration/OpenIdRelyingPartySecuritySettingsElement.cs +++ b/src/DotNetOpenAuth.OpenId/Configuration/OpenIdRelyingPartySecuritySettingsElement.cs @@ -7,7 +7,6 @@ namespace DotNetOpenAuth.Configuration { using System; using System.Configuration; - using System.Diagnostics.Contracts; using DotNetOpenAuth.OpenId; using DotNetOpenAuth.OpenId.RelyingParty; @@ -238,8 +237,6 @@ namespace DotNetOpenAuth.Configuration { /// </summary> /// <returns>The newly created security settings object.</returns> public RelyingPartySecuritySettings CreateSecuritySettings() { - Contract.Ensures(Contract.Result<RelyingPartySecuritySettings>() != null); - RelyingPartySecuritySettings settings = new RelyingPartySecuritySettings(); settings.RequireSsl = this.RequireSsl; settings.RequireDirectedIdentity = this.RequireDirectedIdentity; diff --git a/src/DotNetOpenAuth.OpenId/DotNetOpenAuth.OpenId.csproj b/src/DotNetOpenAuth.OpenId/DotNetOpenAuth.OpenId.csproj index 75bd113..e238d58 100644 --- a/src/DotNetOpenAuth.OpenId/DotNetOpenAuth.OpenId.csproj +++ b/src/DotNetOpenAuth.OpenId/DotNetOpenAuth.OpenId.csproj @@ -4,6 +4,7 @@ <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir> </PropertyGroup> <Import Project="$(ProjectRoot)tools\DotNetOpenAuth.props" /> <PropertyGroup> @@ -40,7 +41,6 @@ </Compile> <Compile Include="OpenId\Behaviors\GsaIcamProfileBase.cs" /> <Compile Include="OpenId\ChannelElements\BackwardCompatibilityBindingElement.cs" /> - <Compile Include="OpenId\ChannelElements\SigningBindingElementContract.cs" /> <Compile Include="OpenId\ChannelElements\ExtensionsBindingElement.cs" /> <Compile Include="OpenId\ChannelElements\IOpenIdExtensionFactory.cs" /> <Compile Include="OpenId\ChannelElements\ITamperResistantOpenIdMessage.cs" /> @@ -50,7 +50,6 @@ <Compile Include="OpenId\ChannelElements\OpenIdChannel.cs" /> <Compile Include="OpenId\ChannelElements\ReturnToSignatureBindingElement.cs" /> <Compile Include="OpenId\ChannelElements\SkipSecurityBindingElement.cs" /> - <Compile Include="OpenId\AssociationContract.cs" /> <Compile Include="OpenId\Extensions\AliasManager.cs" /> <Compile Include="OpenId\Extensions\AttributeExchange\AttributeRequest.cs" /> <Compile Include="OpenId\Extensions\AttributeExchange\AttributeValues.cs" /> @@ -89,7 +88,6 @@ <Compile Include="OpenId\Extensions\UI\UIRequest.cs" /> <Compile Include="OpenId\Extensions\UI\UIUtilities.cs" /> <Compile Include="OpenId\Identifier.cs" /> - <Compile Include="OpenId\IdentifierContract.cs" /> <Compile Include="OpenId\Extensions\OpenIdExtensionsInteropHelper.cs" /> <Compile Include="OpenId\IdentifierDiscoveryResult.cs" /> <Compile Include="OpenId\IIdentifierDiscoveryService.cs" /> @@ -104,13 +102,11 @@ <Compile Include="OpenId\Provider\RelyingPartyDiscoveryResult.cs" /> <Compile Include="OpenId\RelyingParty\AuthenticationStatus.cs" /> <Compile Include="OpenId\RelyingParty\IAuthenticationRequest.cs" /> - <Compile Include="OpenId\RelyingParty\IAuthenticationRequestContract.cs" /> <Compile Include="OpenId\RelyingParty\IAuthenticationResponse.cs" /> <Compile Include="OpenId\RelyingParty\IRelyingPartyBehavior.cs" /> <Compile Include="OpenId\Messages\CheckAuthenticationRequest.cs" /> <Compile Include="OpenId\Messages\CheckAuthenticationResponse.cs" /> <Compile Include="OpenId\Messages\CheckIdRequest.cs" /> - <Compile Include="OpenId\Messages\AssociateSuccessfulResponseContract.cs" /> <Compile Include="OpenId\Messages\IErrorMessage.cs" /> <Compile Include="OpenId\Messages\IndirectResponseBase.cs" /> <Compile Include="OpenId\Messages\IndirectSignedResponse.cs" /> @@ -186,7 +182,17 @@ <Name>Org.Mentalis.Security.Cryptography</Name> </ProjectReference> </ItemGroup> + <ItemGroup> + <Reference Include="Validation"> + <HintPath>..\packages\Validation.2.0.1.12362\lib\portable-windows8+net40+sl5+windowsphone8\Validation.dll</HintPath> + <Private>True</Private> + </Reference> + </ItemGroup> + <ItemGroup> + <None Include="packages.config" /> + </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(ProjectRoot)tools\DotNetOpenAuth.targets" /> <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), EnlistmentInfo.targets))\EnlistmentInfo.targets" Condition=" '$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), EnlistmentInfo.targets))' != '' " /> + <Import Project="$(SolutionDir)\.nuget\nuget.targets" /> </Project>
\ No newline at end of file diff --git a/src/DotNetOpenAuth.OpenId/OpenId/Association.cs b/src/DotNetOpenAuth.OpenId/OpenId/Association.cs index a0f5bae..502afb3 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/Association.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/Association.cs @@ -8,12 +8,12 @@ namespace DotNetOpenAuth.OpenId { using System; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; - using System.Diagnostics.Contracts; using System.IO; using System.Security.Cryptography; using System.Text; using DotNetOpenAuth.Configuration; using DotNetOpenAuth.Messaging; + using Validation; /// <summary> /// Stores a secret used in signing and verifying messages. @@ -24,8 +24,6 @@ namespace DotNetOpenAuth.OpenId { /// (dumb associations). /// </remarks> [DebuggerDisplay("Handle = {Handle}, Expires = {Expires}")] - [ContractVerification(true)] - [ContractClass(typeof(AssociationContract))] public abstract class Association { /// <summary> /// Initializes a new instance of the <see cref="Association"/> class. @@ -37,10 +35,9 @@ namespace DotNetOpenAuth.OpenId { protected Association(string handle, byte[] secret, TimeSpan totalLifeLength, DateTime issued) { Requires.NotNullOrEmpty(handle, "handle"); Requires.NotNull(secret, "secret"); - Requires.InRange(totalLifeLength > TimeSpan.Zero, "totalLifeLength"); - Requires.True(issued.Kind == DateTimeKind.Utc, "issued"); - Requires.InRange(issued <= DateTime.UtcNow, "issued"); - Contract.Ensures(this.TotalLifeLength == totalLifeLength); + Requires.Range(totalLifeLength > TimeSpan.Zero, "totalLifeLength"); + Requires.That(issued.Kind == DateTimeKind.Utc, "issued", "UTC time required."); + Requires.Range(issued <= DateTime.UtcNow, "issued"); this.Handle = handle; this.SecretKey = secret; @@ -93,7 +90,6 @@ namespace DotNetOpenAuth.OpenId { /// </summary> protected internal static TimeSpan DumbSecretLifetime { get { - Contract.Ensures(Contract.Result<TimeSpan>() > TimeSpan.Zero); return OpenIdElement.Configuration.MaxAuthenticationTime; } } @@ -104,7 +100,6 @@ namespace DotNetOpenAuth.OpenId { /// </summary> protected internal long SecondsTillExpiration { get { - Contract.Ensures(Contract.Result<long>() >= 0); return Math.Max(0, (long)this.TimeTillExpiration.TotalSeconds); } } @@ -130,7 +125,6 @@ namespace DotNetOpenAuth.OpenId { /// </remarks> private static TimeSpan MinimumUsefulAssociationLifetime { get { - Contract.Ensures(Contract.Result<TimeSpan>() > TimeSpan.Zero); return OpenIdElement.Configuration.MaxAuthenticationTime; } } @@ -164,7 +158,6 @@ namespace DotNetOpenAuth.OpenId { public static Association Deserialize(string handle, DateTime expiresUtc, byte[] privateData) { Requires.NotNullOrEmpty(handle, "handle"); Requires.NotNull(privateData, "privateData"); - Contract.Ensures(Contract.Result<Association>() != null); expiresUtc = expiresUtc.ToUniversalTimeSafe(); TimeSpan remainingLifeLength = expiresUtc - DateTime.UtcNow; @@ -191,8 +184,6 @@ namespace DotNetOpenAuth.OpenId { /// in this byte array, as they are useful for fast database lookup and are persisted separately. /// </remarks> public byte[] SerializePrivateData() { - Contract.Ensures(Contract.Result<byte[]>() != null); - // We may want to encrypt this secret using the machine.config private key, // and add data regarding which Association derivative will need to be // re-instantiated on deserialization. diff --git a/src/DotNetOpenAuth.OpenId/OpenId/AssociationContract.cs b/src/DotNetOpenAuth.OpenId/OpenId/AssociationContract.cs deleted file mode 100644 index e04a332..0000000 --- a/src/DotNetOpenAuth.OpenId/OpenId/AssociationContract.cs +++ /dev/null @@ -1,65 +0,0 @@ -//----------------------------------------------------------------------- -// <copyright file="AssociationContract.cs" company="Outercurve Foundation"> -// Copyright (c) Outercurve Foundation. All rights reserved. -// </copyright> -//----------------------------------------------------------------------- - -namespace DotNetOpenAuth.OpenId { - using System; - using System.Diagnostics; - using System.Diagnostics.CodeAnalysis; - using System.Diagnostics.Contracts; - using System.IO; - using System.Security.Cryptography; - using System.Text; - using DotNetOpenAuth.Configuration; - using DotNetOpenAuth.Messaging; - - /// <summary> - /// Code contract for the <see cref="Association"/> class. - /// </summary> - [ContractClassFor(typeof(Association))] - internal abstract class AssociationContract : Association { - /// <summary> - /// Prevents a default instance of the <see cref="AssociationContract"/> class from being created. - /// </summary> - private AssociationContract() - : base(null, null, TimeSpan.Zero, DateTime.Now) { - } - - /// <summary> - /// Gets the length (in bits) of the hash this association creates when signing. - /// </summary> - public override int HashBitLength { - get { - Contract.Ensures(Contract.Result<int>() > 0); - throw new NotImplementedException(); - } - } - - /// <summary> - /// The string to pass as the assoc_type value in the OpenID protocol. - /// </summary> - /// <param name="protocol">The protocol version of the message that the assoc_type value will be included in.</param> - /// <returns> - /// The value that should be used for the openid.assoc_type parameter. - /// </returns> - [Pure] - internal override string GetAssociationType(Protocol protocol) { - Requires.NotNull(protocol, "protocol"); - throw new NotImplementedException(); - } - - /// <summary> - /// Returns the specific hash algorithm used for message signing. - /// </summary> - /// <returns> - /// The hash algorithm used for message signing. - /// </returns> - [Pure] - protected override HashAlgorithm CreateHasher() { - Contract.Ensures(Contract.Result<HashAlgorithm>() != null); - throw new NotImplementedException(); - } - } -} diff --git a/src/DotNetOpenAuth.OpenId/OpenId/Behaviors/GsaIcamProfileBase.cs b/src/DotNetOpenAuth.OpenId/OpenId/Behaviors/GsaIcamProfileBase.cs index c7352c8..a51e844 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/Behaviors/GsaIcamProfileBase.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/Behaviors/GsaIcamProfileBase.cs @@ -7,7 +7,6 @@ namespace DotNetOpenAuth.OpenId.Behaviors { using System; using System.Diagnostics.CodeAnalysis; - using System.Diagnostics.Contracts; using System.Linq; using DotNetOpenAuth.Configuration; using DotNetOpenAuth.Messaging; diff --git a/src/DotNetOpenAuth.OpenId/OpenId/ChannelElements/ExtensionsBindingElement.cs b/src/DotNetOpenAuth.OpenId/OpenId/ChannelElements/ExtensionsBindingElement.cs index 46d08a3..f24c8b4 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/ChannelElements/ExtensionsBindingElement.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/ChannelElements/ExtensionsBindingElement.cs @@ -8,13 +8,13 @@ namespace DotNetOpenAuth.OpenId.ChannelElements { using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; - using System.Diagnostics.Contracts; using System.Linq; using System.Text; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.Messaging.Reflection; using DotNetOpenAuth.OpenId.Extensions; using DotNetOpenAuth.OpenId.Messages; + using Validation; /// <summary> /// The binding element that serializes/deserializes OpenID extensions to/from @@ -238,7 +238,7 @@ namespace DotNetOpenAuth.OpenId.ChannelElements { /// A dictionary of message parts, including only signed parts when appropriate. /// </returns> private IDictionary<string, string> GetExtensionsDictionary(IProtocolMessage message, bool ignoreUnsigned) { - Requires.ValidState(this.Channel != null); + RequiresEx.ValidState(this.Channel != null); IndirectSignedResponse signedResponse = message as IndirectSignedResponse; if (signedResponse != null && ignoreUnsigned) { diff --git a/src/DotNetOpenAuth.OpenId/OpenId/ChannelElements/KeyValueFormEncoding.cs b/src/DotNetOpenAuth.OpenId/OpenId/ChannelElements/KeyValueFormEncoding.cs index cdd1085..6ad66c0 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/ChannelElements/KeyValueFormEncoding.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/ChannelElements/KeyValueFormEncoding.cs @@ -8,11 +8,11 @@ namespace DotNetOpenAuth.OpenId.ChannelElements { using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; - using System.Diagnostics.Contracts; using System.Globalization; using System.IO; using System.Text; using DotNetOpenAuth.Messaging; + using Validation; /// <summary> /// Indicates the level of strictness to require when decoding a diff --git a/src/DotNetOpenAuth.OpenId/OpenId/ChannelElements/OpenIdChannel.cs b/src/DotNetOpenAuth.OpenId/OpenId/ChannelElements/OpenIdChannel.cs index 6b88b3f..5a6b8bb 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/ChannelElements/OpenIdChannel.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/ChannelElements/OpenIdChannel.cs @@ -8,7 +8,6 @@ namespace DotNetOpenAuth.OpenId.ChannelElements { using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; - using System.Diagnostics.Contracts; using System.Globalization; using System.IO; using System.Linq; @@ -18,11 +17,11 @@ namespace DotNetOpenAuth.OpenId.ChannelElements { using DotNetOpenAuth.Messaging.Bindings; using DotNetOpenAuth.OpenId.Extensions; using DotNetOpenAuth.OpenId.Messages; + using Validation; /// <summary> /// A channel that knows how to send and receive OpenID messages. /// </summary> - [ContractVerification(true)] internal class OpenIdChannel : Channel { /// <summary> /// The HTTP Content-Type to use in Key-Value Form responses. diff --git a/src/DotNetOpenAuth.OpenId/OpenId/ChannelElements/ReturnToSignatureBindingElement.cs b/src/DotNetOpenAuth.OpenId/OpenId/ChannelElements/ReturnToSignatureBindingElement.cs index 912a322..726c01f 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/ChannelElements/ReturnToSignatureBindingElement.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/ChannelElements/ReturnToSignatureBindingElement.cs @@ -8,13 +8,13 @@ namespace DotNetOpenAuth.OpenId.ChannelElements { using System; using System.Collections.Generic; using System.Collections.Specialized; - using System.Diagnostics.Contracts; using System.Security.Cryptography; using System.Web; using DotNetOpenAuth.Configuration; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.Messaging.Bindings; using DotNetOpenAuth.OpenId.Messages; + using Validation; /// <summary> /// This binding element signs a Relying Party's openid.return_to parameter diff --git a/src/DotNetOpenAuth.OpenId/OpenId/ChannelElements/SigningBindingElement.cs b/src/DotNetOpenAuth.OpenId/OpenId/ChannelElements/SigningBindingElement.cs index 363ff28..584b0e9 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/ChannelElements/SigningBindingElement.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/ChannelElements/SigningBindingElement.cs @@ -8,7 +8,6 @@ namespace DotNetOpenAuth.OpenId.ChannelElements { using System; using System.Collections.Generic; using System.Diagnostics; - using System.Diagnostics.Contracts; using System.Globalization; using System.Linq; using System.Net.Security; @@ -18,11 +17,11 @@ namespace DotNetOpenAuth.OpenId.ChannelElements { using DotNetOpenAuth.Messaging.Bindings; using DotNetOpenAuth.Messaging.Reflection; using DotNetOpenAuth.OpenId.Messages; + using Validation; /// <summary> /// Signs and verifies authentication assertions. /// </summary> - [ContractClass(typeof(SigningBindingElementContract))] internal abstract class SigningBindingElement : IChannelBindingElement { #region IChannelBindingElement Properties @@ -121,7 +120,7 @@ namespace DotNetOpenAuth.OpenId.ChannelElements { /// <returns>The calculated signature of the method.</returns> protected string GetSignature(ITamperResistantOpenIdMessage signedMessage, Association association) { Requires.NotNull(signedMessage, "signedMessage"); - Requires.True(!string.IsNullOrEmpty(signedMessage.SignedParameterOrder), "signedMessage"); + Requires.That(!string.IsNullOrEmpty(signedMessage.SignedParameterOrder), "signedMessage", "SignedParameterOrder must not be null or empty."); Requires.NotNull(association, "association"); // Prepare the parts to sign, taking care to replace an openid.mode value diff --git a/src/DotNetOpenAuth.OpenId/OpenId/ChannelElements/SigningBindingElementContract.cs b/src/DotNetOpenAuth.OpenId/OpenId/ChannelElements/SigningBindingElementContract.cs deleted file mode 100644 index bacbb29..0000000 --- a/src/DotNetOpenAuth.OpenId/OpenId/ChannelElements/SigningBindingElementContract.cs +++ /dev/null @@ -1,64 +0,0 @@ -//----------------------------------------------------------------------- -// <copyright file="SigningBindingElementContract.cs" company="Outercurve Foundation"> -// Copyright (c) Outercurve Foundation. All rights reserved. -// </copyright> -//----------------------------------------------------------------------- - -namespace DotNetOpenAuth.OpenId.ChannelElements { - using System; - using System.Collections.Generic; - using System.Diagnostics; - using System.Diagnostics.Contracts; - using System.Globalization; - using System.Linq; - using System.Net.Security; - using System.Web; - using DotNetOpenAuth.Loggers; - using DotNetOpenAuth.Messaging; - using DotNetOpenAuth.Messaging.Bindings; - using DotNetOpenAuth.Messaging.Reflection; - using DotNetOpenAuth.OpenId.Messages; - - /// <summary> - /// Code contract for the <see cref="SigningBindingElement"/> class. - /// </summary> - [ContractClassFor(typeof(SigningBindingElement))] - internal abstract class SigningBindingElementContract : SigningBindingElement { - /// <summary> - /// Verifies the signature by unrecognized handle. - /// </summary> - /// <param name="message">The message.</param> - /// <param name="signedMessage">The signed message.</param> - /// <param name="protectionsApplied">The protections applied.</param> - /// <returns> - /// The applied protections. - /// </returns> - protected override MessageProtections VerifySignatureByUnrecognizedHandle(IProtocolMessage message, ITamperResistantOpenIdMessage signedMessage, MessageProtections protectionsApplied) { - throw new NotImplementedException(); - } - - /// <summary> - /// Gets the association to use to sign or verify a message. - /// </summary> - /// <param name="signedMessage">The message to sign or verify.</param> - /// <returns> - /// The association to use to sign or verify the message. - /// </returns> - protected override Association GetAssociation(ITamperResistantOpenIdMessage signedMessage) { - Requires.NotNull(signedMessage, "signedMessage"); - throw new NotImplementedException(); - } - - /// <summary> - /// Gets a specific association referenced in a given message's association handle. - /// </summary> - /// <param name="signedMessage">The signed message whose association handle should be used to lookup the association to return.</param> - /// <returns> - /// The referenced association; or <c>null</c> if such an association cannot be found. - /// </returns> - protected override Association GetSpecificAssociation(ITamperResistantOpenIdMessage signedMessage) { - Requires.NotNull(signedMessage, "signedMessage"); - throw new NotImplementedException(); - } - } -} diff --git a/src/DotNetOpenAuth.OpenId/OpenId/DiffieHellmanUtilities.cs b/src/DotNetOpenAuth.OpenId/OpenId/DiffieHellmanUtilities.cs index e15bd6e..6f7fc31 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/DiffieHellmanUtilities.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/DiffieHellmanUtilities.cs @@ -7,13 +7,13 @@ namespace DotNetOpenAuth.OpenId { using System; using System.Collections.Generic; - using System.Diagnostics.Contracts; using System.Globalization; using System.Linq; using System.Security.Cryptography; using System.Text; using DotNetOpenAuth.Messaging; using Org.Mentalis.Security.Cryptography; + using Validation; /// <summary> /// Diffie-Hellman encryption methods used by both the relying party and provider. diff --git a/src/DotNetOpenAuth.OpenId/OpenId/Extensions/AliasManager.cs b/src/DotNetOpenAuth.OpenId/OpenId/Extensions/AliasManager.cs index ff3d3f3..94f7762 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/Extensions/AliasManager.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/Extensions/AliasManager.cs @@ -8,10 +8,10 @@ namespace DotNetOpenAuth.OpenId.Extensions { using System; using System.Collections.Generic; using System.Diagnostics; - using System.Diagnostics.Contracts; using System.Globalization; using System.Text; using DotNetOpenAuth.Messaging; + using Validation; /// <summary> /// Manages a fast, two-way mapping between type URIs and their aliases. diff --git a/src/DotNetOpenAuth.OpenId/OpenId/Extensions/AttributeExchange/AXUtilities.cs b/src/DotNetOpenAuth.OpenId/OpenId/Extensions/AttributeExchange/AXUtilities.cs index 20b8a79..539e570 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/Extensions/AttributeExchange/AXUtilities.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/Extensions/AttributeExchange/AXUtilities.cs @@ -7,9 +7,9 @@ namespace DotNetOpenAuth.OpenId.Extensions.AttributeExchange { using System; using System.Collections.Generic; - using System.Diagnostics.Contracts; using System.Globalization; using DotNetOpenAuth.Messaging; + using Validation; /// <summary> /// Helper methods shared by multiple messages in the Attribute Exchange extension. diff --git a/src/DotNetOpenAuth.OpenId/OpenId/Extensions/AttributeExchange/AttributeRequest.cs b/src/DotNetOpenAuth.OpenId/OpenId/Extensions/AttributeExchange/AttributeRequest.cs index 6590cd1..06ddb45 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/Extensions/AttributeExchange/AttributeRequest.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/Extensions/AttributeExchange/AttributeRequest.cs @@ -7,8 +7,8 @@ namespace DotNetOpenAuth.OpenId.Extensions.AttributeExchange { using System; using System.Diagnostics; - using System.Diagnostics.Contracts; using DotNetOpenAuth.Messaging; + using Validation; /// <summary> /// An individual attribute to be requested of the OpenID Provider using @@ -84,7 +84,7 @@ namespace DotNetOpenAuth.OpenId.Extensions.AttributeExchange { } set { - Requires.InRange(value > 0, "value"); + Requires.Range(value > 0, "value"); this.count = value; } } @@ -100,7 +100,7 @@ namespace DotNetOpenAuth.OpenId.Extensions.AttributeExchange { /// </returns> public AttributeValues Respond(params string[] values) { Requires.NotNull(values, "values"); - Requires.True(values.Length <= this.Count, "values"); + Requires.That(values.Length <= this.Count, "values", "requires values.Length <= this.Count"); return new AttributeValues(this.TypeUri, values); } diff --git a/src/DotNetOpenAuth.OpenId/OpenId/Extensions/AttributeExchange/AttributeValues.cs b/src/DotNetOpenAuth.OpenId/OpenId/Extensions/AttributeExchange/AttributeValues.cs index 44aad04..2aea683 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/Extensions/AttributeExchange/AttributeValues.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/Extensions/AttributeExchange/AttributeValues.cs @@ -8,8 +8,8 @@ namespace DotNetOpenAuth.OpenId.Extensions.AttributeExchange { using System; using System.Collections.Generic; using System.Diagnostics; - using System.Diagnostics.Contracts; using DotNetOpenAuth.Messaging; + using Validation; /// <summary> /// An individual attribute's value(s) as supplied by an OpenID Provider diff --git a/src/DotNetOpenAuth.OpenId/OpenId/Extensions/AttributeExchange/FetchRequest.cs b/src/DotNetOpenAuth.OpenId/OpenId/Extensions/AttributeExchange/FetchRequest.cs index ff47ee6..083d19c 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/Extensions/AttributeExchange/FetchRequest.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/Extensions/AttributeExchange/FetchRequest.cs @@ -8,7 +8,6 @@ namespace DotNetOpenAuth.OpenId.Extensions.AttributeExchange { using System; using System.Collections.Generic; using System.Collections.ObjectModel; - using System.Diagnostics.Contracts; using System.Globalization; using System.Linq; using DotNetOpenAuth.Messaging; @@ -69,7 +68,6 @@ namespace DotNetOpenAuth.OpenId.Extensions.AttributeExchange { /// is all the attribute request details.</value> public KeyedCollection<string, AttributeRequest> Attributes { get { - Contract.Ensures(Contract.Result<KeyedCollection<string, AttributeRequest>>() != null); return this.attributes; } } diff --git a/src/DotNetOpenAuth.OpenId/OpenId/Extensions/AttributeExchange/FetchResponse.cs b/src/DotNetOpenAuth.OpenId/OpenId/Extensions/AttributeExchange/FetchResponse.cs index d5633c3..425b5e2 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/Extensions/AttributeExchange/FetchResponse.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/Extensions/AttributeExchange/FetchResponse.cs @@ -7,7 +7,6 @@ namespace DotNetOpenAuth.OpenId.Extensions.AttributeExchange { using System; using System.Collections.ObjectModel; - using System.Diagnostics.Contracts; using System.Linq; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OpenId.Messages; @@ -54,7 +53,6 @@ namespace DotNetOpenAuth.OpenId.Extensions.AttributeExchange { /// </summary> public KeyedCollection<string, AttributeValues> Attributes { get { - Contract.Ensures(Contract.Result<KeyedCollection<string, AttributeValues>>() != null); return this.attributesProvided; } } diff --git a/src/DotNetOpenAuth.OpenId/OpenId/Extensions/ExtensionArgumentsManager.cs b/src/DotNetOpenAuth.OpenId/OpenId/Extensions/ExtensionArgumentsManager.cs index 1d795da..f3fa7f2 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/Extensions/ExtensionArgumentsManager.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/Extensions/ExtensionArgumentsManager.cs @@ -7,10 +7,10 @@ namespace DotNetOpenAuth.OpenId.Extensions { using System; using System.Collections.Generic; - using System.Diagnostics.Contracts; using System.Globalization; using System.Text; using DotNetOpenAuth.Messaging; + using Validation; /// <summary> /// Manages the processing and construction of OpenID extensions parts. @@ -134,7 +134,7 @@ namespace DotNetOpenAuth.OpenId.Extensions { /// <param name="extensionTypeUri">The extension type URI.</param> /// <param name="arguments">The arguments for this extension to add to the message.</param> public void AddExtensionArguments(string extensionTypeUri, IDictionary<string, string> arguments) { - Requires.ValidState(!this.ReadMode); + RequiresEx.ValidState(!this.ReadMode); Requires.NotNullOrEmpty(extensionTypeUri, "extensionTypeUri"); Requires.NotNull(arguments, "arguments"); if (arguments.Count == 0) { @@ -162,7 +162,7 @@ namespace DotNetOpenAuth.OpenId.Extensions { /// </param> /// <returns>A dictionary of key=value pairs to add to the message to carry the extension.</returns> internal IDictionary<string, string> GetArgumentsToSend(bool includeOpenIdPrefix) { - Requires.ValidState(!this.ReadMode); + RequiresEx.ValidState(!this.ReadMode); Dictionary<string, string> args = new Dictionary<string, string>(); foreach (var typeUriAndExtension in this.extensions) { string typeUri = typeUriAndExtension.Key; @@ -196,7 +196,7 @@ namespace DotNetOpenAuth.OpenId.Extensions { /// </returns> internal IDictionary<string, string> GetExtensionArguments(string extensionTypeUri) { Requires.NotNullOrEmpty(extensionTypeUri, "extensionTypeUri"); - Requires.ValidState(this.ReadMode); + RequiresEx.ValidState(this.ReadMode); IDictionary<string, string> extensionArgs; this.extensions.TryGetValue(extensionTypeUri, out extensionArgs); diff --git a/src/DotNetOpenAuth.OpenId/OpenId/Extensions/OpenIdExtensionFactoryAggregator.cs b/src/DotNetOpenAuth.OpenId/OpenId/Extensions/OpenIdExtensionFactoryAggregator.cs index 2b851dd..ddd60f3 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/Extensions/OpenIdExtensionFactoryAggregator.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/Extensions/OpenIdExtensionFactoryAggregator.cs @@ -6,7 +6,6 @@ namespace DotNetOpenAuth.OpenId.Extensions { using System.Collections.Generic; - using System.Diagnostics.Contracts; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OpenId.ChannelElements; using DotNetOpenAuth.OpenId.Messages; @@ -70,7 +69,6 @@ namespace DotNetOpenAuth.OpenId.Extensions { /// </summary> /// <returns>A new instance of <see cref="OpenIdExtensionFactoryAggregator"/>.</returns> internal static OpenIdExtensionFactoryAggregator LoadFromConfiguration() { - Contract.Ensures(Contract.Result<OpenIdExtensionFactoryAggregator>() != null); var factoriesElement = DotNetOpenAuth.Configuration.OpenIdElement.Configuration.ExtensionFactories; var aggregator = new OpenIdExtensionFactoryAggregator(); aggregator.Factories.Add(new StandardOpenIdExtensionFactory()); diff --git a/src/DotNetOpenAuth.OpenId/OpenId/Extensions/OpenIdExtensionsInteropHelper.cs b/src/DotNetOpenAuth.OpenId/OpenId/Extensions/OpenIdExtensionsInteropHelper.cs index f9d3062..d90dd2a 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/Extensions/OpenIdExtensionsInteropHelper.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/Extensions/OpenIdExtensionsInteropHelper.cs @@ -8,12 +8,12 @@ namespace DotNetOpenAuth.OpenId.Extensions { using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; - using System.Diagnostics.Contracts; using System.Linq; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OpenId.Extensions.AttributeExchange; using DotNetOpenAuth.OpenId.Extensions.SimpleRegistration; using DotNetOpenAuth.OpenId.Messages; + using Validation; /// <summary> /// A set of methods designed to assist in improving interop across different diff --git a/src/DotNetOpenAuth.OpenId/OpenId/Extensions/ProviderAuthenticationPolicy/PapeUtilities.cs b/src/DotNetOpenAuth.OpenId/OpenId/Extensions/ProviderAuthenticationPolicy/PapeUtilities.cs index f017031..e9e8e95 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/Extensions/ProviderAuthenticationPolicy/PapeUtilities.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/Extensions/ProviderAuthenticationPolicy/PapeUtilities.cs @@ -7,11 +7,11 @@ namespace DotNetOpenAuth.OpenId.Extensions.ProviderAuthenticationPolicy { using System; using System.Collections.Generic; - using System.Diagnostics.Contracts; using System.Globalization; using System.Linq; using System.Text; using DotNetOpenAuth.Messaging; + using Validation; /// <summary> /// Utility methods for use by the PAPE extension. diff --git a/src/DotNetOpenAuth.OpenId/OpenId/Extensions/ProviderAuthenticationPolicy/PolicyResponse.cs b/src/DotNetOpenAuth.OpenId/OpenId/Extensions/ProviderAuthenticationPolicy/PolicyResponse.cs index 880a25e..d764118 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/Extensions/ProviderAuthenticationPolicy/PolicyResponse.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/Extensions/ProviderAuthenticationPolicy/PolicyResponse.cs @@ -8,10 +8,10 @@ namespace DotNetOpenAuth.OpenId.Extensions.ProviderAuthenticationPolicy { using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; - using System.Diagnostics.Contracts; using System.Globalization; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OpenId.Messages; + using Validation; /// <summary> /// The PAPE response part of an OpenID Authentication response message. @@ -83,7 +83,7 @@ namespace DotNetOpenAuth.OpenId.Extensions.ProviderAuthenticationPolicy { } set { - Requires.True(!value.HasValue || value.Value.Kind != DateTimeKind.Unspecified, "value", OpenIdStrings.UnspecifiedDateTimeKindNotAllowed); + Requires.That(!value.HasValue || value.Value.Kind != DateTimeKind.Unspecified, "value", OpenIdStrings.UnspecifiedDateTimeKindNotAllowed); // Make sure that whatever is set here, it becomes UTC time. if (value.HasValue) { diff --git a/src/DotNetOpenAuth.OpenId/OpenId/Extensions/SimpleRegistration/ClaimsRequest.cs b/src/DotNetOpenAuth.OpenId/OpenId/Extensions/SimpleRegistration/ClaimsRequest.cs index ab08cbb..f6fd620 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/Extensions/SimpleRegistration/ClaimsRequest.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/Extensions/SimpleRegistration/ClaimsRequest.cs @@ -9,11 +9,11 @@ namespace DotNetOpenAuth.OpenId.Extensions.SimpleRegistration { using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; - using System.Diagnostics.Contracts; using System.Globalization; using System.Text; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OpenId.Messages; + using Validation; /// <summary> /// Carries the request/require/none demand state of the simple registration fields. diff --git a/src/DotNetOpenAuth.OpenId/OpenId/Extensions/SimpleRegistration/ClaimsResponse.cs b/src/DotNetOpenAuth.OpenId/OpenId/Extensions/SimpleRegistration/ClaimsResponse.cs index af60596..361910d 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/Extensions/SimpleRegistration/ClaimsResponse.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/Extensions/SimpleRegistration/ClaimsResponse.cs @@ -8,7 +8,6 @@ namespace DotNetOpenAuth.OpenId.Extensions.SimpleRegistration { using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; - using System.Diagnostics.Contracts; using System.Globalization; using System.Net.Mail; using System.Text; @@ -16,6 +15,7 @@ namespace DotNetOpenAuth.OpenId.Extensions.SimpleRegistration { using System.Xml.Serialization; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OpenId.Messages; + using Validation; /// <summary> /// A struct storing Simple Registration field values describing an diff --git a/src/DotNetOpenAuth.OpenId/OpenId/Extensions/UI/UIRequest.cs b/src/DotNetOpenAuth.OpenId/OpenId/Extensions/UI/UIRequest.cs index 0902a00..731ca1c 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/Extensions/UI/UIRequest.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/Extensions/UI/UIRequest.cs @@ -8,7 +8,6 @@ namespace DotNetOpenAuth.OpenId.Extensions.UI { using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; - using System.Diagnostics.Contracts; using System.Globalization; using System.Linq; using DotNetOpenAuth.Messaging; diff --git a/src/DotNetOpenAuth.OpenId/OpenId/Extensions/UI/UIUtilities.cs b/src/DotNetOpenAuth.OpenId/OpenId/Extensions/UI/UIUtilities.cs index 19e333d..1f48ce3 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/Extensions/UI/UIUtilities.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/Extensions/UI/UIUtilities.cs @@ -6,7 +6,6 @@ namespace DotNetOpenAuth.OpenId.Extensions.UI { using System; - using System.Diagnostics.Contracts; using System.Globalization; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OpenId.RelyingParty; diff --git a/src/DotNetOpenAuth.OpenId/OpenId/HmacShaAssociation.cs b/src/DotNetOpenAuth.OpenId/OpenId/HmacShaAssociation.cs index bf0111d..2eaa8cf 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/HmacShaAssociation.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/HmacShaAssociation.cs @@ -15,11 +15,11 @@ namespace DotNetOpenAuth.OpenId { using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OpenId; using DotNetOpenAuth.OpenId.Messages; + using Validation; /// <summary> /// An association that uses the HMAC-SHA family of algorithms for message signing. /// </summary> - [ContractVerification(true)] internal class HmacShaAssociation : Association { /// <summary> /// A list of HMAC-SHA algorithms in order of decreasing bit lengths. @@ -43,8 +43,7 @@ namespace DotNetOpenAuth.OpenId { Requires.NotNull(typeIdentity, "typeIdentity"); Requires.NotNullOrEmpty(handle, "handle"); Requires.NotNull(secret, "secret"); - Requires.InRange(totalLifeLength > TimeSpan.Zero, "totalLifeLength"); - Contract.Ensures(this.TotalLifeLength == totalLifeLength); + Requires.Range(totalLifeLength > TimeSpan.Zero, "totalLifeLength"); ErrorUtilities.VerifyProtocol(secret.Length == typeIdentity.SecretLength, OpenIdStrings.AssociationSecretAndTypeLengthMismatch, secret.Length, typeIdentity.GetAssociationType(Protocol.Default)); this.typeIdentity = typeIdentity; @@ -73,7 +72,6 @@ namespace DotNetOpenAuth.OpenId { Requires.NotNull(protocol, "protocol"); Requires.NotNullOrEmpty(associationType, "associationType"); Requires.NotNull(secret, "secret"); - Contract.Ensures(Contract.Result<HmacShaAssociation>() != null); HmacSha match = hmacShaAssociationTypes.FirstOrDefault(sha => string.Equals(sha.GetAssociationType(protocol), associationType, StringComparison.Ordinal)); ErrorUtilities.VerifyProtocol(match != null, OpenIdStrings.NoAssociationTypeFoundByName, associationType); return new HmacShaAssociation(match, handle, secret, totalLifeLength); @@ -89,7 +87,6 @@ namespace DotNetOpenAuth.OpenId { public static HmacShaAssociation Create(string handle, byte[] secret, TimeSpan totalLifeLength) { Requires.NotNullOrEmpty(handle, "handle"); Requires.NotNull(secret, "secret"); - Contract.Ensures(Contract.Result<HmacShaAssociation>() != null); HmacSha shaType = hmacShaAssociationTypes.FirstOrDefault(sha => sha.SecretLength == secret.Length); ErrorUtilities.VerifyProtocol(shaType != null, OpenIdStrings.NoAssociationTypeFoundByLength, secret.Length); @@ -211,7 +208,7 @@ namespace DotNetOpenAuth.OpenId { [Pure] protected override HashAlgorithm CreateHasher() { var result = this.typeIdentity.CreateHasher(SecretKey); - Contract.Assume(result != null); + Assumes.True(result != null); return result; } diff --git a/src/DotNetOpenAuth.OpenId/OpenId/IIdentifierDiscoveryService.cs b/src/DotNetOpenAuth.OpenId/OpenId/IIdentifierDiscoveryService.cs index 63c3895..20b8f1c 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/IIdentifierDiscoveryService.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/IIdentifierDiscoveryService.cs @@ -13,11 +13,11 @@ namespace DotNetOpenAuth.OpenId { using System.Text; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OpenId.RelyingParty; + using Validation; /// <summary> /// A module that provides discovery services for OpenID identifiers. /// </summary> - [ContractClass(typeof(IIdentifierDiscoveryServiceContract))] public interface IIdentifierDiscoveryService { /// <summary> /// Performs discovery on the specified identifier. @@ -32,36 +32,4 @@ namespace DotNetOpenAuth.OpenId { [Pure] IEnumerable<IdentifierDiscoveryResult> Discover(Identifier identifier, IDirectWebRequestHandler requestHandler, out bool abortDiscoveryChain); } - - /// <summary> - /// Code contract for the <see cref="IIdentifierDiscoveryService"/> interface. - /// </summary> - [ContractClassFor(typeof(IIdentifierDiscoveryService))] - internal abstract class IIdentifierDiscoveryServiceContract : IIdentifierDiscoveryService { - /// <summary> - /// Prevents a default instance of the <see cref="IIdentifierDiscoveryServiceContract"/> class from being created. - /// </summary> - private IIdentifierDiscoveryServiceContract() { - } - - #region IDiscoveryService Members - - /// <summary> - /// Performs discovery on the specified identifier. - /// </summary> - /// <param name="identifier">The identifier to perform discovery on.</param> - /// <param name="requestHandler">The means to place outgoing HTTP requests.</param> - /// <param name="abortDiscoveryChain">if set to <c>true</c>, no further discovery services will be called for this identifier.</param> - /// <returns> - /// A sequence of service endpoints yielded by discovery. Must not be null, but may be empty. - /// </returns> - IEnumerable<IdentifierDiscoveryResult> IIdentifierDiscoveryService.Discover(Identifier identifier, IDirectWebRequestHandler requestHandler, out bool abortDiscoveryChain) { - Requires.NotNull(identifier, "identifier"); - Requires.NotNull(requestHandler, "requestHandler"); - Contract.Ensures(Contract.Result<IEnumerable<IdentifierDiscoveryResult>>() != null); - throw new NotImplementedException(); - } - - #endregion - } } diff --git a/src/DotNetOpenAuth.OpenId/OpenId/IProviderEndpoint.cs b/src/DotNetOpenAuth.OpenId/OpenId/IProviderEndpoint.cs index b2b231a..b5c1c03 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/IProviderEndpoint.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/IProviderEndpoint.cs @@ -8,7 +8,6 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { using System; using System.Collections.ObjectModel; using System.Diagnostics.CodeAnalysis; - using System.Diagnostics.Contracts; using System.Globalization; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OpenId.Messages; @@ -21,7 +20,6 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { /// Because information provided by this interface is suppplied by a /// user's individually published documents, it may be incomplete or inaccurate. /// </remarks> - [ContractClass(typeof(IProviderEndpointContract))] public interface IProviderEndpoint { /// <summary> /// Gets the detected version of OpenID implemented by the Provider. @@ -67,77 +65,4 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { [Obsolete("Use IAuthenticationRequest.DiscoveryResult.IsExtensionSupported instead.")] bool IsExtensionSupported(Type extensionType); } - - /// <summary> - /// Code contract for the <see cref="IProviderEndpoint"/> type. - /// </summary> - [ContractClassFor(typeof(IProviderEndpoint))] - internal abstract class IProviderEndpointContract : IProviderEndpoint { - /// <summary> - /// Prevents a default instance of the <see cref="IProviderEndpointContract"/> class from being created. - /// </summary> - private IProviderEndpointContract() { - } - - #region IProviderEndpoint Members - - /// <summary> - /// Gets the detected version of OpenID implemented by the Provider. - /// </summary> - Version IProviderEndpoint.Version { - get { - Contract.Ensures(Contract.Result<Version>() != null); - throw new System.NotImplementedException(); - } - } - - /// <summary> - /// Gets the URL that the OpenID Provider receives authentication requests at. - /// </summary> - Uri IProviderEndpoint.Uri { - get { - Contract.Ensures(Contract.Result<Uri>() != null); - throw new System.NotImplementedException(); - } - } - - /// <summary> - /// Checks whether the OpenId Identifier claims support for a given extension. - /// </summary> - /// <typeparam name="T">The extension whose support is being queried.</typeparam> - /// <returns> - /// True if support for the extension is advertised. False otherwise. - /// </returns> - /// <remarks> - /// Note that a true or false return value is no guarantee of a Provider's - /// support for or lack of support for an extension. The return value is - /// determined by how the authenticating user filled out his/her XRDS document only. - /// The only way to be sure of support for a given extension is to include - /// the extension in the request and see if a response comes back for that extension. - /// </remarks> - bool IProviderEndpoint.IsExtensionSupported<T>() { - throw new NotImplementedException(); - } - - /// <summary> - /// Checks whether the OpenId Identifier claims support for a given extension. - /// </summary> - /// <param name="extensionType">The extension whose support is being queried.</param> - /// <returns> - /// True if support for the extension is advertised. False otherwise. - /// </returns> - /// <remarks> - /// Note that a true or false return value is no guarantee of a Provider's - /// support for or lack of support for an extension. The return value is - /// determined by how the authenticating user filled out his/her XRDS document only. - /// The only way to be sure of support for a given extension is to include - /// the extension in the request and see if a response comes back for that extension. - /// </remarks> - bool IProviderEndpoint.IsExtensionSupported(Type extensionType) { - Requires.NotNullSubtype<IOpenIdMessageExtension>(extensionType, "extensionType"); - throw new NotImplementedException(); - } - - #endregion - } } diff --git a/src/DotNetOpenAuth.OpenId/OpenId/Identifier.cs b/src/DotNetOpenAuth.OpenId/OpenId/Identifier.cs index 3cdd0f3..310ebd2 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/Identifier.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/Identifier.cs @@ -12,14 +12,13 @@ namespace DotNetOpenAuth.OpenId { using System.Diagnostics.Contracts; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.Messaging.Reflection; + using Validation; /// <summary> /// An Identifier is either a "http" or "https" URI, or an XRI. /// </summary> [Serializable] - [ContractVerification(true)] [Pure] - [ContractClass(typeof(IdentifierContract))] [DefaultEncoder(typeof(IdentifierEncoder))] public abstract class Identifier { /// <summary> @@ -92,8 +91,7 @@ namespace DotNetOpenAuth.OpenId { [SuppressMessage("Microsoft.Usage", "CA2225:OperatorOverloadsHaveNamedAlternates", Justification = "Our named alternate is Parse.")] [DebuggerStepThrough] public static implicit operator Identifier(string identifier) { - Requires.True(identifier == null || identifier.Length > 0, "identifier"); - Contract.Ensures((identifier == null) == (Contract.Result<Identifier>() == null)); + Requires.That(identifier == null || identifier.Length > 0, "identifier", "Empty string cannot be translated to an identifier."); if (identifier == null) { return null; @@ -109,7 +107,6 @@ namespace DotNetOpenAuth.OpenId { [SuppressMessage("Microsoft.Usage", "CA2225:OperatorOverloadsHaveNamedAlternates", Justification = "We have a Parse function.")] [DebuggerStepThrough] public static implicit operator Identifier(Uri identifier) { - Contract.Ensures((identifier == null) == (Contract.Result<Identifier>() == null)); if (identifier == null) { return null; } @@ -125,7 +122,6 @@ namespace DotNetOpenAuth.OpenId { [SuppressMessage("Microsoft.Usage", "CA2225:OperatorOverloadsHaveNamedAlternates", Justification = "We have a Parse function.")] [DebuggerStepThrough] public static implicit operator string(Identifier identifier) { - Contract.Ensures((identifier == null) == (Contract.Result<string>() == null)); if (identifier == null) { return null; } @@ -141,7 +137,6 @@ namespace DotNetOpenAuth.OpenId { [SuppressMessage("Microsoft.Usage", "CA2234:PassSystemUriObjectsInsteadOfStrings", Justification = "Some of these identifiers are not properly formatted to be Uris at this stage.")] public static Identifier Parse(string identifier) { Requires.NotNullOrEmpty(identifier, "identifier"); - Contract.Ensures(Contract.Result<Identifier>() != null); return Parse(identifier, false); } @@ -158,7 +153,6 @@ namespace DotNetOpenAuth.OpenId { [SuppressMessage("Microsoft.Usage", "CA2234:PassSystemUriObjectsInsteadOfStrings", Justification = "Some of these identifiers are not properly formatted to be Uris at this stage.")] public static Identifier Parse(string identifier, bool serializeExactValue) { Requires.NotNullOrEmpty(identifier, "identifier"); - Contract.Ensures(Contract.Result<Identifier>() != null); Identifier id; if (XriIdentifier.IsValidXri(identifier)) { @@ -265,7 +259,6 @@ namespace DotNetOpenAuth.OpenId { /// <returns>Either <see cref="XriIdentifier"/> or <see cref="UriIdentifier"/>.</returns> internal static Identifier Reparse(Identifier identifier) { Requires.NotNull(identifier, "identifier"); - Contract.Ensures(Contract.Result<Identifier>() != null); return Parse(identifier, identifier.IsDeserializedInstance); } diff --git a/src/DotNetOpenAuth.OpenId/OpenId/IdentifierContract.cs b/src/DotNetOpenAuth.OpenId/OpenId/IdentifierContract.cs deleted file mode 100644 index 0156d12..0000000 --- a/src/DotNetOpenAuth.OpenId/OpenId/IdentifierContract.cs +++ /dev/null @@ -1,56 +0,0 @@ -//----------------------------------------------------------------------- -// <copyright file="IdentifierContract.cs" company="Outercurve Foundation"> -// Copyright (c) Outercurve Foundation. All rights reserved. -// </copyright> -//----------------------------------------------------------------------- - -namespace DotNetOpenAuth.OpenId { - using System; - using System.Collections.Generic; - using System.Diagnostics.Contracts; - using DotNetOpenAuth.Messaging; - - /// <summary> - /// Code Contract for the <see cref="Identifier"/> class. - /// </summary> - [ContractClassFor(typeof(Identifier))] - internal abstract class IdentifierContract : Identifier { - /// <summary> - /// Prevents a default instance of the IdentifierContract class from being created. - /// </summary> - private IdentifierContract() - : base(null, false) { - } - - /// <summary> - /// Returns an <see cref="Identifier"/> that has no URI fragment. - /// Quietly returns the original <see cref="Identifier"/> if it is not - /// a <see cref="UriIdentifier"/> or no fragment exists. - /// </summary> - /// <returns> - /// A new <see cref="Identifier"/> instance if there was a - /// fragment to remove, otherwise this same instance.. - /// </returns> - internal override Identifier TrimFragment() { - Contract.Ensures(Contract.Result<Identifier>() != null); - throw new NotImplementedException(); - } - - /// <summary> - /// Converts a given identifier to its secure equivalent. - /// UriIdentifiers originally created with an implied HTTP scheme change to HTTPS. - /// Discovery is made to require SSL for the entire resolution process. - /// </summary> - /// <param name="secureIdentifier">The newly created secure identifier. - /// If the conversion fails, <paramref name="secureIdentifier"/> retains - /// <i>this</i> identifiers identity, but will never discover any endpoints.</param> - /// <returns> - /// True if the secure conversion was successful. - /// False if the Identifier was originally created with an explicit HTTP scheme. - /// </returns> - internal override bool TryRequireSsl(out Identifier secureIdentifier) { - Contract.Ensures(Contract.ValueAtReturn(out secureIdentifier) != null); - throw new NotImplementedException(); - } - } -} diff --git a/src/DotNetOpenAuth.OpenId/OpenId/IdentifierDiscoveryResult.cs b/src/DotNetOpenAuth.OpenId/OpenId/IdentifierDiscoveryResult.cs index ab69bf6..c7eabf0 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/IdentifierDiscoveryResult.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/IdentifierDiscoveryResult.cs @@ -10,7 +10,6 @@ namespace DotNetOpenAuth.OpenId { using System.Collections.ObjectModel; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; - using System.Diagnostics.Contracts; using System.Globalization; using System.IO; using System.Linq; @@ -18,6 +17,7 @@ namespace DotNetOpenAuth.OpenId { using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OpenId.Messages; using DotNetOpenAuth.OpenId.RelyingParty; + using Validation; /// <summary> /// Represents a single OP endpoint from discovery on some OpenID Identifier. diff --git a/src/DotNetOpenAuth.OpenId/OpenId/IdentifierDiscoveryServices.cs b/src/DotNetOpenAuth.OpenId/OpenId/IdentifierDiscoveryServices.cs index 6a3cfaa..1b20d4e 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/IdentifierDiscoveryServices.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/IdentifierDiscoveryServices.cs @@ -6,10 +6,10 @@ namespace DotNetOpenAuth.OpenId { using System.Collections.Generic; - using System.Diagnostics.Contracts; using System.Linq; using DotNetOpenAuth.Configuration; using DotNetOpenAuth.Messaging; + using Validation; /// <summary> /// A service that can perform discovery on OpenID identifiers. @@ -50,7 +50,6 @@ namespace DotNetOpenAuth.OpenId { /// <returns>A non-null sequence of services discovered for the identifier.</returns> public IEnumerable<IdentifierDiscoveryResult> Discover(Identifier identifier) { Requires.NotNull(identifier, "identifier"); - Contract.Ensures(Contract.Result<IEnumerable<IdentifierDiscoveryResult>>() != null); IEnumerable<IdentifierDiscoveryResult> results = Enumerable.Empty<IdentifierDiscoveryResult>(); foreach (var discoverer in this.DiscoveryServices) { diff --git a/src/DotNetOpenAuth.OpenId/OpenId/Messages/AssociateDiffieHellmanResponse.cs b/src/DotNetOpenAuth.OpenId/OpenId/Messages/AssociateDiffieHellmanResponse.cs index 3860565..1510e97 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/Messages/AssociateDiffieHellmanResponse.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/Messages/AssociateDiffieHellmanResponse.cs @@ -6,7 +6,6 @@ namespace DotNetOpenAuth.OpenId.Messages { using System; - using System.Diagnostics.Contracts; using System.Security.Cryptography; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.Messaging.Reflection; diff --git a/src/DotNetOpenAuth.OpenId/OpenId/Messages/AssociateRequest.cs b/src/DotNetOpenAuth.OpenId/OpenId/Messages/AssociateRequest.cs index 1e716e2..1eaf7b6 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/Messages/AssociateRequest.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/Messages/AssociateRequest.cs @@ -8,7 +8,6 @@ namespace DotNetOpenAuth.OpenId.Messages { using System; using System.Collections.Generic; using System.Diagnostics; - using System.Diagnostics.Contracts; using System.Linq; using System.Text; using DotNetOpenAuth.Messaging; diff --git a/src/DotNetOpenAuth.OpenId/OpenId/Messages/AssociateSuccessfulResponse.cs b/src/DotNetOpenAuth.OpenId/OpenId/Messages/AssociateSuccessfulResponse.cs index 6605530..8daafbd 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/Messages/AssociateSuccessfulResponse.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/Messages/AssociateSuccessfulResponse.cs @@ -8,7 +8,6 @@ namespace DotNetOpenAuth.OpenId.Messages { using System; using System.Collections.Generic; using System.Diagnostics; - using System.Diagnostics.Contracts; using System.Linq; using System.Text; using DotNetOpenAuth.Messaging; @@ -20,7 +19,6 @@ namespace DotNetOpenAuth.OpenId.Messages { /// Association response messages are described in OpenID 2.0 section 8.2. This type covers section 8.2.1. /// </remarks> [DebuggerDisplay("OpenID {Version} associate response {AssociationHandle} {AssociationType} {SessionType}")] - [ContractClass(typeof(AssociateSuccessfulResponseContract))] internal abstract class AssociateSuccessfulResponse : DirectResponseBase { /// <summary> /// Initializes a new instance of the <see cref="AssociateSuccessfulResponse"/> class. diff --git a/src/DotNetOpenAuth.OpenId/OpenId/Messages/AssociateSuccessfulResponseContract.cs b/src/DotNetOpenAuth.OpenId/OpenId/Messages/AssociateSuccessfulResponseContract.cs deleted file mode 100644 index 39a79a4..0000000 --- a/src/DotNetOpenAuth.OpenId/OpenId/Messages/AssociateSuccessfulResponseContract.cs +++ /dev/null @@ -1,17 +0,0 @@ -// <auto-generated /> - -namespace DotNetOpenAuth.OpenId.Messages { - using System; - using System.Collections.Generic; - using System.Diagnostics; - using System.Diagnostics.Contracts; - using System.Linq; - using System.Text; - using DotNetOpenAuth.Messaging; - - [ContractClassFor(typeof(AssociateSuccessfulResponse))] - internal abstract class AssociateSuccessfulResponseContract : AssociateSuccessfulResponse { - protected AssociateSuccessfulResponseContract() : base(null, null) { - } - } -} diff --git a/src/DotNetOpenAuth.OpenId/OpenId/Messages/CheckAuthenticationRequest.cs b/src/DotNetOpenAuth.OpenId/OpenId/Messages/CheckAuthenticationRequest.cs index 0c46411..93cf9d7 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/Messages/CheckAuthenticationRequest.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/Messages/CheckAuthenticationRequest.cs @@ -7,12 +7,12 @@ namespace DotNetOpenAuth.OpenId.Messages { using System; using System.Collections.Generic; - using System.Diagnostics.Contracts; using System.Linq; using System.Text; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.Messaging.Reflection; using DotNetOpenAuth.OpenId.ChannelElements; + using Validation; /// <summary> /// A message a Relying Party sends to a Provider to confirm the validity diff --git a/src/DotNetOpenAuth.OpenId/OpenId/Messages/CheckAuthenticationResponse.cs b/src/DotNetOpenAuth.OpenId/OpenId/Messages/CheckAuthenticationResponse.cs index 9c31ea5..ee9a0b0 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/Messages/CheckAuthenticationResponse.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/Messages/CheckAuthenticationResponse.cs @@ -7,7 +7,6 @@ namespace DotNetOpenAuth.OpenId.Messages { using System; using System.Collections.Generic; - using System.Diagnostics.Contracts; using System.Linq; using System.Text; using DotNetOpenAuth.Messaging; diff --git a/src/DotNetOpenAuth.OpenId/OpenId/Messages/DirectResponseBase.cs b/src/DotNetOpenAuth.OpenId/OpenId/Messages/DirectResponseBase.cs index 787c920..a081159 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/Messages/DirectResponseBase.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/Messages/DirectResponseBase.cs @@ -9,8 +9,8 @@ namespace DotNetOpenAuth.OpenId.Messages { using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; - using System.Diagnostics.Contracts; using DotNetOpenAuth.Messaging; + using Validation; /// <summary> /// A common base class for OpenID direct message responses. diff --git a/src/DotNetOpenAuth.OpenId/OpenId/Messages/IOpenIdMessageExtension.cs b/src/DotNetOpenAuth.OpenId/OpenId/Messages/IOpenIdMessageExtension.cs index dabb752..a7e2268 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/Messages/IOpenIdMessageExtension.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/Messages/IOpenIdMessageExtension.cs @@ -7,7 +7,6 @@ namespace DotNetOpenAuth.OpenId.Messages { using System; using System.Collections.Generic; - using System.Diagnostics.Contracts; using System.Linq; using System.Text; using DotNetOpenAuth.Messaging; @@ -20,7 +19,6 @@ namespace DotNetOpenAuth.OpenId.Messages { /// [<see cref="SerializableAttribute"/>] to allow serializing state servers /// to cache messages, particularly responses. /// </remarks> - [ContractClass(typeof(IOpenIdMessageExtensionContract))] public interface IOpenIdMessageExtension : IExtensionMessage { /// <summary> /// Gets the TypeURI the extension uses in the OpenID protocol and in XRDS advertisements. @@ -53,108 +51,4 @@ namespace DotNetOpenAuth.OpenId.Messages { /// </value> bool IsSignedByRemoteParty { get; set; } } - - /// <summary> - /// Code contract class for the IOpenIdMessageExtension interface. - /// </summary> - [ContractClassFor(typeof(IOpenIdMessageExtension))] - internal abstract class IOpenIdMessageExtensionContract : IOpenIdMessageExtension { - /// <summary> - /// Prevents a default instance of the <see cref="IOpenIdMessageExtensionContract"/> class from being created. - /// </summary> - private IOpenIdMessageExtensionContract() { - } - - #region IOpenIdMessageExtension Members - - /// <summary> - /// Gets the TypeURI the extension uses in the OpenID protocol and in XRDS advertisements. - /// </summary> - string IOpenIdMessageExtension.TypeUri { - get { - Contract.Ensures(!string.IsNullOrEmpty(Contract.Result<string>())); - throw new NotImplementedException(); - } - } - - /// <summary> - /// Gets the additional TypeURIs that are supported by this extension, in preferred order. - /// May be empty if none other than <see cref="IOpenIdMessageExtension.TypeUri"/> is supported, but - /// should not be null. - /// </summary> - /// <remarks> - /// Useful for reading in messages with an older version of an extension. - /// The value in the <see cref="IOpenIdMessageExtension.TypeUri"/> property is always checked before - /// trying this list. - /// If you do support multiple versions of an extension using this method, - /// consider adding a CreateResponse method to your request extension class - /// so that the response can have the context it needs to remain compatible - /// given the version of the extension in the request message. - /// The <see cref="Extensions.SimpleRegistration.ClaimsRequest.CreateResponse"/> for an example. - /// </remarks> - IEnumerable<string> IOpenIdMessageExtension.AdditionalSupportedTypeUris { - get { - Contract.Ensures(Contract.Result<IEnumerable<string>>() != null); - throw new NotImplementedException(); - } - } - - /// <summary> - /// Gets or sets a value indicating whether this extension was - /// signed by the sender. - /// </summary> - /// <value> - /// <c>true</c> if this instance is signed by the sender; otherwise, <c>false</c>. - /// </value> - bool IOpenIdMessageExtension.IsSignedByRemoteParty { - get { throw new NotImplementedException(); } - set { throw new NotImplementedException(); } - } - - #endregion - - #region IMessage Members - - /// <summary> - /// Gets the version of the protocol or extension this message is prepared to implement. - /// </summary> - /// <remarks> - /// Implementations of this interface should ensure that this property never returns null. - /// </remarks> - Version IMessage.Version { - get { - throw new NotImplementedException(); - } - } - - /// <summary> - /// Gets the extra, non-standard Protocol parameters included in the message. - /// </summary> - /// <remarks> - /// Implementations of this interface should ensure that this property never returns null. - /// </remarks> - IDictionary<string, string> IMessage.ExtraData { - get { - throw new NotImplementedException(); - } - } - - /// <summary> - /// Checks the message state for conformity to the protocol specification - /// and throws an exception if the message is invalid. - /// </summary> - /// <remarks> - /// <para>Some messages have required fields, or combinations of fields that must relate to each other - /// in specialized ways. After deserializing a message, this method checks the state of the - /// message to see if it conforms to the protocol.</para> - /// <para>Note that this property should <i>not</i> check signatures or perform any state checks - /// outside this scope of this particular message.</para> - /// </remarks> - /// <exception cref="ProtocolException">Thrown if the message is invalid.</exception> - void IMessage.EnsureValidMessage() { - throw new NotImplementedException(); - } - - #endregion - } } diff --git a/src/DotNetOpenAuth.OpenId/OpenId/Messages/IndirectResponseBase.cs b/src/DotNetOpenAuth.OpenId/OpenId/Messages/IndirectResponseBase.cs index ae0217d..cd56175 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/Messages/IndirectResponseBase.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/Messages/IndirectResponseBase.cs @@ -7,10 +7,10 @@ namespace DotNetOpenAuth.OpenId.Messages { using System; using System.Collections.Generic; - using System.Diagnostics.Contracts; using System.Linq; using System.Text; using DotNetOpenAuth.Messaging; + using Validation; /// <summary> /// A common base class from which indirect response messages should derive. diff --git a/src/DotNetOpenAuth.OpenId/OpenId/Messages/IndirectSignedResponse.cs b/src/DotNetOpenAuth.OpenId/OpenId/Messages/IndirectSignedResponse.cs index 8bceb68..51d6805 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/Messages/IndirectSignedResponse.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/Messages/IndirectSignedResponse.cs @@ -10,7 +10,6 @@ namespace DotNetOpenAuth.OpenId.Messages { using System.Collections.Specialized; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; - using System.Diagnostics.Contracts; using System.Globalization; using System.Linq; using System.Net.Security; @@ -19,6 +18,7 @@ namespace DotNetOpenAuth.OpenId.Messages { using DotNetOpenAuth.Messaging.Bindings; using DotNetOpenAuth.Messaging.Reflection; using DotNetOpenAuth.OpenId.ChannelElements; + using Validation; /// <summary> /// An indirect message from a Provider to a Relying Party where at least part of the diff --git a/src/DotNetOpenAuth.OpenId/OpenId/Messages/NegativeAssertionResponse.cs b/src/DotNetOpenAuth.OpenId/OpenId/Messages/NegativeAssertionResponse.cs index 43fd6f5..9aac107 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/Messages/NegativeAssertionResponse.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/Messages/NegativeAssertionResponse.cs @@ -7,10 +7,10 @@ namespace DotNetOpenAuth.OpenId.Messages { using System; using System.Collections.Generic; - using System.Diagnostics.Contracts; using System.Linq; using System.Text; using DotNetOpenAuth.Messaging; + using Validation; /// <summary> /// The message OpenID Providers send back to Relying Parties to refuse diff --git a/src/DotNetOpenAuth.OpenId/OpenId/Messages/RequestBase.cs b/src/DotNetOpenAuth.OpenId/OpenId/Messages/RequestBase.cs index 678dcee..f91dc96 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/Messages/RequestBase.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/Messages/RequestBase.cs @@ -9,8 +9,8 @@ namespace DotNetOpenAuth.OpenId.Messages { using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; - using System.Diagnostics.Contracts; using DotNetOpenAuth.Messaging; + using Validation; /// <summary> /// A common base class for OpenID request messages and indirect responses (since they are ultimately requests). diff --git a/src/DotNetOpenAuth.OpenId/OpenId/Messages/SignedResponseRequest.cs b/src/DotNetOpenAuth.OpenId/OpenId/Messages/SignedResponseRequest.cs index a2ebb64..688bb40 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/Messages/SignedResponseRequest.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/Messages/SignedResponseRequest.cs @@ -8,10 +8,10 @@ namespace DotNetOpenAuth.OpenId.Messages { using System; using System.Collections.Generic; using System.Diagnostics; - using System.Diagnostics.Contracts; using System.Linq; using System.Text; using DotNetOpenAuth.Messaging; + using Validation; /// <summary> /// An indirect request from a Relying Party to a Provider where the response diff --git a/src/DotNetOpenAuth.OpenId/OpenId/NoDiscoveryIdentifier.cs b/src/DotNetOpenAuth.OpenId/OpenId/NoDiscoveryIdentifier.cs index c439f1f..aa12067 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/NoDiscoveryIdentifier.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/NoDiscoveryIdentifier.cs @@ -10,11 +10,11 @@ namespace DotNetOpenAuth.OpenId { using System.Diagnostics.Contracts; using System.Linq; using DotNetOpenAuth.Messaging; + using Validation; /// <summary> /// Wraps an existing Identifier and prevents it from performing discovery. /// </summary> - [ContractVerification(true)] [Pure] internal class NoDiscoveryIdentifier : Identifier { /// <summary> diff --git a/src/DotNetOpenAuth.OpenId/OpenId/OpenIdUtilities.cs b/src/DotNetOpenAuth.OpenId/OpenId/OpenIdUtilities.cs index a5202de..e04a633 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/OpenIdUtilities.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/OpenIdUtilities.cs @@ -8,7 +8,6 @@ namespace DotNetOpenAuth.OpenId { using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; - using System.Diagnostics.Contracts; using System.Globalization; using System.IO; using System.Linq; @@ -19,6 +18,7 @@ namespace DotNetOpenAuth.OpenId { using DotNetOpenAuth.OpenId.ChannelElements; using DotNetOpenAuth.OpenId.Extensions; using Org.Mentalis.Security.Cryptography; + using Validation; /// <summary> /// A set of utilities especially useful to OpenID. @@ -69,8 +69,6 @@ namespace DotNetOpenAuth.OpenId { /// </summary> /// <returns>The association handle.</returns> public static string GenerateRandomAssociationHandle() { - Contract.Ensures(!string.IsNullOrEmpty(Contract.Result<string>())); - // Generate the handle. It must be unique, and preferably unpredictable, // so we use a time element and a random data element to generate it. string uniq = MessagingUtilities.GetCryptoRandomDataAsBase64(4); diff --git a/src/DotNetOpenAuth.OpenId/OpenId/OpenIdXrdsHelper.cs b/src/DotNetOpenAuth.OpenId/OpenId/OpenIdXrdsHelper.cs index 284f8db..4fca2af 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/OpenIdXrdsHelper.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/OpenIdXrdsHelper.cs @@ -7,10 +7,10 @@ namespace DotNetOpenAuth.OpenId { using System; using System.Collections.Generic; - using System.Diagnostics.Contracts; using System.Linq; using System.Text; using DotNetOpenAuth.Xrds; + using Validation; /// <summary> /// Utility methods for working with XRDS documents. @@ -27,7 +27,6 @@ namespace DotNetOpenAuth.OpenId { /// </remarks> internal static IEnumerable<RelyingPartyEndpointDescription> FindRelyingPartyReceivingEndpoints(this XrdsDocument xrds) { Requires.NotNull(xrds, "xrds"); - Contract.Ensures(Contract.Result<IEnumerable<RelyingPartyEndpointDescription>>() != null); return from service in xrds.FindReturnToServices() from uri in service.UriElements @@ -42,7 +41,6 @@ namespace DotNetOpenAuth.OpenId { /// <returns>A sequence of the icon URLs in preferred order.</returns> internal static IEnumerable<Uri> FindRelyingPartyIcons(this XrdsDocument xrds) { Requires.NotNull(xrds, "xrds"); - Contract.Ensures(Contract.Result<IEnumerable<Uri>>() != null); return from xrd in xrds.XrdElements from service in xrd.OpenIdRelyingPartyIcons @@ -58,7 +56,6 @@ namespace DotNetOpenAuth.OpenId { /// <returns>A sequence of service elements.</returns> private static IEnumerable<ServiceElement> FindReturnToServices(this XrdsDocument xrds) { Requires.NotNull(xrds, "xrds"); - Contract.Ensures(Contract.Result<IEnumerable<ServiceElement>>() != null); return from xrd in xrds.XrdElements from service in xrd.OpenIdRelyingPartyReturnToServices diff --git a/src/DotNetOpenAuth.OpenId/OpenId/Protocol.cs b/src/DotNetOpenAuth.OpenId/OpenId/Protocol.cs index 22f5b9c..7ef3ab5 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/Protocol.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/Protocol.cs @@ -11,8 +11,8 @@ namespace DotNetOpenAuth.OpenId { using DotNetOpenAuth.Messaging; using System.Globalization; using System.Diagnostics.CodeAnalysis; - using System.Diagnostics.Contracts; using System.Diagnostics; + using Validation; /// <summary> /// An enumeration of the OpenID protocol versions supported by this library. diff --git a/src/DotNetOpenAuth.OpenId/OpenId/Provider/IAuthenticationRequest.cs b/src/DotNetOpenAuth.OpenId/OpenId/Provider/IAuthenticationRequest.cs index 5e8efa5..0b121b7 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/Provider/IAuthenticationRequest.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/Provider/IAuthenticationRequest.cs @@ -7,7 +7,6 @@ namespace DotNetOpenAuth.OpenId.Provider { using System; using System.Collections.Generic; - using System.Diagnostics.Contracts; using System.Text; using DotNetOpenAuth.Messaging; @@ -16,7 +15,6 @@ namespace DotNetOpenAuth.OpenId.Provider { /// This interface provides the details of the request and allows setting /// the response. /// </summary> - [ContractClass(typeof(IAuthenticationRequestContract))] public interface IAuthenticationRequest : IHostProcessedRequest { /// <summary> /// Gets a value indicating whether the Provider should help the user @@ -95,273 +93,4 @@ namespace DotNetOpenAuth.OpenId.Provider { /// </exception> void SetClaimedIdentifierFragment(string fragment); } - - /// <summary> - /// Code contract class for the <see cref="IAuthenticationRequest"/> type. - /// </summary> - [ContractClassFor(typeof(IAuthenticationRequest))] - internal abstract class IAuthenticationRequestContract : IAuthenticationRequest { - /// <summary> - /// Initializes a new instance of the <see cref="IAuthenticationRequestContract"/> class. - /// </summary> - protected IAuthenticationRequestContract() { - } - - #region IAuthenticationRequest Properties - - /// <summary> - /// Gets a value indicating whether the Provider should help the user - /// select a Claimed Identifier to send back to the relying party. - /// </summary> - bool IAuthenticationRequest.IsDirectedIdentity { - get { throw new NotImplementedException(); } - } - - /// <summary> - /// Gets a value indicating whether the requesting Relying Party is using a delegated URL. - /// </summary> - /// <remarks> - /// When delegated identifiers are used, the <see cref="IAuthenticationRequest.ClaimedIdentifier"/> should not - /// be changed at the Provider during authentication. - /// Delegation is only detectable on requests originating from OpenID 2.0 relying parties. - /// A relying party implementing only OpenID 1.x may use delegation and this property will - /// return false anyway. - /// </remarks> - bool IAuthenticationRequest.IsDelegatedIdentifier { - get { throw new NotImplementedException(); } - } - - /// <summary> - /// Gets or sets the Local Identifier to this OpenID Provider of the user attempting - /// to authenticate. Check <see cref="IAuthenticationRequest.IsDirectedIdentity"/> to see if - /// this value is valid. - /// </summary> - /// <remarks> - /// This may or may not be the same as the Claimed Identifier that the user agent - /// originally supplied to the relying party. The Claimed Identifier - /// endpoint may be delegating authentication to this provider using - /// this provider's local id, which is what this property contains. - /// Use this identifier when looking up this user in the provider's user account - /// list. - /// </remarks> - Identifier IAuthenticationRequest.LocalIdentifier { - get { - throw new NotImplementedException(); - } - - set { - throw new NotImplementedException(); - } - } - - /// <summary> - /// Gets or sets the identifier that the user agent is claiming at the relying party site. - /// Check <see cref="IAuthenticationRequest.IsDirectedIdentity"/> to see if this value is valid. - /// </summary> - /// <remarks> - /// <para>This property can only be set if <see cref="IAuthenticationRequest.IsDelegatedIdentifier"/> is - /// false, to prevent breaking URL delegation.</para> - /// <para>This will not be the same as this provider's local identifier for the user - /// if the user has set up his/her own identity page that points to this - /// provider for authentication.</para> - /// <para>The provider may use this identifier for displaying to the user when - /// asking for the user's permission to authenticate to the relying party.</para> - /// </remarks> - /// <exception cref="InvalidOperationException">Thrown from the setter - /// if <see cref="IAuthenticationRequest.IsDelegatedIdentifier"/> is true.</exception> - Identifier IAuthenticationRequest.ClaimedIdentifier { - get { - throw new NotImplementedException(); - } - - set { - IAuthenticationRequest req = this; - Requires.ValidState(!req.IsDelegatedIdentifier, OpenIdStrings.ClaimedIdentifierCannotBeSetOnDelegatedAuthentication); - Requires.ValidState(!req.IsDirectedIdentity || !(req.LocalIdentifier != null && req.LocalIdentifier != value), OpenIdStrings.IdentifierSelectRequiresMatchingIdentifiers); - } - } - - /// <summary> - /// Gets or sets a value indicating whether the provider has determined that the - /// <see cref="IAuthenticationRequest.ClaimedIdentifier"/> belongs to the currently logged in user - /// and wishes to share this information with the consumer. - /// </summary> - bool? IAuthenticationRequest.IsAuthenticated { - get { - throw new NotImplementedException(); - } - - set { - throw new NotImplementedException(); - } - } - - #endregion - - #region IHostProcessedRequest Properties - - /// <summary> - /// Gets the version of OpenID being used by the relying party that sent the request. - /// </summary> - ProtocolVersion IHostProcessedRequest.RelyingPartyVersion { - get { throw new NotImplementedException(); } - } - - /// <summary> - /// Gets the URL the consumer site claims to use as its 'base' address. - /// </summary> - Realm IHostProcessedRequest.Realm { - get { throw new NotImplementedException(); } - } - - /// <summary> - /// Gets a value indicating whether the consumer demands an immediate response. - /// If false, the consumer is willing to wait for the identity provider - /// to authenticate the user. - /// </summary> - bool IHostProcessedRequest.Immediate { - get { throw new NotImplementedException(); } - } - - /// <summary> - /// Gets or sets the provider endpoint claimed in the positive assertion. - /// </summary> - /// <value> - /// The default value is the URL that the request came in on from the relying party. - /// This value MUST match the value for the OP Endpoint in the discovery results for the - /// claimed identifier being asserted in a positive response. - /// </value> - Uri IHostProcessedRequest.ProviderEndpoint { - get { - throw new NotImplementedException(); - } - - set { - throw new NotImplementedException(); - } - } - - #endregion - - #region IRequest Properties - - /// <summary> - /// Gets a value indicating whether the response is ready to be sent to the user agent. - /// </summary> - /// <remarks> - /// This property returns false if there are properties that must be set on this - /// request instance before the response can be sent. - /// </remarks> - bool IRequest.IsResponseReady { - get { throw new NotImplementedException(); } - } - - /// <summary> - /// Gets or sets the security settings that apply to this request. - /// </summary> - /// <value> - /// Defaults to the OpenIdProvider.SecuritySettings on the OpenIdProvider. - /// </value> - ProviderSecuritySettings IRequest.SecuritySettings { - get { - throw new NotImplementedException(); - } - - set { - throw new NotImplementedException(); - } - } - - #endregion - - #region IAuthenticationRequest Methods - - /// <summary> - /// Adds an optional fragment (#fragment) portion to the ClaimedIdentifier. - /// Useful for identifier recycling. - /// </summary> - /// <param name="fragment">Should not include the # prefix character as that will be added internally. - /// May be null or the empty string to clear a previously set fragment.</param> - /// <remarks> - /// <para>Unlike the <see cref="IAuthenticationRequest.ClaimedIdentifier"/> property, which can only be set if - /// using directed identity, this method can be called on any URI claimed identifier.</para> - /// <para>Because XRI claimed identifiers (the canonical IDs) are never recycled, - /// this method should<i>not</i> be called for XRIs.</para> - /// </remarks> - /// <exception cref="InvalidOperationException"> - /// Thrown when this method is called on an XRI, or on a directed identity - /// request before the <see cref="IAuthenticationRequest.ClaimedIdentifier"/> property is set. - /// </exception> - void IAuthenticationRequest.SetClaimedIdentifierFragment(string fragment) { - Requires.ValidState(!(((IAuthenticationRequest)this).IsDirectedIdentity && ((IAuthenticationRequest)this).ClaimedIdentifier == null), OpenIdStrings.ClaimedIdentifierMustBeSetFirst); - Requires.ValidState(!(((IAuthenticationRequest)this).ClaimedIdentifier is XriIdentifier), OpenIdStrings.FragmentNotAllowedOnXRIs); - - throw new NotImplementedException(); - } - - #endregion - - #region IHostProcessedRequest Methods - - /// <summary> - /// Attempts to perform relying party discovery of the return URL claimed by the Relying Party. - /// </summary> - /// <param name="webRequestHandler">The web request handler to use for the RP discovery request.</param> - /// <returns> - /// The details of how successful the relying party discovery was. - /// </returns> - /// <remarks> - /// <para>Return URL verification is only attempted if this method is called.</para> - /// <para>See OpenID Authentication 2.0 spec section 9.2.1.</para> - /// </remarks> - RelyingPartyDiscoveryResult IHostProcessedRequest.IsReturnUrlDiscoverable(IDirectWebRequestHandler webRequestHandler) { - throw new NotImplementedException(); - } - - #endregion - - #region IRequest Methods - - /// <summary> - /// Adds an extension to the response to send to the relying party. - /// </summary> - /// <param name="extension">The extension to add to the response message.</param> - void IRequest.AddResponseExtension(DotNetOpenAuth.OpenId.Messages.IOpenIdMessageExtension extension) { - throw new NotImplementedException(); - } - - /// <summary> - /// Removes any response extensions previously added using <see cref="IRequest.AddResponseExtension"/>. - /// </summary> - /// <remarks> - /// This should be called before sending a negative response back to the relying party - /// if extensions were already added, since negative responses cannot carry extensions. - /// </remarks> - void IRequest.ClearResponseExtensions() { - } - - /// <summary> - /// Gets an extension sent from the relying party. - /// </summary> - /// <typeparam name="T">The type of the extension.</typeparam> - /// <returns> - /// An instance of the extension initialized with values passed in with the request. - /// </returns> - T IRequest.GetExtension<T>() { - throw new NotImplementedException(); - } - - /// <summary> - /// Gets an extension sent from the relying party. - /// </summary> - /// <param name="extensionType">The type of the extension.</param> - /// <returns> - /// An instance of the extension initialized with values passed in with the request. - /// </returns> - DotNetOpenAuth.OpenId.Messages.IOpenIdMessageExtension IRequest.GetExtension(Type extensionType) { - throw new NotImplementedException(); - } - - #endregion - } } diff --git a/src/DotNetOpenAuth.OpenId/OpenId/Provider/IHostProcessedRequest.cs b/src/DotNetOpenAuth.OpenId/OpenId/Provider/IHostProcessedRequest.cs index 236f4a8..4a464b9 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/Provider/IHostProcessedRequest.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/Provider/IHostProcessedRequest.cs @@ -6,15 +6,14 @@ namespace DotNetOpenAuth.OpenId.Provider { using System; - using System.Diagnostics.Contracts; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OpenId.Messages; + using Validation; /// <summary> /// Interface exposing incoming messages to the OpenID Provider that /// require interaction with the host site. /// </summary> - [ContractClass(typeof(IHostProcessedRequestContract))] public interface IHostProcessedRequest : IRequest { /// <summary> /// Gets the version of OpenID being used by the relying party that sent the request. @@ -56,147 +55,4 @@ namespace DotNetOpenAuth.OpenId.Provider { /// </remarks> RelyingPartyDiscoveryResult IsReturnUrlDiscoverable(IDirectWebRequestHandler webRequestHandler); } - - /// <summary> - /// Code contract for the <see cref="IHostProcessedRequest"/> type. - /// </summary> - [ContractClassFor(typeof(IHostProcessedRequest))] - internal abstract class IHostProcessedRequestContract : IHostProcessedRequest { - /// <summary> - /// Initializes a new instance of the <see cref="IHostProcessedRequestContract"/> class. - /// </summary> - protected IHostProcessedRequestContract() { - } - - #region IHostProcessedRequest Properties - - /// <summary> - /// Gets the version of OpenID being used by the relying party that sent the request. - /// </summary> - ProtocolVersion IHostProcessedRequest.RelyingPartyVersion { - get { throw new System.NotImplementedException(); } - } - - /// <summary> - /// Gets the URL the consumer site claims to use as its 'base' address. - /// </summary> - Realm IHostProcessedRequest.Realm { - get { throw new System.NotImplementedException(); } - } - - /// <summary> - /// Gets a value indicating whether the consumer demands an immediate response. - /// If false, the consumer is willing to wait for the identity provider - /// to authenticate the user. - /// </summary> - bool IHostProcessedRequest.Immediate { - get { throw new System.NotImplementedException(); } - } - - /// <summary> - /// Gets or sets the provider endpoint. - /// </summary> - /// <value> - /// The default value is the URL that the request came in on from the relying party. - /// </value> - Uri IHostProcessedRequest.ProviderEndpoint { - get { - Contract.Ensures(Contract.Result<Uri>() != null); - throw new NotImplementedException(); - } - - set { - Contract.Requires(value != null); - throw new NotImplementedException(); - } - } - - #endregion - - #region IRequest Members - - /// <summary> - /// Gets or sets the security settings that apply to this request. - /// </summary> - /// <value> - /// Defaults to the OpenIdProvider.SecuritySettings on the OpenIdProvider. - /// </value> - ProviderSecuritySettings IRequest.SecuritySettings { - get { throw new NotImplementedException(); } - set { throw new NotImplementedException(); } - } - - /// <summary> - /// Gets a value indicating whether the response is ready to be sent to the user agent. - /// </summary> - /// <remarks> - /// This property returns false if there are properties that must be set on this - /// request instance before the response can be sent. - /// </remarks> - bool IRequest.IsResponseReady { - get { throw new System.NotImplementedException(); } - } - - /// <summary> - /// Adds an extension to the response to send to the relying party. - /// </summary> - /// <param name="extension">The extension to add to the response message.</param> - void IRequest.AddResponseExtension(DotNetOpenAuth.OpenId.Messages.IOpenIdMessageExtension extension) { - throw new System.NotImplementedException(); - } - - /// <summary> - /// Removes any response extensions previously added using <see cref="IRequest.AddResponseExtension"/>. - /// </summary> - /// <remarks> - /// This should be called before sending a negative response back to the relying party - /// if extensions were already added, since negative responses cannot carry extensions. - /// </remarks> - void IRequest.ClearResponseExtensions() { - } - - /// <summary> - /// Gets an extension sent from the relying party. - /// </summary> - /// <typeparam name="T">The type of the extension.</typeparam> - /// <returns> - /// An instance of the extension initialized with values passed in with the request. - /// </returns> - T IRequest.GetExtension<T>() { - throw new System.NotImplementedException(); - } - - /// <summary> - /// Gets an extension sent from the relying party. - /// </summary> - /// <param name="extensionType">The type of the extension.</param> - /// <returns> - /// An instance of the extension initialized with values passed in with the request. - /// </returns> - DotNetOpenAuth.OpenId.Messages.IOpenIdMessageExtension IRequest.GetExtension(System.Type extensionType) { - throw new System.NotImplementedException(); - } - - #endregion - - #region IHostProcessedRequest Methods - - /// <summary> - /// Attempts to perform relying party discovery of the return URL claimed by the Relying Party. - /// </summary> - /// <param name="webRequestHandler">The web request handler.</param> - /// <returns> - /// The details of how successful the relying party discovery was. - /// </returns> - /// <remarks> - /// <para>Return URL verification is only attempted if this method is called.</para> - /// <para>See OpenID Authentication 2.0 spec section 9.2.1.</para> - /// </remarks> - RelyingPartyDiscoveryResult IHostProcessedRequest.IsReturnUrlDiscoverable(IDirectWebRequestHandler webRequestHandler) { - Requires.NotNull(webRequestHandler, "webRequestHandler"); - throw new System.NotImplementedException(); - } - - #endregion - } } diff --git a/src/DotNetOpenAuth.OpenId/OpenId/Provider/IProviderBehavior.cs b/src/DotNetOpenAuth.OpenId/OpenId/Provider/IProviderBehavior.cs index 840fe3a..57fe66b 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/Provider/IProviderBehavior.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/Provider/IProviderBehavior.cs @@ -6,13 +6,12 @@ namespace DotNetOpenAuth.OpenId.Provider { using System; - using System.Diagnostics.Contracts; using DotNetOpenAuth.OpenId.ChannelElements; + using Validation; /// <summary> /// Applies a custom security policy to certain OpenID security settings and behaviors. /// </summary> - [ContractClass(typeof(IProviderBehaviorContract))] public interface IProviderBehavior { /// <summary> /// Applies a well known set of security requirements to a default set of security settings. @@ -50,65 +49,4 @@ namespace DotNetOpenAuth.OpenId.Provider { /// </returns> bool OnOutgoingResponse(IAuthenticationRequest request); } - - /// <summary> - /// Code contract for the <see cref="IProviderBehavior"/> type. - /// </summary> - [ContractClassFor(typeof(IProviderBehavior))] - internal abstract class IProviderBehaviorContract : IProviderBehavior { - /// <summary> - /// Initializes a new instance of the <see cref="IProviderBehaviorContract"/> class. - /// </summary> - protected IProviderBehaviorContract() { - } - - #region IProviderBehavior Members - - /// <summary> - /// Applies a well known set of security requirements to a default set of security settings. - /// </summary> - /// <param name="securitySettings">The security settings to enhance with the requirements of this profile.</param> - /// <remarks> - /// Care should be taken to never decrease security when applying a profile. - /// Profiles should only enhance security requirements to avoid being - /// incompatible with each other. - /// </remarks> - void IProviderBehavior.ApplySecuritySettings(ProviderSecuritySettings securitySettings) { - Requires.NotNull(securitySettings, "securitySettings"); - throw new System.NotImplementedException(); - } - - /// <summary> - /// Called when a request is received by the Provider. - /// </summary> - /// <param name="request">The incoming request.</param> - /// <returns> - /// <c>true</c> if this behavior owns this request and wants to stop other behaviors - /// from handling it; <c>false</c> to allow other behaviors to process this request. - /// </returns> - /// <remarks> - /// Implementations may set a new value to <see cref="IRequest.SecuritySettings"/> but - /// should not change the properties on the instance of <see cref="ProviderSecuritySettings"/> - /// itself as that instance may be shared across many requests. - /// </remarks> - bool IProviderBehavior.OnIncomingRequest(IRequest request) { - Requires.NotNull(request, "request"); - throw new System.NotImplementedException(); - } - - /// <summary> - /// Called when the Provider is preparing to send a response to an authentication request. - /// </summary> - /// <param name="request">The request that is configured to generate the outgoing response.</param> - /// <returns> - /// <c>true</c> if this behavior owns this request and wants to stop other behaviors - /// from handling it; <c>false</c> to allow other behaviors to process this request. - /// </returns> - bool IProviderBehavior.OnOutgoingResponse(IAuthenticationRequest request) { - Requires.NotNull(request, "request"); - throw new System.NotImplementedException(); - } - - #endregion - } } diff --git a/src/DotNetOpenAuth.OpenId/OpenId/Provider/IRequest.cs b/src/DotNetOpenAuth.OpenId/OpenId/Provider/IRequest.cs index 0e29792..791237f 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/Provider/IRequest.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/Provider/IRequest.cs @@ -8,10 +8,10 @@ namespace DotNetOpenAuth.OpenId.Provider { using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; - using System.Diagnostics.Contracts; using System.Text; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OpenId.Messages; + using Validation; /// <summary> /// Represents an incoming OpenId authentication request. @@ -21,7 +21,6 @@ namespace DotNetOpenAuth.OpenId.Provider { /// be authentication requests where the Provider site has to make decisions based /// on its own user database and policies. /// </remarks> - [ContractClass(typeof(IRequestContract))] public interface IRequest { /// <summary> /// Gets a value indicating whether the response is ready to be sent to the user agent. @@ -68,82 +67,4 @@ namespace DotNetOpenAuth.OpenId.Provider { /// <returns>An instance of the extension initialized with values passed in with the request.</returns> IOpenIdMessageExtension GetExtension(Type extensionType); } - - /// <summary> - /// Code contract for the <see cref="IRequest"/> interface. - /// </summary> - [ContractClassFor(typeof(IRequest))] - internal abstract class IRequestContract : IRequest { - /// <summary> - /// Prevents a default instance of the <see cref="IRequestContract"/> class from being created. - /// </summary> - private IRequestContract() { - } - - #region IRequest Members - - /// <summary> - /// Gets or sets the security settings that apply to this request. - /// </summary> - /// <value>Defaults to the OpenIdProvider.SecuritySettings on the OpenIdProvider.</value> - ProviderSecuritySettings IRequest.SecuritySettings { - get { throw new NotImplementedException(); } - set { throw new NotImplementedException(); } - } - - /// <summary> - /// Gets a value indicating whether the response is ready to be sent to the user agent. - /// </summary> - /// <remarks> - /// This property returns false if there are properties that must be set on this - /// request instance before the response can be sent. - /// </remarks> - bool IRequest.IsResponseReady { - get { throw new NotImplementedException(); } - } - - /// <summary> - /// Adds an extension to the response to send to the relying party. - /// </summary> - /// <param name="extension">The extension to add to the response message.</param> - void IRequest.AddResponseExtension(IOpenIdMessageExtension extension) { - Requires.NotNull(extension, "extension"); - throw new NotImplementedException(); - } - - /// <summary> - /// Removes any response extensions previously added using <see cref="IRequest.AddResponseExtension"/>. - /// </summary> - /// <remarks> - /// This should be called before sending a negative response back to the relying party - /// if extensions were already added, since negative responses cannot carry extensions. - /// </remarks> - void IRequest.ClearResponseExtensions() { - } - - /// <summary> - /// Gets an extension sent from the relying party. - /// </summary> - /// <typeparam name="T">The type of the extension.</typeparam> - /// <returns> - /// An instance of the extension initialized with values passed in with the request. - /// </returns> - T IRequest.GetExtension<T>() { - throw new NotImplementedException(); - } - - /// <summary> - /// Gets an extension sent from the relying party. - /// </summary> - /// <param name="extensionType">The type of the extension.</param> - /// <returns> - /// An instance of the extension initialized with values passed in with the request. - /// </returns> - IOpenIdMessageExtension IRequest.GetExtension(Type extensionType) { - Requires.NotNull(extensionType, "extensionType"); - throw new NotImplementedException(); - } - - #endregion - } } diff --git a/src/DotNetOpenAuth.OpenId/OpenId/ProviderEndpointDescription.cs b/src/DotNetOpenAuth.OpenId/OpenId/ProviderEndpointDescription.cs index 7cac8c6..ff87795 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/ProviderEndpointDescription.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/ProviderEndpointDescription.cs @@ -9,11 +9,11 @@ namespace DotNetOpenAuth.OpenId { using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics.CodeAnalysis; - using System.Diagnostics.Contracts; using System.Linq; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OpenId.Messages; using DotNetOpenAuth.OpenId.RelyingParty; + using Validation; /// <summary> /// Describes some OpenID Provider endpoint and its capabilities. diff --git a/src/DotNetOpenAuth.OpenId/OpenId/Realm.cs b/src/DotNetOpenAuth.OpenId/OpenId/Realm.cs index 8f1baed..c1a959e 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/Realm.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/Realm.cs @@ -19,6 +19,7 @@ namespace DotNetOpenAuth.OpenId { using DotNetOpenAuth.Messaging.Reflection; using DotNetOpenAuth.Xrds; using DotNetOpenAuth.Yadis; + using Validation; /// <summary> /// A trust root to validate requests and match return URLs against. @@ -113,8 +114,7 @@ namespace DotNetOpenAuth.OpenId { /// </remarks> public static Realm AutoDetect { get { - Requires.ValidState(HttpContext.Current != null && HttpContext.Current.Request != null, MessagingStrings.HttpContextRequired); - Contract.Ensures(Contract.Result<Realm>() != null); + RequiresEx.ValidState(HttpContext.Current != null && HttpContext.Current.Request != null, MessagingStrings.HttpContextRequired); var realmUrl = new UriBuilder(MessagingUtilities.GetWebRoot()); @@ -260,7 +260,6 @@ namespace DotNetOpenAuth.OpenId { [SuppressMessage("Microsoft.Usage", "CA2234:PassSystemUriObjectsInsteadOfStrings", Justification = "Not all Realms are valid URLs.")] [DebuggerStepThrough] public static implicit operator Realm(string uri) { - Contract.Ensures((Contract.Result<Realm>() != null) == (uri != null)); return uri != null ? new Realm(uri) : null; } @@ -271,7 +270,6 @@ namespace DotNetOpenAuth.OpenId { /// <returns>The result of the conversion.</returns> [DebuggerStepThrough] public static implicit operator Realm(Uri uri) { - Contract.Ensures((Contract.Result<Realm>() != null) == (uri != null)); return uri != null ? new Realm(uri) : null; } @@ -282,7 +280,6 @@ namespace DotNetOpenAuth.OpenId { /// <returns>The result of the conversion.</returns> [DebuggerStepThrough] public static implicit operator string(Realm realm) { - Contract.Ensures((Contract.Result<string>() != null) == (realm != null)); return realm != null ? realm.ToString() : null; } diff --git a/src/DotNetOpenAuth.OpenId/OpenId/RelyingParty/IAuthenticationRequest.cs b/src/DotNetOpenAuth.OpenId/OpenId/RelyingParty/IAuthenticationRequest.cs index 92e3233..886029c 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/RelyingParty/IAuthenticationRequest.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/RelyingParty/IAuthenticationRequest.cs @@ -7,7 +7,6 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { using System; using System.Collections.Generic; - using System.Diagnostics.Contracts; using System.Linq; using System.Text; using DotNetOpenAuth.Messaging; @@ -18,7 +17,6 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { /// requests that may be queried/modified in specific ways before being /// routed to the OpenID Provider. /// </summary> - [ContractClass(typeof(IAuthenticationRequestContract))] public interface IAuthenticationRequest { /// <summary> /// Gets or sets the mode the Provider should use during authentication. diff --git a/src/DotNetOpenAuth.OpenId/OpenId/RelyingParty/IAuthenticationRequestContract.cs b/src/DotNetOpenAuth.OpenId/OpenId/RelyingParty/IAuthenticationRequestContract.cs deleted file mode 100644 index 4ddc6ae..0000000 --- a/src/DotNetOpenAuth.OpenId/OpenId/RelyingParty/IAuthenticationRequestContract.cs +++ /dev/null @@ -1,111 +0,0 @@ -// <auto-generated /> - -namespace DotNetOpenAuth.OpenId.RelyingParty { - using System; - using System.Collections.Generic; - using System.Diagnostics.Contracts; - using System.Linq; - using System.Text; - using DotNetOpenAuth.Messaging; - using DotNetOpenAuth.OpenId.Messages; - - [ContractClassFor(typeof(IAuthenticationRequest))] - internal abstract class IAuthenticationRequestContract : IAuthenticationRequest { - #region IAuthenticationRequest Members - - AuthenticationRequestMode IAuthenticationRequest.Mode { - get { - throw new NotImplementedException(); - } - - set { - throw new NotImplementedException(); - } - } - - OutgoingWebResponse IAuthenticationRequest.RedirectingResponse { - get { throw new NotImplementedException(); } - } - - Uri IAuthenticationRequest.ReturnToUrl { - get { throw new NotImplementedException(); } - } - - Realm IAuthenticationRequest.Realm { - get { - Contract.Ensures(Contract.Result<Realm>() != null); - throw new NotImplementedException(); - } - } - - Identifier IAuthenticationRequest.ClaimedIdentifier { - get { - throw new NotImplementedException(); - } - } - - bool IAuthenticationRequest.IsDirectedIdentity { - get { throw new NotImplementedException(); } - } - - bool IAuthenticationRequest.IsExtensionOnly { - get { - throw new NotImplementedException(); - } - - set { - throw new NotImplementedException(); - } - } - - IProviderEndpoint IAuthenticationRequest.Provider { - get { - Contract.Ensures(Contract.Result<IProviderEndpoint>() != null); - throw new NotImplementedException(); - } - } - - IdentifierDiscoveryResult IAuthenticationRequest.DiscoveryResult { - get { - Contract.Ensures(Contract.Result<IdentifierDiscoveryResult>() != null); - throw new NotImplementedException(); - } - } - - void IAuthenticationRequest.AddCallbackArguments(IDictionary<string, string> arguments) { - Requires.NotNull(arguments, "arguments"); - Requires.True(arguments.Keys.All(k => !string.IsNullOrEmpty(k)), "arguments"); - Requires.True(arguments.Values.All(v => v != null), "arguments"); - throw new NotImplementedException(); - } - - void IAuthenticationRequest.AddCallbackArguments(string key, string value) { - Requires.NotNullOrEmpty(key, "key"); - Requires.NotNull(value, "value"); - throw new NotImplementedException(); - } - - void IAuthenticationRequest.SetCallbackArgument(string key, string value) { - Requires.NotNullOrEmpty(key, "key"); - Requires.NotNull(value, "value"); - throw new NotImplementedException(); - } - - void IAuthenticationRequest.AddExtension(IOpenIdMessageExtension extension) { - Requires.NotNull(extension, "extension"); - throw new NotImplementedException(); - } - - void IAuthenticationRequest.RedirectToProvider() { - throw new NotImplementedException(); - } - - void IAuthenticationRequest.SetUntrustedCallbackArgument(string key, string value) { - Requires.NotNullOrEmpty(key, "key"); - Requires.NotNull(value, "value"); - throw new NotImplementedException(); - } - - #endregion - } -} diff --git a/src/DotNetOpenAuth.OpenId/OpenId/RelyingParty/IAuthenticationResponse.cs b/src/DotNetOpenAuth.OpenId/OpenId/RelyingParty/IAuthenticationResponse.cs index 10e99e4..bfdc65d 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/RelyingParty/IAuthenticationResponse.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/RelyingParty/IAuthenticationResponse.cs @@ -8,12 +8,12 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; - using System.Diagnostics.Contracts; using System.Globalization; using System.Text; using System.Web; using DotNetOpenAuth.OpenId.Extensions; using DotNetOpenAuth.OpenId.Messages; + using Validation; /// <summary> /// An instance of this interface represents an identity assertion @@ -26,7 +26,6 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { /// assertions. This interface does not offer a way to discern between /// solicited and unsolicited assertions as they should be treated equally. /// </remarks> - [ContractClass(typeof(IAuthenticationResponseContract))] public interface IAuthenticationResponse { /// <summary> /// Gets the Identifier that the end user claims to own. For use with user database storage and lookup. @@ -254,277 +253,4 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { /// </remarks> IOpenIdMessageExtension GetUntrustedExtension(Type extensionType); } - - /// <summary> - /// Code contract for the <see cref="IAuthenticationResponse"/> type. - /// </summary> - [ContractClassFor(typeof(IAuthenticationResponse))] - internal abstract class IAuthenticationResponseContract : IAuthenticationResponse { - /// <summary> - /// Initializes a new instance of the <see cref="IAuthenticationResponseContract"/> class. - /// </summary> - protected IAuthenticationResponseContract() { - } - - #region IAuthenticationResponse Members - - /// <summary> - /// Gets the Identifier that the end user claims to own. For use with user database storage and lookup. - /// May be null for some failed authentications (i.e. failed directed identity authentications). - /// </summary> - /// <value></value> - /// <remarks> - /// <para> - /// This is the secure identifier that should be used for database storage and lookup. - /// It is not always friendly (i.e. =Arnott becomes =!9B72.7DD1.50A9.5CCD), but it protects - /// user identities against spoofing and other attacks. - /// </para> - /// <para> - /// For user-friendly identifiers to display, use the - /// <see cref="IAuthenticationResponse.FriendlyIdentifierForDisplay"/> property. - /// </para> - /// </remarks> - Identifier IAuthenticationResponse.ClaimedIdentifier { - get { throw new NotImplementedException(); } - } - - /// <summary> - /// Gets a user-friendly OpenID Identifier for display purposes ONLY. - /// </summary> - /// <value></value> - /// <remarks> - /// <para> - /// This <i>should</i> be put through <see cref="HttpUtility.HtmlEncode(string)"/> before - /// sending to a browser to secure against javascript injection attacks. - /// </para> - /// <para> - /// This property retains some aspects of the user-supplied identifier that get lost - /// in the <see cref="IAuthenticationResponse.ClaimedIdentifier"/>. For example, XRIs used as user-supplied - /// identifiers (i.e. =Arnott) become unfriendly unique strings (i.e. =!9B72.7DD1.50A9.5CCD). - /// For display purposes, such as text on a web page that says "You're logged in as ...", - /// this property serves to provide the =Arnott string, or whatever else is the most friendly - /// string close to what the user originally typed in. - /// </para> - /// <para> - /// If the user-supplied identifier is a URI, this property will be the URI after all - /// redirects, and with the protocol and fragment trimmed off. - /// If the user-supplied identifier is an XRI, this property will be the original XRI. - /// If the user-supplied identifier is an OpenID Provider identifier (i.e. yahoo.com), - /// this property will be the Claimed Identifier, with the protocol stripped if it is a URI. - /// </para> - /// <para> - /// It is <b>very</b> important that this property <i>never</i> be used for database storage - /// or lookup to avoid identity spoofing and other security risks. For database storage - /// and lookup please use the <see cref="IAuthenticationResponse.ClaimedIdentifier"/> property. - /// </para> - /// </remarks> - string IAuthenticationResponse.FriendlyIdentifierForDisplay { - get { throw new NotImplementedException(); } - } - - /// <summary> - /// Gets the detailed success or failure status of the authentication attempt. - /// </summary> - /// <value></value> - AuthenticationStatus IAuthenticationResponse.Status { - get { throw new NotImplementedException(); } - } - - /// <summary> - /// Gets information about the OpenId Provider, as advertised by the - /// OpenID discovery documents found at the <see cref="IAuthenticationResponse.ClaimedIdentifier"/> - /// location, if available. - /// </summary> - /// <value> - /// The Provider endpoint that issued the positive assertion; - /// or <c>null</c> if information about the Provider is unavailable. - /// </value> - IProviderEndpoint IAuthenticationResponse.Provider { - get { throw new NotImplementedException(); } - } - - /// <summary> - /// Gets the details regarding a failed authentication attempt, if available. - /// This will be set if and only if <see cref="IAuthenticationResponse.Status"/> is <see cref="AuthenticationStatus.Failed"/>. - /// </summary> - /// <value></value> - Exception IAuthenticationResponse.Exception { - get { throw new NotImplementedException(); } - } - - /// <summary> - /// Gets a callback argument's value that was previously added using - /// <see cref="IAuthenticationRequest.AddCallbackArguments(string, string)"/>. - /// </summary> - /// <param name="key">The name of the parameter whose value is sought.</param> - /// <returns> - /// The value of the argument, or null if the named parameter could not be found. - /// </returns> - /// <remarks> - /// <para>This may return any argument on the querystring that came with the authentication response, - /// which may include parameters not explicitly added using - /// <see cref="IAuthenticationRequest.AddCallbackArguments(string, string)"/>.</para> - /// <para>Note that these values are NOT protected against tampering in transit.</para> - /// </remarks> - string IAuthenticationResponse.GetCallbackArgument(string key) { - Requires.NotNullOrEmpty(key, "key"); - throw new NotImplementedException(); - } - - /// <summary> - /// Gets all the callback arguments that were previously added using - /// <see cref="IAuthenticationRequest.AddCallbackArguments(string, string)"/> or as a natural part - /// of the return_to URL. - /// </summary> - /// <returns>A name-value dictionary. Never null.</returns> - /// <remarks> - /// <para>This MAY return any argument on the querystring that came with the authentication response, - /// which may include parameters not explicitly added using - /// <see cref="IAuthenticationRequest.AddCallbackArguments(string, string)"/>.</para> - /// <para>Note that these values are NOT protected against tampering in transit.</para> - /// </remarks> - IDictionary<string, string> IAuthenticationResponse.GetCallbackArguments() { - throw new NotImplementedException(); - } - - /// <summary> - /// Tries to get an OpenID extension that may be present in the response. - /// </summary> - /// <typeparam name="T">The type of extension to look for in the response message.</typeparam> - /// <returns> - /// The extension, if it is found. Null otherwise. - /// </returns> - /// <remarks> - /// <para>Extensions are returned only if the Provider signed them. - /// Relying parties that do not care if the values were modified in - /// transit should use the <see cref="IAuthenticationResponse.GetUntrustedExtension<T>"/> method - /// in order to allow the Provider to not sign the extension. </para> - /// <para>Unsigned extensions are completely unreliable and should be - /// used only to prefill user forms since the user or any other third - /// party may have tampered with the data carried by the extension.</para> - /// <para>Signed extensions are only reliable if the relying party - /// trusts the OpenID Provider that signed them. Signing does not mean - /// the relying party can trust the values -- it only means that the values - /// have not been tampered with since the Provider sent the message.</para> - /// </remarks> - T IAuthenticationResponse.GetExtension<T>() { - throw new NotImplementedException(); - } - - /// <summary> - /// Tries to get an OpenID extension that may be present in the response. - /// </summary> - /// <param name="extensionType">Type of the extension to look for in the response.</param> - /// <returns> - /// The extension, if it is found. Null otherwise. - /// </returns> - /// <remarks> - /// <para>Extensions are returned only if the Provider signed them. - /// Relying parties that do not care if the values were modified in - /// transit should use the <see cref="IAuthenticationResponse.GetUntrustedExtension"/> method - /// in order to allow the Provider to not sign the extension. </para> - /// <para>Unsigned extensions are completely unreliable and should be - /// used only to prefill user forms since the user or any other third - /// party may have tampered with the data carried by the extension.</para> - /// <para>Signed extensions are only reliable if the relying party - /// trusts the OpenID Provider that signed them. Signing does not mean - /// the relying party can trust the values -- it only means that the values - /// have not been tampered with since the Provider sent the message.</para> - /// </remarks> - IOpenIdMessageExtension IAuthenticationResponse.GetExtension(Type extensionType) { - Requires.NotNullSubtype<IOpenIdMessageExtension>(extensionType, "extensionType"); - ////ErrorUtilities.VerifyArgument(typeof(IOpenIdMessageExtension).IsAssignableFrom(extensionType), string.Format(CultureInfo.CurrentCulture, OpenIdStrings.TypeMustImplementX, typeof(IOpenIdMessageExtension).FullName)); - throw new NotImplementedException(); - } - - /// <summary> - /// Tries to get an OpenID extension that may be present in the response, without - /// requiring it to be signed by the Provider. - /// </summary> - /// <typeparam name="T">The type of extension to look for in the response message.</typeparam> - /// <returns> - /// The extension, if it is found. Null otherwise. - /// </returns> - /// <remarks> - /// <para>Extensions are returned whether they are signed or not. - /// Use the <see cref="IAuthenticationResponse.GetExtension<T>"/> method to retrieve - /// extension responses only if they are signed by the Provider to - /// protect against tampering. </para> - /// <para>Unsigned extensions are completely unreliable and should be - /// used only to prefill user forms since the user or any other third - /// party may have tampered with the data carried by the extension.</para> - /// <para>Signed extensions are only reliable if the relying party - /// trusts the OpenID Provider that signed them. Signing does not mean - /// the relying party can trust the values -- it only means that the values - /// have not been tampered with since the Provider sent the message.</para> - /// </remarks> - T IAuthenticationResponse.GetUntrustedExtension<T>() { - throw new NotImplementedException(); - } - - /// <summary> - /// Tries to get an OpenID extension that may be present in the response, without - /// requiring it to be signed by the Provider. - /// </summary> - /// <param name="extensionType">Type of the extension to look for in the response.</param> - /// <returns> - /// The extension, if it is found. Null otherwise. - /// </returns> - /// <remarks> - /// <para>Extensions are returned whether they are signed or not. - /// Use the <see cref="IAuthenticationResponse.GetExtension"/> method to retrieve - /// extension responses only if they are signed by the Provider to - /// protect against tampering. </para> - /// <para>Unsigned extensions are completely unreliable and should be - /// used only to prefill user forms since the user or any other third - /// party may have tampered with the data carried by the extension.</para> - /// <para>Signed extensions are only reliable if the relying party - /// trusts the OpenID Provider that signed them. Signing does not mean - /// the relying party can trust the values -- it only means that the values - /// have not been tampered with since the Provider sent the message.</para> - /// </remarks> - IOpenIdMessageExtension IAuthenticationResponse.GetUntrustedExtension(Type extensionType) { - Requires.NotNullSubtype<IOpenIdMessageExtension>(extensionType, "extensionType"); - ////ErrorUtilities.VerifyArgument(typeof(IOpenIdMessageExtension).IsAssignableFrom(extensionType), string.Format(CultureInfo.CurrentCulture, OpenIdStrings.TypeMustImplementX, typeof(IOpenIdMessageExtension).FullName)); - throw new NotImplementedException(); - } - - /// <summary> - /// Gets a callback argument's value that was previously added using - /// <see cref="IAuthenticationRequest.AddCallbackArguments(string, string)"/>. - /// </summary> - /// <param name="key">The name of the parameter whose value is sought.</param> - /// <returns> - /// The value of the argument, or null if the named parameter could not be found. - /// </returns> - /// <remarks> - /// Callback parameters are only available even if the RP is in stateless mode, - /// or the callback parameters are otherwise unverifiable as untampered with. - /// Therefore, use this method only when the callback argument is not to be - /// used to make a security-sensitive decision. - /// </remarks> - string IAuthenticationResponse.GetUntrustedCallbackArgument(string key) { - Requires.NotNullOrEmpty(key, "key"); - throw new NotImplementedException(); - } - - /// <summary> - /// Gets all the callback arguments that were previously added using - /// <see cref="IAuthenticationRequest.AddCallbackArguments(string, string)"/> or as a natural part - /// of the return_to URL. - /// </summary> - /// <returns>A name-value dictionary. Never null.</returns> - /// <remarks> - /// Callback parameters are only available even if the RP is in stateless mode, - /// or the callback parameters are otherwise unverifiable as untampered with. - /// Therefore, use this method only when the callback argument is not to be - /// used to make a security-sensitive decision. - /// </remarks> - IDictionary<string, string> IAuthenticationResponse.GetUntrustedCallbackArguments() { - Contract.Ensures(Contract.Result<IDictionary<string, string>>() != null); - throw new NotImplementedException(); - } - - #endregion - } } diff --git a/src/DotNetOpenAuth.OpenId/OpenId/RelyingParty/IRelyingPartyBehavior.cs b/src/DotNetOpenAuth.OpenId/OpenId/RelyingParty/IRelyingPartyBehavior.cs index 0113f62..b056fcd 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/RelyingParty/IRelyingPartyBehavior.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/RelyingParty/IRelyingPartyBehavior.cs @@ -6,12 +6,11 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { using System; - using System.Diagnostics.Contracts; + using Validation; /// <summary> /// Applies a custom security policy to certain OpenID security settings and behaviors. /// </summary> - [ContractClass(typeof(IRelyingPartyBehaviorContract))] public interface IRelyingPartyBehavior { /// <summary> /// Applies a well known set of security requirements to a default set of security settings. @@ -40,53 +39,4 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { /// <param name="assertion">The positive assertion.</param> void OnIncomingPositiveAssertion(IAuthenticationResponse assertion); } - - /// <summary> - /// Contract class for the <see cref="IRelyingPartyBehavior"/> interface. - /// </summary> - [ContractClassFor(typeof(IRelyingPartyBehavior))] - internal abstract class IRelyingPartyBehaviorContract : IRelyingPartyBehavior { - /// <summary> - /// Prevents a default instance of the <see cref="IRelyingPartyBehaviorContract"/> class from being created. - /// </summary> - private IRelyingPartyBehaviorContract() { - } - - #region IRelyingPartyBehavior Members - - /// <summary> - /// Applies a well known set of security requirements to a default set of security settings. - /// </summary> - /// <param name="securitySettings">The security settings to enhance with the requirements of this profile.</param> - /// <remarks> - /// Care should be taken to never decrease security when applying a profile. - /// Profiles should only enhance security requirements to avoid being - /// incompatible with each other. - /// </remarks> - void IRelyingPartyBehavior.ApplySecuritySettings(RelyingPartySecuritySettings securitySettings) { - Requires.NotNull(securitySettings, "securitySettings"); - } - - /// <summary> - /// Called when an authentication request is about to be sent. - /// </summary> - /// <param name="request">The request.</param> - /// <remarks> - /// Implementations should be prepared to be called multiple times on the same outgoing message - /// without malfunctioning. - /// </remarks> - void IRelyingPartyBehavior.OnOutgoingAuthenticationRequest(IAuthenticationRequest request) { - Requires.NotNull(request, "request"); - } - - /// <summary> - /// Called when an incoming positive assertion is received. - /// </summary> - /// <param name="assertion">The positive assertion.</param> - void IRelyingPartyBehavior.OnIncomingPositiveAssertion(IAuthenticationResponse assertion) { - Requires.NotNull(assertion, "assertion"); - } - - #endregion - } } diff --git a/src/DotNetOpenAuth.OpenId/OpenId/RelyingParty/RelyingPartySecuritySettings.cs b/src/DotNetOpenAuth.OpenId/OpenId/RelyingParty/RelyingPartySecuritySettings.cs index 77ccbca..e866f24 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/RelyingParty/RelyingPartySecuritySettings.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/RelyingParty/RelyingPartySecuritySettings.cs @@ -9,7 +9,6 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics.CodeAnalysis; - using System.Diagnostics.Contracts; using System.Linq; using DotNetOpenAuth.Messaging; diff --git a/src/DotNetOpenAuth.OpenId/OpenId/RelyingPartyEndpointDescription.cs b/src/DotNetOpenAuth.OpenId/OpenId/RelyingPartyEndpointDescription.cs index f0d3b6a..d7ebd3a 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/RelyingPartyEndpointDescription.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/RelyingPartyEndpointDescription.cs @@ -8,10 +8,10 @@ namespace DotNetOpenAuth.OpenId { using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; - using System.Diagnostics.Contracts; using System.Linq; using System.Text; using DotNetOpenAuth.Messaging; + using Validation; /// <summary> /// A description of some OpenID Relying Party endpoint. diff --git a/src/DotNetOpenAuth.OpenId/OpenId/SecuritySettings.cs b/src/DotNetOpenAuth.OpenId/OpenId/SecuritySettings.cs index 2035c9f..589f470 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/SecuritySettings.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/SecuritySettings.cs @@ -8,8 +8,8 @@ namespace DotNetOpenAuth.OpenId { using System; using System.Collections.Generic; using System.Collections.Specialized; - using System.Diagnostics.Contracts; using DotNetOpenAuth.Messaging; + using Validation; /// <summary> /// Security settings that may be applicable to both relying parties and providers. diff --git a/src/DotNetOpenAuth.OpenId/OpenId/UriIdentifier.cs b/src/DotNetOpenAuth.OpenId/OpenId/UriIdentifier.cs index 631eab6..b9f6ebc 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/UriIdentifier.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/UriIdentifier.cs @@ -19,6 +19,7 @@ namespace DotNetOpenAuth.OpenId { using DotNetOpenAuth.Messaging; using DotNetOpenAuth.Xrds; using DotNetOpenAuth.Yadis; + using Validation; /// <summary> /// A URI style of OpenID Identifier. @@ -480,7 +481,6 @@ namespace DotNetOpenAuth.OpenId { /// <returns>The non-compressing equivalent scheme or URL for the given value.</returns> private static string NormalSchemeToSpecialRoundTrippingScheme(string normal) { Requires.NotNullOrEmpty(normal, "normal"); - Contract.Ensures(!string.IsNullOrEmpty(Contract.Result<string>())); ErrorUtilities.VerifyInternal(schemeSubstitution, "Wrong schemeSubstitution value."); int delimiterIndex = normal.IndexOf(Uri.SchemeDelimiter, StringComparison.Ordinal); @@ -564,14 +564,14 @@ namespace DotNetOpenAuth.OpenId { // Get the Path out ourselves, since the default Uri parser compresses it too much for OpenID. int schemeLength = value.IndexOf(Uri.SchemeDelimiter, StringComparison.Ordinal); - Contract.Assume(schemeLength > 0); + Assumes.True(schemeLength > 0); int hostStart = schemeLength + Uri.SchemeDelimiter.Length; int hostFinish = value.IndexOf('/', hostStart); if (hostFinish < 0) { this.Path = "/"; } else { int pathFinish = value.IndexOfAny(PathEndingCharacters, hostFinish); - Contract.Assume(pathFinish >= hostFinish || pathFinish < 0); + Assumes.True(pathFinish >= hostFinish || pathFinish < 0); if (pathFinish < 0) { this.Path = value.Substring(hostFinish); } else { diff --git a/src/DotNetOpenAuth.OpenId/OpenId/XriDiscoveryProxyService.cs b/src/DotNetOpenAuth.OpenId/OpenId/XriDiscoveryProxyService.cs index 3189a5d..a3e8345 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/XriDiscoveryProxyService.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/XriDiscoveryProxyService.cs @@ -8,7 +8,6 @@ namespace DotNetOpenAuth.OpenId { using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; - using System.Diagnostics.Contracts; using System.Globalization; using System.Linq; using System.Text; @@ -18,6 +17,7 @@ namespace DotNetOpenAuth.OpenId { using DotNetOpenAuth.OpenId.RelyingParty; using DotNetOpenAuth.Xrds; using DotNetOpenAuth.Yadis; + using Validation; /// <summary> /// The discovery service for XRI identifiers that uses an XRI proxy resolver for discovery. @@ -74,7 +74,6 @@ namespace DotNetOpenAuth.OpenId { private static XrdsDocument DownloadXrds(XriIdentifier identifier, IDirectWebRequestHandler requestHandler) { Requires.NotNull(identifier, "identifier"); Requires.NotNull(requestHandler, "requestHandler"); - Contract.Ensures(Contract.Result<XrdsDocument>() != null); XrdsDocument doc; using (var xrdsResponse = Yadis.Request(requestHandler, GetXrdsUrl(identifier), identifier.IsDiscoverySecureEndToEnd)) { var readerSettings = MessagingUtilities.CreateUntrustedXmlReaderSettings(); diff --git a/src/DotNetOpenAuth.OpenId/OpenId/XriIdentifier.cs b/src/DotNetOpenAuth.OpenId/OpenId/XriIdentifier.cs index f6a633f..4222726 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/XriIdentifier.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/XriIdentifier.cs @@ -15,12 +15,12 @@ namespace DotNetOpenAuth.OpenId { using DotNetOpenAuth.Messaging; using DotNetOpenAuth.Xrds; using DotNetOpenAuth.Yadis; + using Validation; /// <summary> /// An XRI style of OpenID Identifier. /// </summary> [Serializable] - [ContractVerification(true)] [Pure] public sealed class XriIdentifier : Identifier { /// <summary> @@ -45,7 +45,7 @@ namespace DotNetOpenAuth.OpenId { internal XriIdentifier(string xri) : this(xri, false) { Requires.NotNullOrEmpty(xri, "xri"); - Requires.Format(IsValidXri(xri), OpenIdStrings.InvalidXri); + RequiresEx.Format(IsValidXri(xri), OpenIdStrings.InvalidXri); } /// <summary> @@ -59,8 +59,8 @@ namespace DotNetOpenAuth.OpenId { internal XriIdentifier(string xri, bool requireSsl) : base(xri, requireSsl) { Requires.NotNullOrEmpty(xri, "xri"); - Requires.Format(IsValidXri(xri), OpenIdStrings.InvalidXri); - Contract.Assume(xri != null); // Proven by IsValidXri + RequiresEx.Format(IsValidXri(xri), OpenIdStrings.InvalidXri); + Assumes.True(xri != null); // Proven by IsValidXri this.OriginalXri = xri; this.canonicalXri = CanonicalizeXri(xri); } @@ -75,7 +75,6 @@ namespace DotNetOpenAuth.OpenId { /// </summary> internal string CanonicalXri { get { - Contract.Ensures(Contract.Result<string>() != null); return this.canonicalXri; } } @@ -169,7 +168,6 @@ namespace DotNetOpenAuth.OpenId { /// True if the secure conversion was successful. /// False if the Identifier was originally created with an explicit HTTP scheme. /// </returns> - [ContractVerification(false)] // bugs/limitations in CC static analysis internal override bool TryRequireSsl(out Identifier secureIdentifier) { secureIdentifier = IsDiscoverySecureEndToEnd ? this : new XriIdentifier(this, true); return true; @@ -183,10 +181,9 @@ namespace DotNetOpenAuth.OpenId { /// <remarks>The canonical form, per the OpenID spec, is no scheme and no whitespace on either end.</remarks> private static string CanonicalizeXri(string xri) { Requires.NotNull(xri, "xri"); - Contract.Ensures(Contract.Result<string>() != null); xri = xri.Trim(); if (xri.StartsWith(XriScheme, StringComparison.OrdinalIgnoreCase)) { - Contract.Assume(XriScheme.Length <= xri.Length); // should be implied by StartsWith + Assumes.True(XriScheme.Length <= xri.Length); // should be implied by StartsWith xri = xri.Substring(XriScheme.Length); } return xri; diff --git a/src/DotNetOpenAuth.OpenId/OpenIdXrdsHelperRelyingParty.cs b/src/DotNetOpenAuth.OpenId/OpenIdXrdsHelperRelyingParty.cs index 4e3221f..885370c 100644 --- a/src/DotNetOpenAuth.OpenId/OpenIdXrdsHelperRelyingParty.cs +++ b/src/DotNetOpenAuth.OpenId/OpenIdXrdsHelperRelyingParty.cs @@ -7,11 +7,11 @@ namespace DotNetOpenAuth.OpenId { using System; using System.Collections.Generic; - using System.Diagnostics.Contracts; using System.Linq; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OpenId.RelyingParty; using DotNetOpenAuth.Xrds; + using Validation; /// <summary> /// Adds OpenID-specific extension methods to the XrdsDocument class. @@ -31,7 +31,6 @@ namespace DotNetOpenAuth.OpenId { Requires.NotNull(xrds, "xrds"); Requires.NotNull(claimedIdentifier, "claimedIdentifier"); Requires.NotNull(userSuppliedIdentifier, "userSuppliedIdentifier"); - Contract.Ensures(Contract.Result<IEnumerable<IdentifierDiscoveryResult>>() != null); var endpoints = new List<IdentifierDiscoveryResult>(); endpoints.AddRange(xrds.GenerateOPIdentifierServiceEndpoints(userSuppliedIdentifier)); @@ -52,7 +51,6 @@ namespace DotNetOpenAuth.OpenId { internal static IEnumerable<IdentifierDiscoveryResult> CreateServiceEndpoints(this IEnumerable<XrdElement> xrds, XriIdentifier userSuppliedIdentifier) { Requires.NotNull(xrds, "xrds"); Requires.NotNull(userSuppliedIdentifier, "userSuppliedIdentifier"); - Contract.Ensures(Contract.Result<IEnumerable<IdentifierDiscoveryResult>>() != null); var endpoints = new List<IdentifierDiscoveryResult>(); endpoints.AddRange(xrds.GenerateOPIdentifierServiceEndpoints(userSuppliedIdentifier)); @@ -71,7 +69,6 @@ namespace DotNetOpenAuth.OpenId { private static IEnumerable<IdentifierDiscoveryResult> GenerateOPIdentifierServiceEndpoints(this IEnumerable<XrdElement> xrds, Identifier opIdentifier) { Requires.NotNull(xrds, "xrds"); Requires.NotNull(opIdentifier, "opIdentifier"); - Contract.Ensures(Contract.Result<IEnumerable<IdentifierDiscoveryResult>>() != null); return from service in xrds.FindOPIdentifierServices() from uri in service.UriElements let protocol = Protocol.FindBestVersion(p => p.OPIdentifierServiceTypeURI, service.TypeElementUris) @@ -92,7 +89,6 @@ namespace DotNetOpenAuth.OpenId { private static IEnumerable<IdentifierDiscoveryResult> GenerateClaimedIdentifierServiceEndpoints(this IEnumerable<XrdElement> xrds, UriIdentifier claimedIdentifier, UriIdentifier userSuppliedIdentifier) { Requires.NotNull(xrds, "xrds"); Requires.NotNull(claimedIdentifier, "claimedIdentifier"); - Contract.Ensures(Contract.Result<IEnumerable<IdentifierDiscoveryResult>>() != null); return from service in xrds.FindClaimedIdentifierServices() from uri in service.UriElements @@ -111,8 +107,7 @@ namespace DotNetOpenAuth.OpenId { private static IEnumerable<IdentifierDiscoveryResult> GenerateClaimedIdentifierServiceEndpoints(this IEnumerable<XrdElement> xrds, XriIdentifier userSuppliedIdentifier) { // Cannot use code contracts because this method uses yield return. ////Requires.NotNull(xrds, "xrds"); - ////Contract.Ensures(Contract.Result<IEnumerable<IdentifierDiscoveryResult>>() != null); - ErrorUtilities.VerifyArgumentNotNull(xrds, "xrds"); + //// ErrorUtilities.VerifyArgumentNotNull(xrds, "xrds"); foreach (var service in xrds.FindClaimedIdentifierServices()) { foreach (var uri in service.UriElements) { @@ -138,7 +133,6 @@ namespace DotNetOpenAuth.OpenId { /// <returns>A sequence of service elements.</returns> private static IEnumerable<ServiceElement> FindOPIdentifierServices(this IEnumerable<XrdElement> xrds) { Requires.NotNull(xrds, "xrds"); - Contract.Ensures(Contract.Result<IEnumerable<ServiceElement>>() != null); return from xrd in xrds from service in xrd.OpenIdProviderIdentifierServices @@ -153,7 +147,6 @@ namespace DotNetOpenAuth.OpenId { /// <returns>A sequence of the services offered.</returns> private static IEnumerable<ServiceElement> FindClaimedIdentifierServices(this IEnumerable<XrdElement> xrds) { Requires.NotNull(xrds, "xrds"); - Contract.Ensures(Contract.Result<IEnumerable<ServiceElement>>() != null); return from xrd in xrds from service in xrd.OpenIdClaimedIdentifierServices diff --git a/src/DotNetOpenAuth.OpenId/Properties/AssemblyInfo.cs b/src/DotNetOpenAuth.OpenId/Properties/AssemblyInfo.cs index 42aa959..ac795f5 100644 --- a/src/DotNetOpenAuth.OpenId/Properties/AssemblyInfo.cs +++ b/src/DotNetOpenAuth.OpenId/Properties/AssemblyInfo.cs @@ -7,7 +7,6 @@ // We DON'T put an AssemblyVersionAttribute in here because it is generated in the build. using System; -using System.Diagnostics.Contracts; using System.Net; using System.Reflection; using System.Resources; @@ -31,8 +30,6 @@ using System.Web.UI; // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("7d73990c-47c0-4256-9f20-a893add9e289")] -[assembly: ContractVerification(true)] - #if StrongNameSigned // See comment at top of this file. We need this so that strong-naming doesn't // keep this assembly from being useful to shared host (medium trust) web sites. diff --git a/src/DotNetOpenAuth.OpenId/Xrds/TypeElement.cs b/src/DotNetOpenAuth.OpenId/Xrds/TypeElement.cs index 717dfee..97f7ded 100644 --- a/src/DotNetOpenAuth.OpenId/Xrds/TypeElement.cs +++ b/src/DotNetOpenAuth.OpenId/Xrds/TypeElement.cs @@ -6,8 +6,8 @@ namespace DotNetOpenAuth.Xrds { using System; - using System.Diagnostics.Contracts; using System.Xml.XPath; + using Validation; /// <summary> /// The Type element in an XRDS document. diff --git a/src/DotNetOpenAuth.OpenId/Xrds/XrdsNode.cs b/src/DotNetOpenAuth.OpenId/Xrds/XrdsNode.cs index 3e163f7..91c59ba 100644 --- a/src/DotNetOpenAuth.OpenId/Xrds/XrdsNode.cs +++ b/src/DotNetOpenAuth.OpenId/Xrds/XrdsNode.cs @@ -6,10 +6,10 @@ namespace DotNetOpenAuth.Xrds { using System; - using System.Diagnostics.Contracts; using System.Xml; using System.Xml.XPath; using DotNetOpenAuth.Messaging; + using Validation; /// <summary> /// A node in an XRDS document. @@ -45,7 +45,7 @@ namespace DotNetOpenAuth.Xrds { /// <param name="document">The document's root node, which this instance represents.</param> protected XrdsNode(XPathNavigator document) { Requires.NotNull(document, "document"); - Requires.True(document.NameTable != null, null); + Requires.That(document.NameTable != null, "document", "requires document.NameTable != null"); this.Node = document; this.XmlNamespaceResolver = new XmlNamespaceManager(document.NameTable); diff --git a/src/DotNetOpenAuth.OpenId/Yadis/HtmlParser.cs b/src/DotNetOpenAuth.OpenId/Yadis/HtmlParser.cs index 481d6a7..36b7bf1 100644 --- a/src/DotNetOpenAuth.OpenId/Yadis/HtmlParser.cs +++ b/src/DotNetOpenAuth.OpenId/Yadis/HtmlParser.cs @@ -7,13 +7,13 @@ namespace DotNetOpenAuth.Yadis { using System; using System.Collections.Generic; - using System.Diagnostics.Contracts; using System.Globalization; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Web; using System.Web.UI.HtmlControls; + using Validation; /// <summary> /// An HTML HEAD tag parser. diff --git a/src/DotNetOpenAuth.OpenId/Yadis/Yadis.cs b/src/DotNetOpenAuth.OpenId/Yadis/Yadis.cs index a23e019..4a06ea7 100644 --- a/src/DotNetOpenAuth.OpenId/Yadis/Yadis.cs +++ b/src/DotNetOpenAuth.OpenId/Yadis/Yadis.cs @@ -6,7 +6,6 @@ namespace DotNetOpenAuth.Yadis { using System; - using System.Diagnostics.Contracts; using System.IO; using System.Net; using System.Net.Cache; @@ -16,6 +15,7 @@ namespace DotNetOpenAuth.Yadis { using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OpenId; using DotNetOpenAuth.Xrds; + using Validation; /// <summary> /// YADIS discovery manager. @@ -137,8 +137,6 @@ namespace DotNetOpenAuth.Yadis { internal static IncomingWebResponse Request(IDirectWebRequestHandler requestHandler, Uri uri, bool requireSsl, params string[] acceptTypes) { Requires.NotNull(requestHandler, "requestHandler"); Requires.NotNull(uri, "uri"); - Contract.Ensures(Contract.Result<IncomingWebResponse>() != null); - Contract.Ensures(Contract.Result<IncomingWebResponse>().ResponseStream != null); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); request.CachePolicy = IdentifierDiscoveryCachePolicy; diff --git a/src/DotNetOpenAuth.OpenId/packages.config b/src/DotNetOpenAuth.OpenId/packages.config new file mode 100644 index 0000000..70866e7 --- /dev/null +++ b/src/DotNetOpenAuth.OpenId/packages.config @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="Validation" version="2.0.1.12362" targetFramework="net40" /> +</packages>
\ No newline at end of file |