diff options
Diffstat (limited to 'src/DotNetOpenAuth.InfoCard')
7 files changed, 23 insertions, 21 deletions
diff --git a/src/DotNetOpenAuth.InfoCard/DotNetOpenAuth.InfoCard.csproj b/src/DotNetOpenAuth.InfoCard/DotNetOpenAuth.InfoCard.csproj index 09371f1..ee0899b 100644 --- a/src/DotNetOpenAuth.InfoCard/DotNetOpenAuth.InfoCard.csproj +++ b/src/DotNetOpenAuth.InfoCard/DotNetOpenAuth.InfoCard.csproj @@ -46,6 +46,15 @@ <Name>DotNetOpenAuth.Core</Name> </ProjectReference> </ItemGroup> + <ItemGroup> + <Reference Include="Validation, Version=2.0.0.0, Culture=neutral, PublicKeyToken=2fc06f0d701809a7, processorArchitecture=MSIL"> + <SpecificVersion>False</SpecificVersion> + <HintPath>..\packages\Validation.2.0.0.12319\lib\portable-windows8+net40+sl5+windowsphone8\Validation.dll</HintPath> + </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))' != '' " /> diff --git a/src/DotNetOpenAuth.InfoCard/InfoCard/Token/Token.cs b/src/DotNetOpenAuth.InfoCard/InfoCard/Token/Token.cs index 0660ec7..2ac1788 100644 --- a/src/DotNetOpenAuth.InfoCard/InfoCard/Token/Token.cs +++ b/src/DotNetOpenAuth.InfoCard/InfoCard/Token/Token.cs @@ -18,11 +18,11 @@ namespace DotNetOpenAuth.InfoCard { using System.Xml; using System.Xml.XPath; using DotNetOpenAuth.Messaging; + using Validation; /// <summary> /// The decrypted token that was submitted as an Information Card. /// </summary> - [ContractVerification(true)] public class Token { /// <summary> /// Backing field for the <see cref="Claims"/> property. @@ -44,8 +44,7 @@ namespace DotNetOpenAuth.InfoCard { [SuppressMessage("Microsoft.Usage", "CA2202:Do not dispose objects multiple times", Justification = "Not a problem for this type."), SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "False positive")] private Token(string tokenXml, Uri audience, TokenDecryptor decryptor) { Requires.NotNullOrEmpty(tokenXml, "tokenXml"); - Requires.True(decryptor != null || !IsEncrypted(tokenXml), null); - Contract.Ensures(this.AuthorizationContext != null); + Requires.That(decryptor != null || !IsEncrypted(tokenXml), "decryptor", "Required when tokenXml is encrypted."); byte[] decryptedBytes; string decryptedString; @@ -53,12 +52,12 @@ namespace DotNetOpenAuth.InfoCard { using (StringReader xmlReader = new StringReader(tokenXml)) { var readerSettings = MessagingUtilities.CreateUntrustedXmlReaderSettings(); using (XmlReader tokenReader = XmlReader.Create(xmlReader, readerSettings)) { - Contract.Assume(tokenReader != null); // BCL contract should say XmlReader.Create result != null + Assumes.True(tokenReader != null); // BCL contract should say XmlReader.Create result != null if (IsEncrypted(tokenReader)) { Logger.InfoCard.DebugFormat("Incoming SAML token, before decryption: {0}", tokenXml); decryptedBytes = decryptor.DecryptToken(tokenReader); decryptedString = Encoding.UTF8.GetString(decryptedBytes); - Contract.Assume(decryptedString != null); // BCL contracts should be enhanced here + Assumes.True(decryptedString != null); // BCL contracts should be enhanced here } else { decryptedBytes = Encoding.UTF8.GetBytes(tokenXml); decryptedString = tokenXml; @@ -118,7 +117,7 @@ namespace DotNetOpenAuth.InfoCard { /// </summary> public string SiteSpecificId { get { - Requires.ValidState(this.Claims.ContainsKey(ClaimTypes.PPID) && !string.IsNullOrEmpty(this.Claims[ClaimTypes.PPID])); + RequiresEx.ValidState(this.Claims.ContainsKey(ClaimTypes.PPID) && !string.IsNullOrEmpty(this.Claims[ClaimTypes.PPID])); string ppidValue; ErrorUtilities.VerifyOperation(this.Claims.TryGetValue(ClaimTypes.PPID, out ppidValue) && ppidValue != null, InfoCardStrings.PpidClaimRequired); return TokenUtility.CalculateSiteSpecificID(ppidValue); @@ -181,7 +180,6 @@ namespace DotNetOpenAuth.InfoCard { public static Token Read(string tokenXml, Uri audience, IEnumerable<SecurityToken> decryptionTokens) { Requires.NotNullOrEmpty(tokenXml, "tokenXml"); Requires.NotNull(decryptionTokens, "decryptionTokens"); - Contract.Ensures(Contract.Result<Token>() != null); TokenDecryptor decryptor = null; @@ -215,7 +213,7 @@ namespace DotNetOpenAuth.InfoCard { } try { - Contract.Assume(tokenReader != null); // CC missing for XmlReader.Create + Assumes.True(tokenReader != null); // CC missing for XmlReader.Create return IsEncrypted(tokenReader); } catch { IDisposable disposableReader = tokenReader; diff --git a/src/DotNetOpenAuth.InfoCard/InfoCard/Token/TokenDecryptor.cs b/src/DotNetOpenAuth.InfoCard/InfoCard/Token/TokenDecryptor.cs index e9199c7..fab5148 100644 --- a/src/DotNetOpenAuth.InfoCard/InfoCard/Token/TokenDecryptor.cs +++ b/src/DotNetOpenAuth.InfoCard/InfoCard/Token/TokenDecryptor.cs @@ -13,7 +13,6 @@ namespace DotNetOpenAuth.InfoCard { using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; - using System.Diagnostics.Contracts; using System.IdentityModel.Selectors; using System.IdentityModel.Tokens; using System.Linq; @@ -22,6 +21,7 @@ namespace DotNetOpenAuth.InfoCard { using System.ServiceModel.Security; using System.Xml; using DotNetOpenAuth.Messaging; + using Validation; /// <summary> /// A utility class for decrypting InfoCard tokens. @@ -90,7 +90,6 @@ namespace DotNetOpenAuth.InfoCard { /// <returns>A byte array of the contents of the encrypted token</returns> internal byte[] DecryptToken(XmlReader reader) { Requires.NotNull(reader, "reader"); - Contract.Ensures(Contract.Result<byte[]>() != null); byte[] securityTokenData; string encryptionAlgorithm; diff --git a/src/DotNetOpenAuth.InfoCard/InfoCard/Token/TokenUtility.cs b/src/DotNetOpenAuth.InfoCard/InfoCard/Token/TokenUtility.cs index 8b9eef8..616cb9f 100644 --- a/src/DotNetOpenAuth.InfoCard/InfoCard/Token/TokenUtility.cs +++ b/src/DotNetOpenAuth.InfoCard/InfoCard/Token/TokenUtility.cs @@ -13,7 +13,6 @@ namespace DotNetOpenAuth.InfoCard { using System.Collections.Generic; using System.Configuration; using System.Diagnostics.CodeAnalysis; - using System.Diagnostics.Contracts; using System.IdentityModel.Claims; using System.IdentityModel.Policy; using System.IdentityModel.Selectors; @@ -27,6 +26,7 @@ namespace DotNetOpenAuth.InfoCard { using System.Text; using System.Xml; using DotNetOpenAuth.Messaging; + using Validation; /// <summary> /// Tools for reading InfoCard tokens. @@ -49,8 +49,6 @@ namespace DotNetOpenAuth.InfoCard { /// The authorization context carried by the token. /// </returns> internal static AuthorizationContext AuthenticateToken(XmlReader reader, Uri audience) { - Contract.Ensures(Contract.Result<AuthorizationContext>() != null); - // Extensibility Point: // in order to accept different token types, you would need to add additional // code to create an authenticationcontext from the security token. @@ -227,7 +225,6 @@ namespace DotNetOpenAuth.InfoCard { [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "False positive.")] internal static string CalculateSiteSpecificID(string ppid) { Requires.NotNull(ppid, "ppid"); - Contract.Ensures(!string.IsNullOrEmpty(Contract.Result<string>())); int callSignChars = 10; char[] charMap = "QL23456789ABCDEFGHJKMNPRSTUVWXYZ".ToCharArray(); @@ -281,7 +278,6 @@ namespace DotNetOpenAuth.InfoCard { private static string ComputeCombinedId(RSA issuerKey, string claimValue) { Requires.NotNull(issuerKey, "issuerKey"); Requires.NotNull(claimValue, "claimValue"); - Contract.Ensures(Contract.Result<string>() != null); int nameLength = Encoding.UTF8.GetByteCount(claimValue); RSAParameters rsaParams = issuerKey.ExportParameters(false); diff --git a/src/DotNetOpenAuth.InfoCard/InfoCardErrorUtilities.cs b/src/DotNetOpenAuth.InfoCard/InfoCardErrorUtilities.cs index cfde838..aaff82b 100644 --- a/src/DotNetOpenAuth.InfoCard/InfoCardErrorUtilities.cs +++ b/src/DotNetOpenAuth.InfoCard/InfoCardErrorUtilities.cs @@ -11,6 +11,7 @@ namespace DotNetOpenAuth { using System.Globalization; using System.Linq; using System.Text; + using Validation; /// <summary> /// Error reporting methods specific to InfoCard validation. @@ -27,9 +28,7 @@ namespace DotNetOpenAuth { [Pure] internal static void VerifyInfoCard(bool condition, string errorMessage, params object[] args) { Requires.NotNull(args, "args"); - Contract.Ensures(condition); - Contract.EnsuresOnThrow<InfoCard.InformationCardException>(!condition); - Contract.Assume(errorMessage != null); + Assumes.True(errorMessage != null); if (!condition) { errorMessage = string.Format(CultureInfo.CurrentCulture, errorMessage, args); throw new InfoCard.InformationCardException(errorMessage); diff --git a/src/DotNetOpenAuth.InfoCard/Properties/AssemblyInfo.cs b/src/DotNetOpenAuth.InfoCard/Properties/AssemblyInfo.cs index e9f2c20..1288eb4 100644 --- a/src/DotNetOpenAuth.InfoCard/Properties/AssemblyInfo.cs +++ b/src/DotNetOpenAuth.InfoCard/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.InfoCard/packages.config b/src/DotNetOpenAuth.InfoCard/packages.config new file mode 100644 index 0000000..10eec89 --- /dev/null +++ b/src/DotNetOpenAuth.InfoCard/packages.config @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="Validation" version="2.0.0.12319" targetFramework="net40" /> +</packages>
\ No newline at end of file |