summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/DotNetOpenAuth/Logger.cs4
-rw-r--r--src/DotNetOpenAuth/Messaging/EnumerableCache.cs9
-rw-r--r--src/DotNetOpenAuth/Messaging/MessagingUtilities.cs4
-rw-r--r--src/DotNetOpenAuth/Messaging/Reflection/MessageDescription.cs7
-rw-r--r--src/DotNetOpenAuth/OAuth/ChannelElements/SigningBindingElementBase.cs11
-rw-r--r--src/DotNetOpenAuth/OAuth/ChannelElements/SigningBindingElementChain.cs18
-rw-r--r--src/DotNetOpenAuth/OpenId/ChannelElements/OpenIdChannel.cs4
-rw-r--r--src/DotNetOpenAuth/OpenId/Extensions/ProviderAuthenticationPolicy/PolicyResponse.cs7
-rw-r--r--src/DotNetOpenAuth/OpenId/Extensions/SimpleRegistration/ClaimsResponse.cs5
-rw-r--r--src/DotNetOpenAuth/OpenId/Messages/RequestBase.cs8
-rw-r--r--src/DotNetOpenAuth/OpenId/Protocol.cs6
11 files changed, 20 insertions, 63 deletions
diff --git a/src/DotNetOpenAuth/Logger.cs b/src/DotNetOpenAuth/Logger.cs
index ede8172..1c1b8a5 100644
--- a/src/DotNetOpenAuth/Logger.cs
+++ b/src/DotNetOpenAuth/Logger.cs
@@ -154,9 +154,7 @@ namespace DotNetOpenAuth {
/// <param name="type">A type whose full name that will be included in the log file.</param>
/// <returns>The <see cref="ILog"/> instance created with the given type name.</returns>
internal static ILog Create(Type type) {
- if (type == null) {
- throw new ArgumentNullException("type");
- }
+ Contract.Requires<ArgumentNullException>(type != null);
return Create(type.FullName);
}
diff --git a/src/DotNetOpenAuth/Messaging/EnumerableCache.cs b/src/DotNetOpenAuth/Messaging/EnumerableCache.cs
index d343410..6639de1 100644
--- a/src/DotNetOpenAuth/Messaging/EnumerableCache.cs
+++ b/src/DotNetOpenAuth/Messaging/EnumerableCache.cs
@@ -9,6 +9,7 @@ namespace DotNetOpenAuth.Messaging {
using System;
using System.Collections;
using System.Collections.Generic;
+ using System.Diagnostics.Contracts;
/// <summary>
/// Extension methods for <see cref="IEnumerable&lt;T&gt;"/> types.
@@ -80,9 +81,7 @@ namespace DotNetOpenAuth.Messaging {
/// </summary>
/// <param name="generator">The generator.</param>
internal EnumerableCache(IEnumerable<T> generator) {
- if (generator == null) {
- throw new ArgumentNullException("generator");
- }
+ Contract.Requires<ArgumentNullException>(generator != null);
this.generator = generator;
}
@@ -140,9 +139,7 @@ namespace DotNetOpenAuth.Messaging {
/// </summary>
/// <param name="parent">The parent cached enumerable whose GetEnumerator method is calling this constructor.</param>
internal EnumeratorCache(EnumerableCache<T> parent) {
- if (parent == null) {
- throw new ArgumentNullException("parent");
- }
+ Contract.Requires<ArgumentNullException>(parent != null);
this.parent = parent;
}
diff --git a/src/DotNetOpenAuth/Messaging/MessagingUtilities.cs b/src/DotNetOpenAuth/Messaging/MessagingUtilities.cs
index 2ab628a..b1a253d 100644
--- a/src/DotNetOpenAuth/Messaging/MessagingUtilities.cs
+++ b/src/DotNetOpenAuth/Messaging/MessagingUtilities.cs
@@ -906,9 +906,7 @@ namespace DotNetOpenAuth.Messaging {
/// </summary>
/// <param name="comparison">The comparison method to use.</param>
internal ComparisonHelper(Comparison<T> comparison) {
- if (comparison == null) {
- throw new ArgumentNullException("comparison");
- }
+ Contract.Requires<ArgumentNullException>(comparison != null);
this.comparison = comparison;
}
diff --git a/src/DotNetOpenAuth/Messaging/Reflection/MessageDescription.cs b/src/DotNetOpenAuth/Messaging/Reflection/MessageDescription.cs
index f250a57..9c0cbe2 100644
--- a/src/DotNetOpenAuth/Messaging/Reflection/MessageDescription.cs
+++ b/src/DotNetOpenAuth/Messaging/Reflection/MessageDescription.cs
@@ -43,13 +43,6 @@ namespace DotNetOpenAuth.Messaging.Reflection {
Contract.Requires<ArgumentNullException>(messageType != null);
Contract.Requires<ArgumentException>(typeof(IMessage).IsAssignableFrom(messageType));
Contract.Requires<ArgumentNullException>(messageVersion != null);
- if (!typeof(IMessage).IsAssignableFrom(messageType)) {
- throw new ArgumentException(string.Format(
- CultureInfo.CurrentCulture,
- MessagingStrings.UnexpectedType,
- typeof(IMessage),
- messageType));
- }
this.messageType = messageType;
this.messageVersion = messageVersion;
diff --git a/src/DotNetOpenAuth/OAuth/ChannelElements/SigningBindingElementBase.cs b/src/DotNetOpenAuth/OAuth/ChannelElements/SigningBindingElementBase.cs
index 0fd9bf9..004e7d5 100644
--- a/src/DotNetOpenAuth/OAuth/ChannelElements/SigningBindingElementBase.cs
+++ b/src/DotNetOpenAuth/OAuth/ChannelElements/SigningBindingElementBase.cs
@@ -149,19 +149,10 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
/// </remarks>
internal static string ConstructSignatureBaseString(ITamperResistantOAuthMessage message, MessageDictionary messageDictionary) {
Contract.Requires<ArgumentNullException>(message != null);
+ Contract.Requires<ArgumentException>(!string.IsNullOrEmpty(message.HttpMethod));
Contract.Requires<ArgumentNullException>(messageDictionary != null);
Contract.Requires<ArgumentException>(messageDictionary.Message == message);
- if (String.IsNullOrEmpty(message.HttpMethod)) {
- throw new ArgumentException(
- string.Format(
- CultureInfo.CurrentCulture,
- MessagingStrings.ArgumentPropertyMissing,
- typeof(ITamperResistantOAuthMessage).Name,
- "HttpMethod"),
- "message");
- }
-
List<string> signatureBaseStringElements = new List<string>(3);
signatureBaseStringElements.Add(message.HttpMethod.ToUpperInvariant());
diff --git a/src/DotNetOpenAuth/OAuth/ChannelElements/SigningBindingElementChain.cs b/src/DotNetOpenAuth/OAuth/ChannelElements/SigningBindingElementChain.cs
index f88e7ab..bdb0219 100644
--- a/src/DotNetOpenAuth/OAuth/ChannelElements/SigningBindingElementChain.cs
+++ b/src/DotNetOpenAuth/OAuth/ChannelElements/SigningBindingElementChain.cs
@@ -7,6 +7,7 @@
namespace DotNetOpenAuth.OAuth.ChannelElements {
using System;
using System.Collections.Generic;
+ using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;
using DotNetOpenAuth.Messaging;
@@ -29,19 +30,10 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
/// in preferred use order.
/// </param>
internal SigningBindingElementChain(ITamperProtectionChannelBindingElement[] signers) {
- if (signers == null) {
- throw new ArgumentNullException("signers");
- }
- if (signers.Length == 0) {
- throw new ArgumentException(MessagingStrings.SequenceContainsNoElements, "signers");
- }
- if (signers.Contains(null)) {
- throw new ArgumentException(MessagingStrings.SequenceContainsNullElement, "signers");
- }
- MessageProtections protection = signers[0].Protection;
- if (signers.Any(element => element.Protection != protection)) {
- throw new ArgumentException(OAuthStrings.SigningElementsMustShareSameProtection, "signers");
- }
+ Contract.Requires<ArgumentNullException>(signers != null);
+ Contract.Requires<ArgumentException>(signers.Length > 0);
+ Contract.Requires<ArgumentException>(!signers.Contains(null), MessagingStrings.SequenceContainsNullElement);
+ Contract.Requires<ArgumentException>(signers.Select(s => s.Protection).Distinct().Count() == 1, OAuthStrings.SigningElementsMustShareSameProtection);
this.signers = signers;
}
diff --git a/src/DotNetOpenAuth/OpenId/ChannelElements/OpenIdChannel.cs b/src/DotNetOpenAuth/OpenId/ChannelElements/OpenIdChannel.cs
index aff535c..b25e819 100644
--- a/src/DotNetOpenAuth/OpenId/ChannelElements/OpenIdChannel.cs
+++ b/src/DotNetOpenAuth/OpenId/ChannelElements/OpenIdChannel.cs
@@ -208,10 +208,6 @@ namespace DotNetOpenAuth.OpenId.ChannelElements {
/// </returns>
/// <exception cref="ProtocolException">Thrown when the response is not valid.</exception>
protected override IDictionary<string, string> ReadFromResponseCore(IncomingWebResponse response) {
- if (response == null) {
- throw new ArgumentNullException("response");
- }
-
try {
return this.keyValueForm.GetDictionary(response.ResponseStream);
} catch (FormatException ex) {
diff --git a/src/DotNetOpenAuth/OpenId/Extensions/ProviderAuthenticationPolicy/PolicyResponse.cs b/src/DotNetOpenAuth/OpenId/Extensions/ProviderAuthenticationPolicy/PolicyResponse.cs
index b476cf7..246ec07 100644
--- a/src/DotNetOpenAuth/OpenId/Extensions/ProviderAuthenticationPolicy/PolicyResponse.cs
+++ b/src/DotNetOpenAuth/OpenId/Extensions/ProviderAuthenticationPolicy/PolicyResponse.cs
@@ -8,6 +8,7 @@ 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;
@@ -82,12 +83,10 @@ namespace DotNetOpenAuth.OpenId.Extensions.ProviderAuthenticationPolicy {
}
set {
+ Contract.Requires<ArgumentException>(!value.HasValue || value.Value.Kind != DateTimeKind.Unspecified, OpenIdStrings.UnspecifiedDateTimeKindNotAllowed);
+
// Make sure that whatever is set here, it becomes UTC time.
if (value.HasValue) {
- if (value.Value.Kind == DateTimeKind.Unspecified) {
- throw new ArgumentException(OpenIdStrings.UnspecifiedDateTimeKindNotAllowed, "value");
- }
-
// Convert to UTC and cut to the second, since the protocol only allows for
// that level of precision.
this.authenticationTimeUtc = OpenIdUtilities.CutToSecond(value.Value.ToUniversalTimeSafe());
diff --git a/src/DotNetOpenAuth/OpenId/Extensions/SimpleRegistration/ClaimsResponse.cs b/src/DotNetOpenAuth/OpenId/Extensions/SimpleRegistration/ClaimsResponse.cs
index ed99243..9079615 100644
--- a/src/DotNetOpenAuth/OpenId/Extensions/SimpleRegistration/ClaimsResponse.cs
+++ b/src/DotNetOpenAuth/OpenId/Extensions/SimpleRegistration/ClaimsResponse.cs
@@ -122,11 +122,8 @@ namespace DotNetOpenAuth.OpenId.Extensions.SimpleRegistration {
}
set {
+ Contract.Requires<ArgumentException>(value == null || birthDateValidator.IsMatch(value), OpenIdStrings.SregInvalidBirthdate);
if (value != null) {
- if (!birthDateValidator.IsMatch(value)) {
- throw new ArgumentException(OpenIdStrings.SregInvalidBirthdate, "value");
- }
-
// Update the BirthDate property, if possible.
// Don't use property accessor for peer property to avoid infinite loop between the two proeprty accessors.
// Some valid sreg dob values like "2000-00-00" will not work as a DateTime struct,
diff --git a/src/DotNetOpenAuth/OpenId/Messages/RequestBase.cs b/src/DotNetOpenAuth/OpenId/Messages/RequestBase.cs
index 8a4a2a6..6b89e92 100644
--- a/src/DotNetOpenAuth/OpenId/Messages/RequestBase.cs
+++ b/src/DotNetOpenAuth/OpenId/Messages/RequestBase.cs
@@ -49,12 +49,8 @@ namespace DotNetOpenAuth.OpenId.Messages {
/// <param name="mode">The value for the openid.mode parameter.</param>
/// <param name="transport">A value indicating whether the message will be transmitted directly or indirectly.</param>
protected RequestBase(Version version, Uri providerEndpoint, string mode, MessageTransport transport) {
- if (providerEndpoint == null) {
- throw new ArgumentNullException("providerEndpoint");
- }
- if (String.IsNullOrEmpty(mode)) {
- throw new ArgumentNullException("mode");
- }
+ Contract.Requires<ArgumentNullException>(providerEndpoint != null);
+ Contract.Requires<ArgumentException>(!String.IsNullOrEmpty(mode));
this.Recipient = providerEndpoint;
this.Mode = mode;
diff --git a/src/DotNetOpenAuth/OpenId/Protocol.cs b/src/DotNetOpenAuth/OpenId/Protocol.cs
index d84a923..5aacfd2 100644
--- a/src/DotNetOpenAuth/OpenId/Protocol.cs
+++ b/src/DotNetOpenAuth/OpenId/Protocol.cs
@@ -157,7 +157,7 @@ namespace DotNetOpenAuth.OpenId {
/// of an incoming OpenID <i>indirect</i> message or <i>direct request</i>.
/// </summary>
internal static Protocol Detect(IDictionary<string, string> query) {
- if (query == null) throw new ArgumentNullException("query");
+ Contract.Requires<ArgumentNullException>(query != null);
return query.ContainsKey(V20.openid.ns) ? V20 : V11;
}
/// <summary>
@@ -165,7 +165,7 @@ namespace DotNetOpenAuth.OpenId {
/// of an incoming OpenID <i>direct</i> response message.
/// </summary>
internal static Protocol DetectFromDirectResponse(IDictionary<string, string> query) {
- if (query == null) throw new ArgumentNullException("query");
+ Contract.Requires<ArgumentNullException>(query != null);
return query.ContainsKey(V20.openidnp.ns) ? V20 : V11;
}
/// <summary>
@@ -173,7 +173,7 @@ namespace DotNetOpenAuth.OpenId {
/// of XRDS Service Type URIs included for some service.
/// </summary>
internal static Protocol Detect(IEnumerable<string> serviceTypeURIs) {
- if (serviceTypeURIs == null) throw new ArgumentNullException("serviceTypeURIs");
+ Contract.Requires<ArgumentNullException>(serviceTypeURIs != null);
return FindBestVersion(p => p.OPIdentifierServiceTypeURI, serviceTypeURIs) ??
FindBestVersion(p => p.ClaimedIdentifierServiceTypeURI, serviceTypeURIs) ??
FindBestVersion(p => p.RPReturnToTypeURI, serviceTypeURIs);