summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Core/Messaging
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2012-01-27 08:19:20 -0800
committerAndrew Arnott <andrewarnott@gmail.com>2012-01-29 10:39:00 -0800
commiteb2fe80ed606932a983bb8002c132a98514db827 (patch)
tree944f9e57a51eb92da4b169d85c09487b15288432 /src/DotNetOpenAuth.Core/Messaging
parent8dc4fc1e94fd0c4f7b34e68da67cb81efab504d7 (diff)
downloadDotNetOpenAuth-eb2fe80ed606932a983bb8002c132a98514db827.zip
DotNetOpenAuth-eb2fe80ed606932a983bb8002c132a98514db827.tar.gz
DotNetOpenAuth-eb2fe80ed606932a983bb8002c132a98514db827.tar.bz2
OpenID messages that are missing signed parameters now throws ProtocolException instead of KeyNotFoundException.
Fixes #45
Diffstat (limited to 'src/DotNetOpenAuth.Core/Messaging')
-rw-r--r--src/DotNetOpenAuth.Core/Messaging/ErrorUtilities.cs20
-rw-r--r--src/DotNetOpenAuth.Core/Messaging/MessagingStrings.Designer.cs11
-rw-r--r--src/DotNetOpenAuth.Core/Messaging/MessagingStrings.resx5
3 files changed, 34 insertions, 2 deletions
diff --git a/src/DotNetOpenAuth.Core/Messaging/ErrorUtilities.cs b/src/DotNetOpenAuth.Core/Messaging/ErrorUtilities.cs
index c6a652b..129a03d 100644
--- a/src/DotNetOpenAuth.Core/Messaging/ErrorUtilities.cs
+++ b/src/DotNetOpenAuth.Core/Messaging/ErrorUtilities.cs
@@ -6,6 +6,7 @@
namespace DotNetOpenAuth.Messaging {
using System;
+ using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Globalization;
@@ -361,5 +362,24 @@ namespace DotNetOpenAuth.Messaging {
Contract.Ensures(HttpContext.Current.Request != null);
ErrorUtilities.VerifyOperation(HttpContext.Current != null && HttpContext.Current.Request != null, MessagingStrings.HttpContextRequired);
}
+
+ /// <summary>
+ /// Obtains a value from the dictionary if possible, or throws a <see cref="ProtocolException"/> if it's missing.
+ /// </summary>
+ /// <typeparam name="TKey">The type of key in the dictionary.</typeparam>
+ /// <typeparam name="TValue">The type of value in the dictionary.</typeparam>
+ /// <param name="dictionary">The dictionary.</param>
+ /// <param name="key">The key to use to look up the value.</param>
+ /// <param name="message">The message to claim is invalid if the key cannot be found.</param>
+ /// <returns>The value for the given key.</returns>
+ [Pure]
+ internal static TValue GetValueOrThrow<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, IMessage message) {
+ Requires.NotNull(dictionary, "dictionary");
+ Requires.NotNull(message, "message");
+
+ TValue value;
+ VerifyProtocol(dictionary.TryGetValue(key, out value), MessagingStrings.ExpectedParameterWasMissing, key, message.GetType().Name);
+ return value;
+ }
}
}
diff --git a/src/DotNetOpenAuth.Core/Messaging/MessagingStrings.Designer.cs b/src/DotNetOpenAuth.Core/Messaging/MessagingStrings.Designer.cs
index 11bd751..3ad2bdd 100644
--- a/src/DotNetOpenAuth.Core/Messaging/MessagingStrings.Designer.cs
+++ b/src/DotNetOpenAuth.Core/Messaging/MessagingStrings.Designer.cs
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
-// Runtime Version:4.0.30319.1
+// Runtime Version:4.0.30319.239
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
@@ -187,6 +187,15 @@ namespace DotNetOpenAuth.Messaging {
}
/// <summary>
+ /// Looks up a localized string similar to The message part {0} was expected in the {1} message but was not found..
+ /// </summary>
+ internal static string ExpectedParameterWasMissing {
+ get {
+ return ResourceManager.GetString("ExpectedParameterWasMissing", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to The message expired at {0} and it is now {1}..
/// </summary>
internal static string ExpiredMessage {
diff --git a/src/DotNetOpenAuth.Core/Messaging/MessagingStrings.resx b/src/DotNetOpenAuth.Core/Messaging/MessagingStrings.resx
index bd10b76..5f3f79a 100644
--- a/src/DotNetOpenAuth.Core/Messaging/MessagingStrings.resx
+++ b/src/DotNetOpenAuth.Core/Messaging/MessagingStrings.resx
@@ -321,4 +321,7 @@
<data name="ExtraParameterAddFailure" xml:space="preserve">
<value>Failed to add extra parameter '{0}' with value '{1}'.</value>
</data>
-</root>
+ <data name="ExpectedParameterWasMissing" xml:space="preserve">
+ <value>The message part {0} was expected in the {1} message but was not found.</value>
+ </data>
+</root> \ No newline at end of file