summaryrefslogtreecommitdiffstats
path: root/src/DotNetOAuth/Messaging
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2008-11-03 17:22:00 -0800
committerAndrew <andrewarnott@gmail.com>2008-11-04 08:12:52 -0800
commit462e19abd9034c11a12cad30e9899740f2bef8ff (patch)
treee08667f1d69249f8daa6c348a919bd0fd5434415 /src/DotNetOAuth/Messaging
parent6a79be0eca3929d8fb4e797799dac8d6f7875475 (diff)
downloadDotNetOpenAuth-462e19abd9034c11a12cad30e9899740f2bef8ff.zip
DotNetOpenAuth-462e19abd9034c11a12cad30e9899740f2bef8ff.tar.gz
DotNetOpenAuth-462e19abd9034c11a12cad30e9899740f2bef8ff.tar.bz2
Changed namepace and project names in preparation for merge with DotNetOpenId.
Diffstat (limited to 'src/DotNetOAuth/Messaging')
-rw-r--r--src/DotNetOAuth/Messaging/Bindings/Bindings.cd76
-rw-r--r--src/DotNetOAuth/Messaging/Bindings/ExpiredMessageException.cs37
-rw-r--r--src/DotNetOAuth/Messaging/Bindings/IExpiringProtocolMessage.cs29
-rw-r--r--src/DotNetOAuth/Messaging/Bindings/INonceStore.cs37
-rw-r--r--src/DotNetOAuth/Messaging/Bindings/IReplayProtectedProtocolMessage.cs24
-rw-r--r--src/DotNetOAuth/Messaging/Bindings/InvalidSignatureException.cs34
-rw-r--r--src/DotNetOAuth/Messaging/Bindings/NonceMemoryStore.cs72
-rw-r--r--src/DotNetOAuth/Messaging/Bindings/ReplayedMessageException.cs34
-rw-r--r--src/DotNetOAuth/Messaging/Bindings/StandardExpirationBindingElement.cs119
-rw-r--r--src/DotNetOAuth/Messaging/Bindings/StandardReplayProtectionBindingElement.cs135
-rw-r--r--src/DotNetOAuth/Messaging/Channel.cs693
-rw-r--r--src/DotNetOAuth/Messaging/ChannelEventArgs.cs31
-rw-r--r--src/DotNetOAuth/Messaging/Exceptions.cd33
-rw-r--r--src/DotNetOAuth/Messaging/HttpDeliveryMethods.cs43
-rw-r--r--src/DotNetOAuth/Messaging/HttpRequestInfo.cs180
-rw-r--r--src/DotNetOAuth/Messaging/IChannelBindingElement.cs48
-rw-r--r--src/DotNetOAuth/Messaging/IDirectedProtocolMessage.cs20
-rw-r--r--src/DotNetOAuth/Messaging/IMessageTypeProvider.cs41
-rw-r--r--src/DotNetOAuth/Messaging/IProtocolMessage.cs54
-rw-r--r--src/DotNetOAuth/Messaging/ITamperProtectionChannelBindingElement.cs28
-rw-r--r--src/DotNetOAuth/Messaging/ITamperResistantProtocolMessage.cs22
-rw-r--r--src/DotNetOAuth/Messaging/MessagePartAttribute.cs57
-rw-r--r--src/DotNetOAuth/Messaging/MessageProtections.cs46
-rw-r--r--src/DotNetOAuth/Messaging/MessageReceivingEndpoint.cs54
-rw-r--r--src/DotNetOAuth/Messaging/MessageSerializer.cs136
-rw-r--r--src/DotNetOAuth/Messaging/MessageTransport.cs22
-rw-r--r--src/DotNetOAuth/Messaging/Messaging.cd62
-rw-r--r--src/DotNetOAuth/Messaging/MessagingStrings.Designer.cs351
-rw-r--r--src/DotNetOAuth/Messaging/MessagingStrings.resx216
-rw-r--r--src/DotNetOAuth/Messaging/MessagingUtilities.cs271
-rw-r--r--src/DotNetOAuth/Messaging/ProtocolException.cs254
-rw-r--r--src/DotNetOAuth/Messaging/Reflection/MessageDescription.cs128
-rw-r--r--src/DotNetOAuth/Messaging/Reflection/MessageDictionary.cs320
-rw-r--r--src/DotNetOAuth/Messaging/Reflection/MessagePart.cs251
-rw-r--r--src/DotNetOAuth/Messaging/Reflection/ValueMapping.cs42
-rw-r--r--src/DotNetOAuth/Messaging/Response.cs178
-rw-r--r--src/DotNetOAuth/Messaging/UnprotectedMessageException.cs37
37 files changed, 0 insertions, 4215 deletions
diff --git a/src/DotNetOAuth/Messaging/Bindings/Bindings.cd b/src/DotNetOAuth/Messaging/Bindings/Bindings.cd
deleted file mode 100644
index c663332..0000000
--- a/src/DotNetOAuth/Messaging/Bindings/Bindings.cd
+++ /dev/null
@@ -1,76 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<ClassDiagram MajorVersion="1" MinorVersion="1">
- <Class Name="DotNetOAuth.Messaging.Bindings.InvalidSignatureException" Collapsed="true">
- <Position X="8.25" Y="2" Width="1.5" />
- <TypeIdentifier>
- <HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
- <FileName>Messaging\Bindings\InvalidSignatureException.cs</FileName>
- </TypeIdentifier>
- </Class>
- <Class Name="DotNetOAuth.Messaging.Bindings.ReplayedMessageException" Collapsed="true">
- <Position X="6" Y="2" Width="1.5" />
- <TypeIdentifier>
- <HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
- <FileName>Messaging\Bindings\ReplayedMessageException.cs</FileName>
- </TypeIdentifier>
- </Class>
- <Class Name="DotNetOAuth.Messaging.Bindings.ExpiredMessageException" Collapsed="true">
- <Position X="3.75" Y="2" Width="1.5" />
- <TypeIdentifier>
- <HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
- <FileName>Messaging\Bindings\ExpiredMessageException.cs</FileName>
- </TypeIdentifier>
- </Class>
- <Class Name="DotNetOAuth.Messaging.ProtocolException" Collapsed="true">
- <Position X="6" Y="0.5" Width="1.5" />
- <TypeIdentifier>
- <HashCode>AAAKAAAAAAAAAAAAAIBAAAAACAQAIAAAAACAAAAAAAA=</HashCode>
- <FileName>Messaging\ProtocolException.cs</FileName>
- </TypeIdentifier>
- <Lollipop Position="0.2" />
- </Class>
- <Class Name="DotNetOAuth.Messaging.Bindings.StandardExpirationBindingElement" Collapsed="true">
- <Position X="1" Y="3" Width="2.75" />
- <TypeIdentifier>
- <HashCode>AAAQAAAAAAAARAAAAAAAEAAAAAIAAAAAAAAAAAAAAAA=</HashCode>
- <FileName>Messaging\Bindings\StandardExpirationBindingElement.cs</FileName>
- </TypeIdentifier>
- <Lollipop Position="0.2" />
- </Class>
- <Interface Name="DotNetOAuth.Messaging.IProtocolMessage" Collapsed="true">
- <Position X="6" Y="3.5" Width="1.5" />
- <TypeIdentifier>
- <HashCode>AAAAAAAAQAAAAAAAAAAAAAYAAAAAAAAAAAACAAAAAAA=</HashCode>
- <FileName>Messaging\IProtocolMessage.cs</FileName>
- </TypeIdentifier>
- </Interface>
- <Interface Name="DotNetOAuth.Messaging.Bindings.IExpiringProtocolMessage" Collapsed="true">
- <Position X="3.75" Y="4.75" Width="1.5" />
- <TypeIdentifier>
- <HashCode>AAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAA=</HashCode>
- <FileName>Messaging\Bindings\IExpiringProtocolMessage.cs</FileName>
- </TypeIdentifier>
- </Interface>
- <Interface Name="DotNetOAuth.Messaging.Bindings.IReplayProtectedProtocolMessage" Collapsed="true">
- <Position X="6" Y="4.75" Width="1.5" />
- <TypeIdentifier>
- <HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAA=</HashCode>
- <FileName>Messaging\Bindings\IReplayProtectedProtocolMessage.cs</FileName>
- </TypeIdentifier>
- </Interface>
- <Interface Name="DotNetOAuth.Messaging.Bindings.ISignedOAuthMessage" Collapsed="true">
- <Position X="8.25" Y="4.75" Width="1.5" />
- <TypeIdentifier>
- <HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAE=</HashCode>
- <FileName>Messaging\Bindings\ISignedOAuthMessage.cs</FileName>
- </TypeIdentifier>
- </Interface>
- <Interface Name="DotNetOAuth.Messaging.IChannelBindingElement">
- <Position X="0.5" Y="0.5" Width="2" />
- <TypeIdentifier>
- <HashCode>BAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAEAAAAAAAAA=</HashCode>
- <FileName>Messaging\IChannelBindingElement.cs</FileName>
- </TypeIdentifier>
- </Interface>
- <Font Name="Segoe UI" Size="9" />
-</ClassDiagram> \ No newline at end of file
diff --git a/src/DotNetOAuth/Messaging/Bindings/ExpiredMessageException.cs b/src/DotNetOAuth/Messaging/Bindings/ExpiredMessageException.cs
deleted file mode 100644
index fabe7e4..0000000
--- a/src/DotNetOAuth/Messaging/Bindings/ExpiredMessageException.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="ExpiredMessageException.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOAuth.Messaging.Bindings {
- using System;
- using System.Globalization;
-
- /// <summary>
- /// An exception thrown when a message is received that exceeds the maximum message age limit.
- /// </summary>
- [Serializable]
- internal class ExpiredMessageException : ProtocolException {
- /// <summary>
- /// Initializes a new instance of the <see cref="ExpiredMessageException"/> class.
- /// </summary>
- /// <param name="utcExpirationDate">The date the message expired.</param>
- /// <param name="faultedMessage">The expired message.</param>
- public ExpiredMessageException(DateTime utcExpirationDate, IProtocolMessage faultedMessage)
- : base(string.Format(CultureInfo.CurrentCulture, MessagingStrings.ExpiredMessage, utcExpirationDate.ToUniversalTime(), DateTime.UtcNow), faultedMessage) {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="ExpiredMessageException"/> class.
- /// </summary>
- /// <param name="info">The <see cref="System.Runtime.Serialization.SerializationInfo"/>
- /// that holds the serialized object data about the exception being thrown.</param>
- /// <param name="context">The System.Runtime.Serialization.StreamingContext
- /// that contains contextual information about the source or destination.</param>
- protected ExpiredMessageException(
- System.Runtime.Serialization.SerializationInfo info,
- System.Runtime.Serialization.StreamingContext context)
- : base(info, context) { }
- }
-}
diff --git a/src/DotNetOAuth/Messaging/Bindings/IExpiringProtocolMessage.cs b/src/DotNetOAuth/Messaging/Bindings/IExpiringProtocolMessage.cs
deleted file mode 100644
index 39c4f97..0000000
--- a/src/DotNetOAuth/Messaging/Bindings/IExpiringProtocolMessage.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="IExpiringProtocolMessage.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOAuth.Messaging.Bindings {
- using System;
-
- /// <summary>
- /// The contract a message that has an allowable time window for processing must implement.
- /// </summary>
- /// <remarks>
- /// All expiring messages must also be signed to prevent tampering with the creation date.
- /// </remarks>
- internal interface IExpiringProtocolMessage : IProtocolMessage {
- /// <summary>
- /// Gets or sets the UTC date/time the message was originally sent onto the network.
- /// </summary>
- /// <remarks>
- /// The property setter should ensure a UTC date/time,
- /// and throw an exception if this is not possible.
- /// </remarks>
- /// <exception cref="ArgumentException">
- /// Thrown when a DateTime that cannot be converted to UTC is set.
- /// </exception>
- DateTime UtcCreationDate { get; set; }
- }
-}
diff --git a/src/DotNetOAuth/Messaging/Bindings/INonceStore.cs b/src/DotNetOAuth/Messaging/Bindings/INonceStore.cs
deleted file mode 100644
index 0ff7e60..0000000
--- a/src/DotNetOAuth/Messaging/Bindings/INonceStore.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="INonceStore.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOAuth.Messaging.Bindings {
- using System;
-
- /// <summary>
- /// Describes the contract a nonce store must fulfill.
- /// </summary>
- internal interface INonceStore {
- /// <summary>
- /// Stores a given nonce and timestamp.
- /// </summary>
- /// <param name="nonce">
- /// A series of random characters.
- /// </param>
- /// <param name="timestamp">
- /// The timestamp that together with the nonce string make it unique.
- /// The timestamp may also be used by the data store to clear out old nonces.
- /// </param>
- /// <returns>
- /// True if the nonce+timestamp (combination) was not previously in the database.
- /// False if the nonce was stored previously with the same timestamp.
- /// </returns>
- /// <remarks>
- /// The nonce must be stored for no less than the maximum time window a message may
- /// be processed within before being discarded as an expired message.
- /// If the binding element is applicable to your channel, this expiration window
- /// is retrieved or set using the
- /// <see cref="StandardExpirationBindingElement.MaximumMessageAge"/> property.
- /// </remarks>
- bool StoreNonce(string nonce, DateTime timestamp);
- }
-}
diff --git a/src/DotNetOAuth/Messaging/Bindings/IReplayProtectedProtocolMessage.cs b/src/DotNetOAuth/Messaging/Bindings/IReplayProtectedProtocolMessage.cs
deleted file mode 100644
index bc685ce..0000000
--- a/src/DotNetOAuth/Messaging/Bindings/IReplayProtectedProtocolMessage.cs
+++ /dev/null
@@ -1,24 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="IReplayProtectedProtocolMessage.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOAuth.Messaging.Bindings {
- using System;
- using DotNetOAuth.Messaging;
-
- /// <summary>
- /// The contract a message that has an allowable time window for processing must implement.
- /// </summary>
- /// <remarks>
- /// All replay-protected messages must also be set to expire so the nonces do not have
- /// to be stored indefinitely.
- /// </remarks>
- internal interface IReplayProtectedProtocolMessage : IExpiringProtocolMessage {
- /// <summary>
- /// Gets or sets the nonce that will protect the message from replay attacks.
- /// </summary>
- string Nonce { get; set; }
- }
-}
diff --git a/src/DotNetOAuth/Messaging/Bindings/InvalidSignatureException.cs b/src/DotNetOAuth/Messaging/Bindings/InvalidSignatureException.cs
deleted file mode 100644
index 89fa938..0000000
--- a/src/DotNetOAuth/Messaging/Bindings/InvalidSignatureException.cs
+++ /dev/null
@@ -1,34 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="InvalidSignatureException.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOAuth.Messaging.Bindings {
- using System;
-
- /// <summary>
- /// An exception thrown when a signed message does not pass signature validation.
- /// </summary>
- [Serializable]
- internal class InvalidSignatureException : ProtocolException {
- /// <summary>
- /// Initializes a new instance of the <see cref="InvalidSignatureException"/> class.
- /// </summary>
- /// <param name="faultedMessage">The message with the invalid signature.</param>
- public InvalidSignatureException(IProtocolMessage faultedMessage)
- : base(MessagingStrings.SignatureInvalid, faultedMessage) { }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="InvalidSignatureException"/> class.
- /// </summary>
- /// <param name="info">The <see cref="System.Runtime.Serialization.SerializationInfo"/>
- /// that holds the serialized object data about the exception being thrown.</param>
- /// <param name="context">The System.Runtime.Serialization.StreamingContext
- /// that contains contextual information about the source or destination.</param>
- protected InvalidSignatureException(
- System.Runtime.Serialization.SerializationInfo info,
- System.Runtime.Serialization.StreamingContext context)
- : base(info, context) { }
- }
-}
diff --git a/src/DotNetOAuth/Messaging/Bindings/NonceMemoryStore.cs b/src/DotNetOAuth/Messaging/Bindings/NonceMemoryStore.cs
deleted file mode 100644
index 98b93ff..0000000
--- a/src/DotNetOAuth/Messaging/Bindings/NonceMemoryStore.cs
+++ /dev/null
@@ -1,72 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="NonceMemoryStore.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOAuth.Messaging.Bindings {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using DotNetOAuth.Messaging.Bindings;
-
- /// <summary>
- /// An in-memory nonce store. Useful for single-server web applications.
- /// NOT for web farms.
- /// </summary>
- internal class NonceMemoryStore : INonceStore {
- /// <summary>
- /// The maximum age a message can be before it is discarded.
- /// </summary>
- /// <remarks>
- /// This is useful for knowing how long used nonces must be retained.
- /// </remarks>
- private readonly TimeSpan maximumMessageAge;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="NonceMemoryStore"/> class.
- /// </summary>
- /// <param name="maximumMessageAge">The maximum age a message can be before it is discarded.</param>
- internal NonceMemoryStore(TimeSpan maximumMessageAge) {
- this.maximumMessageAge = maximumMessageAge;
- }
-
- #region INonceStore Members
-
- /// <summary>
- /// Stores a given nonce and timestamp.
- /// </summary>
- /// <param name="nonce">
- /// A series of random characters.
- /// </param>
- /// <param name="timestamp">
- /// The timestamp that together with the nonce string make it unique.
- /// The timestamp may also be used by the data store to clear out old nonces.
- /// </param>
- /// <returns>
- /// True if the nonce+timestamp (combination) was not previously in the database.
- /// False if the nonce was stored previously with the same timestamp.
- /// </returns>
- /// <remarks>
- /// The nonce must be stored for no less than the maximum time window a message may
- /// be processed within before being discarded as an expired message.
- /// If the binding element is applicable to your channel, this expiration window
- /// is retrieved or set using the
- /// <see cref="StandardExpirationBindingElement.MaximumMessageAge"/> property.
- /// </remarks>
- public bool StoreNonce(string nonce, DateTime timestamp) {
- if (timestamp.ToUniversalTime() + this.maximumMessageAge < DateTime.UtcNow) {
- // The expiration binding element should have taken care of this, but perhaps
- // it's at the boundary case. We should fail just to be safe.
- return false;
- }
-
- // TODO: implement actual nonce checking.
- Logger.Warn("Nonce checking not implemented yet.");
- return true;
- }
-
- #endregion
- }
-}
diff --git a/src/DotNetOAuth/Messaging/Bindings/ReplayedMessageException.cs b/src/DotNetOAuth/Messaging/Bindings/ReplayedMessageException.cs
deleted file mode 100644
index 11cf096..0000000
--- a/src/DotNetOAuth/Messaging/Bindings/ReplayedMessageException.cs
+++ /dev/null
@@ -1,34 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="ReplayedMessageException.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOAuth.Messaging.Bindings {
- using System;
-
- /// <summary>
- /// An exception thrown when a message is received for the second time, signalling a possible
- /// replay attack.
- /// </summary>
- [Serializable]
- internal class ReplayedMessageException : ProtocolException {
- /// <summary>
- /// Initializes a new instance of the <see cref="ReplayedMessageException"/> class.
- /// </summary>
- /// <param name="faultedMessage">The replayed message.</param>
- public ReplayedMessageException(IProtocolMessage faultedMessage) : base(MessagingStrings.ReplayAttackDetected, faultedMessage) { }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="ReplayedMessageException"/> class.
- /// </summary>
- /// <param name="info">The <see cref="System.Runtime.Serialization.SerializationInfo"/>
- /// that holds the serialized object data about the exception being thrown.</param>
- /// <param name="context">The System.Runtime.Serialization.StreamingContext
- /// that contains contextual information about the source or destination.</param>
- protected ReplayedMessageException(
- System.Runtime.Serialization.SerializationInfo info,
- System.Runtime.Serialization.StreamingContext context)
- : base(info, context) { }
- }
-}
diff --git a/src/DotNetOAuth/Messaging/Bindings/StandardExpirationBindingElement.cs b/src/DotNetOAuth/Messaging/Bindings/StandardExpirationBindingElement.cs
deleted file mode 100644
index fa7f78c..0000000
--- a/src/DotNetOAuth/Messaging/Bindings/StandardExpirationBindingElement.cs
+++ /dev/null
@@ -1,119 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="StandardExpirationBindingElement.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOAuth.Messaging.Bindings {
- using System;
-
- /// <summary>
- /// A message expiration enforcing binding element that supports messages
- /// implementing the <see cref="IExpiringProtocolMessage"/> interface.
- /// </summary>
- internal class StandardExpirationBindingElement : IChannelBindingElement {
- /// <summary>
- /// The default maximum message age to use if the default constructor is called.
- /// </summary>
- internal static readonly TimeSpan DefaultMaximumMessageAge = TimeSpan.FromMinutes(13);
-
- /// <summary>
- /// Initializes a new instance of the <see cref="StandardExpirationBindingElement"/> class
- /// with a default maximum message lifetime of 13 minutes.
- /// </summary>
- internal StandardExpirationBindingElement()
- : this(DefaultMaximumMessageAge) {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="StandardExpirationBindingElement"/> class.
- /// </summary>
- /// <param name="maximumAge">
- /// <para>The maximum age a message implementing the
- /// <see cref="IExpiringProtocolMessage"/> interface can be before
- /// being discarded as too old.</para>
- /// <para>This time limit should take into account expected time skew for servers
- /// across the Internet. For example, if a server could conceivably have its
- /// clock d = 5 minutes off UTC time, then any two servers could have
- /// their clocks disagree by as much as 2*d = 10 minutes.
- /// If a message should live for at least t = 3 minutes,
- /// this property should be set to (2*d + t) = 13 minutes.</para>
- /// </param>
- internal StandardExpirationBindingElement(TimeSpan maximumAge) {
- this.MaximumMessageAge = maximumAge;
- }
-
- #region IChannelBindingElement Properties
-
- /// <summary>
- /// Gets the protection offered by this binding element.
- /// </summary>
- /// <value><see cref="MessageProtections.Expiration"/></value>
- MessageProtections IChannelBindingElement.Protection {
- get { return MessageProtections.Expiration; }
- }
-
- #endregion
-
- /// <summary>
- /// Gets the maximum age a message implementing the
- /// <see cref="IExpiringProtocolMessage"/> interface can be before
- /// being discarded as too old.
- /// </summary>
- protected internal TimeSpan MaximumMessageAge {
- get;
- private set;
- }
-
- #region IChannelBindingElement Methods
-
- /// <summary>
- /// Sets the timestamp on an outgoing message.
- /// </summary>
- /// <param name="message">The outgoing message.</param>
- /// <returns>
- /// True if the <paramref name="message"/> applied to this binding element
- /// and the operation was successful. False otherwise.
- /// </returns>
- bool IChannelBindingElement.PrepareMessageForSending(IProtocolMessage message) {
- IExpiringProtocolMessage expiringMessage = message as IExpiringProtocolMessage;
- if (expiringMessage != null) {
- expiringMessage.UtcCreationDate = DateTime.UtcNow;
- return true;
- }
-
- return false;
- }
-
- /// <summary>
- /// Reads the timestamp on a message and throws an exception if the message is too old.
- /// </summary>
- /// <param name="message">The incoming message.</param>
- /// <returns>
- /// True if the <paramref name="message"/> applied to this binding element
- /// and the operation was successful. False if the operation did not apply to this message.
- /// </returns>
- /// <exception cref="ExpiredMessageException">Thrown if the given message has already expired.</exception>
- /// <exception cref="ProtocolException">
- /// Thrown when the binding element rules indicate that this message is invalid and should
- /// NOT be processed.
- /// </exception>
- bool IChannelBindingElement.PrepareMessageForReceiving(IProtocolMessage message) {
- IExpiringProtocolMessage expiringMessage = message as IExpiringProtocolMessage;
- if (expiringMessage != null) {
- // Yes the UtcCreationDate is supposed to always be in UTC already,
- // but just in case a given message failed to guarantee that, we do it here.
- DateTime expirationDate = expiringMessage.UtcCreationDate.ToUniversalTime() + this.MaximumMessageAge;
- if (expirationDate < DateTime.UtcNow) {
- throw new ExpiredMessageException(expirationDate, expiringMessage);
- }
-
- return true;
- }
-
- return false;
- }
-
- #endregion
- }
-}
diff --git a/src/DotNetOAuth/Messaging/Bindings/StandardReplayProtectionBindingElement.cs b/src/DotNetOAuth/Messaging/Bindings/StandardReplayProtectionBindingElement.cs
deleted file mode 100644
index b97b25e..0000000
--- a/src/DotNetOAuth/Messaging/Bindings/StandardReplayProtectionBindingElement.cs
+++ /dev/null
@@ -1,135 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="StandardReplayProtectionBindingElement.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOAuth.Messaging.Bindings {
- using System;
- using System.Diagnostics;
-
- /// <summary>
- /// A binding element that checks/verifies a nonce message part.
- /// </summary>
- internal class StandardReplayProtectionBindingElement : IChannelBindingElement {
- /// <summary>
- /// These are the characters that may be chosen from when forming a random nonce.
- /// </summary>
- private const string AllowedCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
-
- /// <summary>
- /// The persistent store for nonces received.
- /// </summary>
- private INonceStore nonceStore;
-
- /// <summary>
- /// The length of generated nonces.
- /// </summary>
- private int nonceLength = 8;
-
- /// <summary>
- /// A random number generator.
- /// </summary>
- private Random generator = new Random();
-
- /// <summary>
- /// Initializes a new instance of the <see cref="StandardReplayProtectionBindingElement"/> class.
- /// </summary>
- /// <param name="nonceStore">The store where nonces will be persisted and checked.</param>
- internal StandardReplayProtectionBindingElement(INonceStore nonceStore) {
- if (nonceStore == null) {
- throw new ArgumentNullException("nonceStore");
- }
-
- this.nonceStore = nonceStore;
- }
-
- #region IChannelBindingElement Properties
-
- /// <summary>
- /// Gets the protection that this binding element provides messages.
- /// </summary>
- public MessageProtections Protection {
- get { return MessageProtections.ReplayProtection; }
- }
-
- #endregion
-
- /// <summary>
- /// Gets or sets the strength of the nonce, which is measured by the number of
- /// nonces that could theoretically be generated.
- /// </summary>
- /// <remarks>
- /// The strength of the nonce is equal to the number of characters that might appear
- /// in the nonce to the power of the length of the nonce.
- /// </remarks>
- internal double NonceStrength {
- get {
- return Math.Pow(AllowedCharacters.Length, this.nonceLength);
- }
-
- set {
- value = Math.Max(value, AllowedCharacters.Length);
- this.nonceLength = (int)Math.Log(value, AllowedCharacters.Length);
- Debug.Assert(this.nonceLength > 0, "Nonce length calculated to be below 1!");
- }
- }
-
- #region IChannelBindingElement Methods
-
- /// <summary>
- /// Applies a nonce to the message.
- /// </summary>
- /// <param name="message">The message to apply replay protection to.</param>
- /// <returns>True if the message protection was applied. False otherwise.</returns>
- public bool PrepareMessageForSending(IProtocolMessage message) {
- IReplayProtectedProtocolMessage nonceMessage = message as IReplayProtectedProtocolMessage;
- if (nonceMessage != null) {
- nonceMessage.Nonce = this.GenerateUniqueFragment();
- return true;
- }
-
- return false;
- }
-
- /// <summary>
- /// Verifies that the nonce in an incoming message has not been seen before.
- /// </summary>
- /// <param name="message">The incoming message.</param>
- /// <returns>
- /// True if the message nonce passed replay detection checks.
- /// False if the message did not have a nonce that could be checked at all.
- /// </returns>
- /// <exception cref="ReplayedMessageException">Thrown when the nonce check revealed a replayed message.</exception>
- public bool PrepareMessageForReceiving(IProtocolMessage message) {
- IReplayProtectedProtocolMessage nonceMessage = message as IReplayProtectedProtocolMessage;
- if (nonceMessage != null) {
- if (nonceMessage.Nonce == null || nonceMessage.Nonce.Length <= 0) {
- throw new ProtocolException(MessagingStrings.InvalidNonceReceived);
- }
-
- if (!this.nonceStore.StoreNonce(nonceMessage.Nonce, nonceMessage.UtcCreationDate)) {
- throw new ReplayedMessageException(message);
- }
-
- return true;
- }
-
- return false;
- }
-
- #endregion
-
- /// <summary>
- /// Generates a string of random characters for use as a nonce.
- /// </summary>
- /// <returns>The nonce string.</returns>
- private string GenerateUniqueFragment() {
- char[] nonce = new char[this.nonceLength];
- for (int i = 0; i < nonce.Length; i++) {
- nonce[i] = AllowedCharacters[this.generator.Next(AllowedCharacters.Length)];
- }
- return new string(nonce);
- }
- }
-}
diff --git a/src/DotNetOAuth/Messaging/Channel.cs b/src/DotNetOAuth/Messaging/Channel.cs
deleted file mode 100644
index 0f2fe04..0000000
--- a/src/DotNetOAuth/Messaging/Channel.cs
+++ /dev/null
@@ -1,693 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="Channel.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOAuth.Messaging {
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Diagnostics;
- using System.Globalization;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Text;
- using System.Web;
- using DotNetOAuth.Messaging.Reflection;
-
- /// <summary>
- /// Manages sending direct messages to a remote party and receiving responses.
- /// </summary>
- public abstract class Channel {
- /// <summary>
- /// The maximum allowable size for a 301 Redirect response before we send
- /// a 200 OK response with a scripted form POST with the parameters instead
- /// in order to ensure successfully sending a large payload to another server
- /// that might have a maximum allowable size restriction on its GET request.
- /// </summary>
- private static int indirectMessageGetToPostThreshold = 2 * 1024; // 2KB, recommended by OpenID group
-
- /// <summary>
- /// The template for indirect messages that require form POST to forward through the user agent.
- /// </summary>
- /// <remarks>
- /// We are intentionally using " instead of the html single quote ' below because
- /// the HtmlEncode'd values that we inject will only escape the double quote, so
- /// only the double-quote used around these values is safe.
- /// </remarks>
- private static string indirectMessageFormPostFormat = @"
-<html>
-<body onload=""var btn = document.getElementById('submit_button'); btn.disabled = true; btn.value = 'Login in progress'; document.getElementById('openid_message').submit()"">
-<form id=""openid_message"" action=""{0}"" method=""post"" accept-charset=""UTF-8"" enctype=""application/x-www-form-urlencoded"" onSubmit=""var btn = document.getElementById('submit_button'); btn.disabled = true; btn.value = 'Login in progress'; return true;"">
-{1}
- <input id=""submit_button"" type=""submit"" value=""Continue"" />
-</form>
-</body>
-</html>
-";
-
- /// <summary>
- /// A tool that can figure out what kind of message is being received
- /// so it can be deserialized.
- /// </summary>
- private IMessageTypeProvider messageTypeProvider;
-
- /// <summary>
- /// A list of binding elements in the order they must be applied to outgoing messages.
- /// </summary>
- /// <remarks>
- /// Incoming messages should have the binding elements applied in reverse order.
- /// </remarks>
- [DebuggerBrowsable(DebuggerBrowsableState.Never)]
- private List<IChannelBindingElement> bindingElements = new List<IChannelBindingElement>();
-
- /// <summary>
- /// Initializes a new instance of the <see cref="Channel"/> class.
- /// </summary>
- /// <param name="messageTypeProvider">
- /// A class prepared to analyze incoming messages and indicate what concrete
- /// message types can deserialize from it.
- /// </param>
- /// <param name="bindingElements">The binding elements to use in sending and receiving messages.</param>
- protected Channel(IMessageTypeProvider messageTypeProvider, params IChannelBindingElement[] bindingElements) {
- if (messageTypeProvider == null) {
- throw new ArgumentNullException("messageTypeProvider");
- }
-
- this.messageTypeProvider = messageTypeProvider;
- this.bindingElements = new List<IChannelBindingElement>(ValidateAndPrepareBindingElements(bindingElements));
- }
-
- /// <summary>
- /// An event fired whenever a message is about to be encoded and sent.
- /// </summary>
- internal event EventHandler<ChannelEventArgs> Sending;
-
- /// <summary>
- /// Gets the binding elements used by this channel, in the order they are applied to outgoing messages.
- /// </summary>
- /// <remarks>
- /// Incoming messages are processed by this binding elements in the reverse order.
- /// </remarks>
- protected internal ReadOnlyCollection<IChannelBindingElement> BindingElements {
- get {
- return this.bindingElements.AsReadOnly();
- }
- }
-
- /// <summary>
- /// Gets a tool that can figure out what kind of message is being received
- /// so it can be deserialized.
- /// </summary>
- protected IMessageTypeProvider MessageTypeProvider {
- get { return this.messageTypeProvider; }
- }
-
- /// <summary>
- /// Queues an indirect message (either a request or response)
- /// or direct message response for transmission to a remote party.
- /// </summary>
- /// <param name="message">The one-way message to send</param>
- /// <returns>The pending user agent redirect based message to be sent as an HttpResponse.</returns>
- public Response Send(IProtocolMessage message) {
- if (message == null) {
- throw new ArgumentNullException("message");
- }
- this.PrepareMessageForSending(message);
- Logger.DebugFormat("Sending message: {0}", message);
-
- switch (message.Transport) {
- case MessageTransport.Direct:
- // This is a response to a direct message.
- return this.SendDirectMessageResponse(message);
- case MessageTransport.Indirect:
- var directedMessage = message as IDirectedProtocolMessage;
- if (directedMessage == null) {
- throw new ArgumentException(
- string.Format(
- CultureInfo.CurrentCulture,
- MessagingStrings.IndirectMessagesMustImplementIDirectedProtocolMessage,
- typeof(IDirectedProtocolMessage).FullName),
- "message");
- }
- if (directedMessage.Recipient == null) {
- throw new ArgumentException(MessagingStrings.DirectedMessageMissingRecipient, "message");
- }
- return this.SendIndirectMessage(directedMessage);
- default:
- throw new ArgumentException(
- string.Format(
- CultureInfo.CurrentCulture,
- MessagingStrings.UnrecognizedEnumValue,
- "Transport",
- message.Transport),
- "message");
- }
- }
-
- /// <summary>
- /// Gets the protocol message embedded in the given HTTP request, if present.
- /// </summary>
- /// <returns>The deserialized message, if one is found. Null otherwise.</returns>
- /// <remarks>
- /// Requires an HttpContext.Current context.
- /// </remarks>
- /// <exception cref="InvalidOperationException">Thrown when <see cref="HttpContext.Current"/> is null.</exception>
- public IProtocolMessage ReadFromRequest() {
- return this.ReadFromRequest(this.GetRequestFromContext());
- }
-
- /// <summary>
- /// Gets the protocol message embedded in the given HTTP request, if present.
- /// </summary>
- /// <typeparam name="TREQUEST">The expected type of the message to be received.</typeparam>
- /// <param name="request">The deserialized message, if one is found. Null otherwise.</param>
- /// <returns>True if the expected message was recognized and deserialized. False otherwise.</returns>
- /// <remarks>
- /// Requires an HttpContext.Current context.
- /// </remarks>
- /// <exception cref="InvalidOperationException">Thrown when <see cref="HttpContext.Current"/> is null.</exception>
- /// <exception cref="ProtocolException">Thrown when a request message of an unexpected type is received.</exception>
- public bool TryReadFromRequest<TREQUEST>(out TREQUEST request)
- where TREQUEST : class, IProtocolMessage {
- return TryReadFromRequest<TREQUEST>(this.GetRequestFromContext(), out request);
- }
-
- /// <summary>
- /// Gets the protocol message embedded in the given HTTP request, if present.
- /// </summary>
- /// <typeparam name="TREQUEST">The expected type of the message to be received.</typeparam>
- /// <param name="httpRequest">The request to search for an embedded message.</param>
- /// <param name="request">The deserialized message, if one is found. Null otherwise.</param>
- /// <returns>True if the expected message was recognized and deserialized. False otherwise.</returns>
- /// <exception cref="InvalidOperationException">Thrown when <see cref="HttpContext.Current"/> is null.</exception>
- /// <exception cref="ProtocolException">Thrown when a request message of an unexpected type is received.</exception>
- public bool TryReadFromRequest<TREQUEST>(HttpRequestInfo httpRequest, out TREQUEST request)
- where TREQUEST : class, IProtocolMessage {
- IProtocolMessage untypedRequest = this.ReadFromRequest(httpRequest);
- if (untypedRequest == null) {
- request = null;
- return false;
- }
-
- request = untypedRequest as TREQUEST;
- if (request == null) {
- throw new ProtocolException(
- string.Format(
- CultureInfo.CurrentCulture,
- MessagingStrings.UnexpectedMessageReceived,
- typeof(TREQUEST),
- untypedRequest.GetType()));
- }
-
- return true;
- }
-
- /// <summary>
- /// Gets the protocol message embedded in the given HTTP request, if present.
- /// </summary>
- /// <typeparam name="TREQUEST">The expected type of the message to be received.</typeparam>
- /// <returns>The deserialized message.</returns>
- /// <remarks>
- /// Requires an HttpContext.Current context.
- /// </remarks>
- /// <exception cref="InvalidOperationException">Thrown when <see cref="HttpContext.Current"/> is null.</exception>
- /// <exception cref="ProtocolException">Thrown if the expected message was not recognized in the response.</exception>
- public TREQUEST ReadFromRequest<TREQUEST>()
- where TREQUEST : class, IProtocolMessage {
- return this.ReadFromRequest<TREQUEST>(this.GetRequestFromContext());
- }
-
- /// <summary>
- /// Gets the protocol message that may be embedded in the given HTTP request.
- /// </summary>
- /// <typeparam name="TREQUEST">The expected type of the message to be received.</typeparam>
- /// <param name="httpRequest">The request to search for an embedded message.</param>
- /// <returns>The deserialized message, if one is found. Null otherwise.</returns>
- /// <exception cref="ProtocolException">Thrown if the expected message was not recognized in the response.</exception>
- public TREQUEST ReadFromRequest<TREQUEST>(HttpRequestInfo httpRequest)
- where TREQUEST : class, IProtocolMessage {
- TREQUEST request;
- if (this.TryReadFromRequest<TREQUEST>(httpRequest, out request)) {
- return request;
- } else {
- throw new ProtocolException(
- string.Format(
- CultureInfo.CurrentCulture,
- MessagingStrings.ExpectedMessageNotReceived,
- typeof(TREQUEST)));
- }
- }
-
- /// <summary>
- /// Gets the protocol message that may be embedded in the given HTTP request.
- /// </summary>
- /// <param name="httpRequest">The request to search for an embedded message.</param>
- /// <returns>The deserialized message, if one is found. Null otherwise.</returns>
- public IProtocolMessage ReadFromRequest(HttpRequestInfo httpRequest) {
- IProtocolMessage requestMessage = this.ReadFromRequestInternal(httpRequest);
- if (requestMessage != null) {
- Logger.DebugFormat("Incoming request received: {0}", requestMessage);
- this.VerifyMessageAfterReceiving(requestMessage);
- }
-
- return requestMessage;
- }
-
- /// <summary>
- /// Sends a direct message to a remote party and waits for the response.
- /// </summary>
- /// <typeparam name="TRESPONSE">The expected type of the message to be received.</typeparam>
- /// <param name="request">The message to send.</param>
- /// <returns>The remote party's response.</returns>
- /// <exception cref="ProtocolException">
- /// Thrown if no message is recognized in the response
- /// or an unexpected type of message is received.
- /// </exception>
- public TRESPONSE Request<TRESPONSE>(IDirectedProtocolMessage request)
- where TRESPONSE : class, IProtocolMessage {
- IProtocolMessage response = this.Request(request);
- if (response == null) {
- throw new ProtocolException(
- string.Format(
- CultureInfo.CurrentCulture,
- MessagingStrings.ExpectedMessageNotReceived,
- typeof(TRESPONSE)));
- }
-
- var expectedResponse = response as TRESPONSE;
- if (expectedResponse == null) {
- throw new ProtocolException(
- string.Format(
- CultureInfo.CurrentCulture,
- MessagingStrings.UnexpectedMessageReceived,
- typeof(TRESPONSE),
- response.GetType()));
- }
-
- return expectedResponse;
- }
-
- /// <summary>
- /// Sends a direct message to a remote party and waits for the response.
- /// </summary>
- /// <param name="request">The message to send.</param>
- /// <returns>The remote party's response.</returns>
- public IProtocolMessage Request(IDirectedProtocolMessage request) {
- if (request == null) {
- throw new ArgumentNullException("request");
- }
-
- this.PrepareMessageForSending(request);
- Logger.DebugFormat("Sending request: {0}", request);
- IProtocolMessage response = this.RequestInternal(request);
- if (response != null) {
- Logger.DebugFormat("Received response: {0}", response);
- this.VerifyMessageAfterReceiving(response);
- }
-
- return response;
- }
-
- /// <summary>
- /// Gets the current HTTP request being processed.
- /// </summary>
- /// <returns>The HttpRequestInfo for the current request.</returns>
- /// <remarks>
- /// Requires an HttpContext.Current context.
- /// </remarks>
- /// <exception cref="InvalidOperationException">Thrown when <see cref="HttpContext.Current"/> is null.</exception>
- protected internal virtual HttpRequestInfo GetRequestFromContext() {
- if (HttpContext.Current == null) {
- throw new InvalidOperationException(MessagingStrings.HttpContextRequired);
- }
-
- return new HttpRequestInfo(HttpContext.Current.Request);
- }
-
- /// <summary>
- /// Fires the <see cref="Sending"/> event.
- /// </summary>
- /// <param name="message">The message about to be encoded and sent.</param>
- protected virtual void OnSending(IProtocolMessage message) {
- if (message == null) {
- throw new ArgumentNullException("message");
- }
-
- var sending = this.Sending;
- if (sending != null) {
- sending(this, new ChannelEventArgs(message));
- }
- }
-
- /// <summary>
- /// Gets the protocol message that may be embedded in the given HTTP request.
- /// </summary>
- /// <param name="request">The request to search for an embedded message.</param>
- /// <returns>The deserialized message, if one is found. Null otherwise.</returns>
- protected virtual IProtocolMessage ReadFromRequestInternal(HttpRequestInfo request) {
- if (request == null) {
- throw new ArgumentNullException("request");
- }
-
- // Search Form data first, and if nothing is there search the QueryString
- var fields = request.Form.ToDictionary();
- if (fields.Count == 0) {
- fields = request.QueryString.ToDictionary();
- }
-
- return this.Receive(fields, request.GetRecipient());
- }
-
- /// <summary>
- /// Deserializes a dictionary of values into a message.
- /// </summary>
- /// <param name="fields">The dictionary of values that were read from an HTTP request or response.</param>
- /// <param name="recipient">Information about where the message was been directed. Null for direct response messages.</param>
- /// <returns>The deserialized message, or null if no message could be recognized in the provided data.</returns>
- protected virtual IProtocolMessage Receive(Dictionary<string, string> fields, MessageReceivingEndpoint recipient) {
- if (fields == null) {
- throw new ArgumentNullException("fields");
- }
-
- Type messageType = this.MessageTypeProvider.GetRequestMessageType(fields);
-
- // If there was no data, or we couldn't recognize it as a message, abort.
- if (messageType == null) {
- return null;
- }
-
- // We have a message! Assemble it.
- var serializer = MessageSerializer.Get(messageType);
- IProtocolMessage message = serializer.Deserialize(fields, recipient);
-
- return message;
- }
-
- /// <summary>
- /// Queues an indirect message for transmittal via the user agent.
- /// </summary>
- /// <param name="message">The message to send.</param>
- /// <returns>The pending user agent redirect based message to be sent as an HttpResponse.</returns>
- protected virtual Response SendIndirectMessage(IDirectedProtocolMessage message) {
- if (message == null) {
- throw new ArgumentNullException("message");
- }
-
- var serializer = MessageSerializer.Get(message.GetType());
- var fields = serializer.Serialize(message);
- Response response;
- if (CalculateSizeOfPayload(fields) > indirectMessageGetToPostThreshold) {
- response = this.CreateFormPostResponse(message, fields);
- } else {
- response = this.Create301RedirectResponse(message, fields);
- }
-
- return response;
- }
-
- /// <summary>
- /// Encodes an HTTP response that will instruct the user agent to forward a message to
- /// some remote third party using a 301 Redirect GET method.
- /// </summary>
- /// <param name="message">The message to forward.</param>
- /// <param name="fields">The pre-serialized fields from the message.</param>
- /// <returns>The encoded HTTP response.</returns>
- protected virtual Response Create301RedirectResponse(IDirectedProtocolMessage message, IDictionary<string, string> fields) {
- if (message == null) {
- throw new ArgumentNullException("message");
- }
- if (message.Recipient == null) {
- throw new ArgumentException(MessagingStrings.DirectedMessageMissingRecipient, "message");
- }
- if (fields == null) {
- throw new ArgumentNullException("fields");
- }
-
- WebHeaderCollection headers = new WebHeaderCollection();
- UriBuilder builder = new UriBuilder(message.Recipient);
- MessagingUtilities.AppendQueryArgs(builder, fields);
- headers.Add(HttpResponseHeader.Location, builder.Uri.AbsoluteUri);
- Logger.DebugFormat("Redirecting to {0}", builder.Uri.AbsoluteUri);
- Response response = new Response {
- Status = HttpStatusCode.Redirect,
- Headers = headers,
- Body = null,
- OriginalMessage = message
- };
-
- return response;
- }
-
- /// <summary>
- /// Encodes an HTTP response that will instruct the user agent to forward a message to
- /// some remote third party using a form POST method.
- /// </summary>
- /// <param name="message">The message to forward.</param>
- /// <param name="fields">The pre-serialized fields from the message.</param>
- /// <returns>The encoded HTTP response.</returns>
- protected virtual Response CreateFormPostResponse(IDirectedProtocolMessage message, IDictionary<string, string> fields) {
- if (message == null) {
- throw new ArgumentNullException("message");
- }
- if (message.Recipient == null) {
- throw new ArgumentException(MessagingStrings.DirectedMessageMissingRecipient, "message");
- }
- if (fields == null) {
- throw new ArgumentNullException("fields");
- }
-
- WebHeaderCollection headers = new WebHeaderCollection();
- StringWriter bodyWriter = new StringWriter(CultureInfo.InvariantCulture);
- StringBuilder hiddenFields = new StringBuilder();
- foreach (var field in fields) {
- hiddenFields.AppendFormat(
- "\t<input type=\"hidden\" name=\"{0}\" value=\"{1}\" />\r\n",
- HttpUtility.HtmlEncode(field.Key),
- HttpUtility.HtmlEncode(field.Value));
- }
- bodyWriter.WriteLine(
- indirectMessageFormPostFormat,
- HttpUtility.HtmlEncode(message.Recipient.AbsoluteUri),
- hiddenFields);
- bodyWriter.Flush();
- Response response = new Response {
- Status = HttpStatusCode.OK,
- Headers = headers,
- Body = bodyWriter.ToString(),
- OriginalMessage = message
- };
-
- return response;
- }
-
- /// <summary>
- /// Gets the protocol message that may be in the given HTTP response stream.
- /// </summary>
- /// <param name="responseStream">The response that is anticipated to contain an OAuth message.</param>
- /// <returns>The deserialized message, if one is found. Null otherwise.</returns>
- protected abstract IProtocolMessage ReadFromResponseInternal(Stream responseStream);
-
- /// <summary>
- /// Sends a direct message to a remote party and waits for the response.
- /// </summary>
- /// <param name="request">The message to send.</param>
- /// <returns>The remote party's response.</returns>
- protected abstract IProtocolMessage RequestInternal(IDirectedProtocolMessage request);
-
- /// <summary>
- /// Queues a message for sending in the response stream where the fields
- /// are sent in the response stream in querystring style.
- /// </summary>
- /// <param name="response">The message to send as a response.</param>
- /// <returns>The pending user agent redirect based message to be sent as an HttpResponse.</returns>
- /// <remarks>
- /// This method implements spec V1.0 section 5.3.
- /// </remarks>
- protected abstract Response SendDirectMessageResponse(IProtocolMessage response);
-
- /// <summary>
- /// Prepares a message for transmit by applying signatures, nonces, etc.
- /// </summary>
- /// <param name="message">The message to prepare for sending.</param>
- /// <remarks>
- /// This method should NOT be called by derived types
- /// except when sending ONE WAY request messages.
- /// </remarks>
- protected void PrepareMessageForSending(IProtocolMessage message) {
- if (message == null) {
- throw new ArgumentNullException("message");
- }
-
- this.OnSending(message);
-
- MessageProtections appliedProtection = MessageProtections.None;
- foreach (IChannelBindingElement bindingElement in this.bindingElements) {
- if (bindingElement.PrepareMessageForSending(message)) {
- appliedProtection |= bindingElement.Protection;
- }
- }
-
- // Ensure that the message's protection requirements have been satisfied.
- if ((message.RequiredProtection & appliedProtection) != message.RequiredProtection) {
- throw new UnprotectedMessageException(message, appliedProtection);
- }
-
- EnsureValidMessageParts(message);
- message.EnsureValidMessage();
- }
-
- /// <summary>
- /// Verifies that all required message parts are initialized to values
- /// prior to sending the message to a remote party.
- /// </summary>
- /// <param name="message">The message to verify.</param>
- /// <exception cref="ProtocolException">
- /// Thrown when any required message part does not have a value.
- /// </exception>
- private static void EnsureValidMessageParts(IProtocolMessage message) {
- Debug.Assert(message != null, "message == null");
-
- MessageDictionary dictionary = new MessageDictionary(message);
- MessageDescription description = MessageDescription.Get(message.GetType());
- description.EnsureRequiredMessagePartsArePresent(dictionary.Keys);
- }
-
- /// <summary>
- /// Calculates a fairly accurate estimation on the size of a message that contains
- /// a given set of fields.
- /// </summary>
- /// <param name="fields">The fields that would be included in a message.</param>
- /// <returns>The size (in bytes) of the message payload.</returns>
- private static int CalculateSizeOfPayload(IDictionary<string, string> fields) {
- Debug.Assert(fields != null, "fields == null");
-
- int size = 0;
- foreach (var field in fields) {
- size += field.Key.Length;
- size += field.Value.Length;
- size += 2; // & and =
- }
- return size;
- }
-
- /// <summary>
- /// Ensures a consistent and secure set of binding elements and
- /// sorts them as necessary for a valid sequence of operations.
- /// </summary>
- /// <param name="elements">The binding elements provided to the channel.</param>
- /// <returns>The properly ordered list of elements.</returns>
- /// <exception cref="ProtocolException">Thrown when the binding elements are incomplete or inconsistent with each other.</exception>
- private static IEnumerable<IChannelBindingElement> ValidateAndPrepareBindingElements(IEnumerable<IChannelBindingElement> elements) {
- if (elements == null) {
- return new IChannelBindingElement[0];
- }
- if (elements.Contains(null)) {
- throw new ArgumentException(MessagingStrings.SequenceContainsNullElement, "elements");
- }
-
- // Filter the elements between the mere transforming ones and the protection ones.
- var transformationElements = new List<IChannelBindingElement>(
- elements.Where(element => element.Protection == MessageProtections.None));
- var protectionElements = new List<IChannelBindingElement>(
- elements.Where(element => element.Protection != MessageProtections.None));
-
- bool wasLastProtectionPresent = true;
- foreach (MessageProtections protectionKind in Enum.GetValues(typeof(MessageProtections))) {
- if (protectionKind == MessageProtections.None) {
- continue;
- }
-
- int countProtectionsOfThisKind = protectionElements.Count(element => (element.Protection & protectionKind) == protectionKind);
-
- // Each protection binding element is backed by the presence of its dependent protection(s).
- if (countProtectionsOfThisKind > 0 && !wasLastProtectionPresent) {
- throw new ProtocolException(
- string.Format(
- CultureInfo.CurrentCulture,
- MessagingStrings.RequiredProtectionMissing,
- protectionKind));
- }
-
- // At most one binding element for each protection type.
- if (countProtectionsOfThisKind > 1) {
- throw new ProtocolException(
- string.Format(
- CultureInfo.CurrentCulture,
- MessagingStrings.TooManyBindingsOfferingSameProtection,
- protectionKind,
- countProtectionsOfThisKind));
- }
- wasLastProtectionPresent = countProtectionsOfThisKind > 0;
- }
-
- // Put the binding elements in order so they are correctly applied to outgoing messages.
- // Start with the transforming (non-protecting) binding elements first and preserve their original order.
- var orderedList = new List<IChannelBindingElement>(transformationElements);
-
- // Now sort the protection binding elements among themselves and add them to the list.
- orderedList.AddRange(protectionElements.OrderBy(element => element.Protection, BindingElementOutgoingMessageApplicationOrder));
- return orderedList;
- }
-
- /// <summary>
- /// Puts binding elements in their correct outgoing message processing order.
- /// </summary>
- /// <param name="protection1">The first protection type to compare.</param>
- /// <param name="protection2">The second protection type to compare.</param>
- /// <returns>
- /// -1 if <paramref name="element1"/> should be applied to an outgoing message before <paramref name="element2"/>.
- /// 1 if <paramref name="element2"/> should be applied to an outgoing message before <paramref name="element1"/>.
- /// 0 if it doesn't matter.
- /// </returns>
- private static int BindingElementOutgoingMessageApplicationOrder(MessageProtections protection1, MessageProtections protection2) {
- Debug.Assert(protection1 != MessageProtections.None || protection2 != MessageProtections.None, "This comparison function should only be used to compare protection binding elements. Otherwise we change the order of user-defined message transformations.");
-
- // Now put the protection ones in the right order.
- return -((int)protection1).CompareTo((int)protection2); // descending flag ordinal order
- }
-
- /// <summary>
- /// Gets the protocol message that may be in the given HTTP response stream.
- /// </summary>
- /// <param name="responseStream">The response that is anticipated to contain an OAuth message.</param>
- /// <returns>The deserialized message, if one is found. Null otherwise.</returns>
- private IProtocolMessage ReadFromResponse(Stream responseStream) {
- IProtocolMessage message = this.ReadFromResponseInternal(responseStream);
- Logger.DebugFormat("Received message response: {0}", message);
- this.VerifyMessageAfterReceiving(message);
- return message;
- }
-
- /// <summary>
- /// Verifies the integrity and applicability of an incoming message.
- /// </summary>
- /// <param name="message">The message just received.</param>
- /// <exception cref="ProtocolException">
- /// Thrown when the message is somehow invalid.
- /// This can be due to tampering, replay attack or expiration, among other things.
- /// </exception>
- private void VerifyMessageAfterReceiving(IProtocolMessage message) {
- Debug.Assert(message != null, "message == null");
-
- MessageProtections appliedProtection = MessageProtections.None;
- foreach (IChannelBindingElement bindingElement in this.bindingElements.Reverse<IChannelBindingElement>()) {
- if (bindingElement.PrepareMessageForReceiving(message)) {
- appliedProtection |= bindingElement.Protection;
- }
- }
-
- // Ensure that the message's protection requirements have been satisfied.
- if ((message.RequiredProtection & appliedProtection) != message.RequiredProtection) {
- throw new UnprotectedMessageException(message, appliedProtection);
- }
-
- // We do NOT verify that all required message parts are present here... the
- // message deserializer did for us. It would be too late to do it here since
- // they might look initialized by the time we have an IProtocolMessage instance.
- message.EnsureValidMessage();
- }
- }
-}
diff --git a/src/DotNetOAuth/Messaging/ChannelEventArgs.cs b/src/DotNetOAuth/Messaging/ChannelEventArgs.cs
deleted file mode 100644
index 82506c3..0000000
--- a/src/DotNetOAuth/Messaging/ChannelEventArgs.cs
+++ /dev/null
@@ -1,31 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="ChannelEventArgs.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOAuth.Messaging {
- using System;
-
- /// <summary>
- /// The data packet sent with Channel events.
- /// </summary>
- public class ChannelEventArgs : EventArgs {
- /// <summary>
- /// Initializes a new instance of the <see cref="ChannelEventArgs"/> class.
- /// </summary>
- /// <param name="message">The message behind the fired event..</param>
- internal ChannelEventArgs(IProtocolMessage message) {
- if (message == null) {
- throw new ArgumentNullException("message");
- }
-
- this.Message = message;
- }
-
- /// <summary>
- /// Gets the message that caused the event to fire.
- /// </summary>
- public IProtocolMessage Message { get; private set; }
- }
-}
diff --git a/src/DotNetOAuth/Messaging/Exceptions.cd b/src/DotNetOAuth/Messaging/Exceptions.cd
deleted file mode 100644
index f0e527b..0000000
--- a/src/DotNetOAuth/Messaging/Exceptions.cd
+++ /dev/null
@@ -1,33 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<ClassDiagram MajorVersion="1" MinorVersion="1">
- <Class Name="DotNetOAuth.Messaging.ExpiredMessageException">
- <Position X="7.25" Y="2.25" Width="2" />
- <TypeIdentifier>
- <HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
- <FileName>Messaging\ExpiredMessageException.cs</FileName>
- </TypeIdentifier>
- </Class>
- <Class Name="DotNetOAuth.Messaging.ProtocolException" Collapsed="true">
- <Position X="9.75" Y="0.75" Width="1.5" />
- <TypeIdentifier>
- <HashCode>AAAKAAAAAAAAQAAAAIBAAAAACAAAAAAAAACAAAAAAAA=</HashCode>
- <FileName>Messaging\ProtocolException.cs</FileName>
- </TypeIdentifier>
- <Lollipop Position="0.2" />
- </Class>
- <Class Name="DotNetOAuth.Messaging.InvalidSignatureException" Collapsed="true">
- <Position X="9.5" Y="2.25" Width="2" />
- <TypeIdentifier>
- <HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
- <FileName>Messaging\InvalidSignatureException.cs</FileName>
- </TypeIdentifier>
- </Class>
- <Class Name="DotNetOAuth.Messaging.ReplayedMessageException" Collapsed="true">
- <Position X="11.75" Y="2.25" Width="2.25" />
- <TypeIdentifier>
- <HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
- <FileName>Messaging\ReplayedMessageException.cs</FileName>
- </TypeIdentifier>
- </Class>
- <Font Name="Segoe UI" Size="9" />
-</ClassDiagram> \ No newline at end of file
diff --git a/src/DotNetOAuth/Messaging/HttpDeliveryMethods.cs b/src/DotNetOAuth/Messaging/HttpDeliveryMethods.cs
deleted file mode 100644
index e0f26c0..0000000
--- a/src/DotNetOAuth/Messaging/HttpDeliveryMethods.cs
+++ /dev/null
@@ -1,43 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="HttpDeliveryMethods.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOAuth.Messaging {
- using System;
-
- /// <summary>
- /// The methods available for the Consumer to send direct messages to the Service Provider.
- /// </summary>
- /// <remarks>
- /// See 1.0 spec section 5.2.
- /// </remarks>
- [Flags]
- public enum HttpDeliveryMethods {
- /// <summary>
- /// No HTTP methods are allowed.
- /// </summary>
- None = 0x0,
-
- /// <summary>
- /// In the HTTP Authorization header as defined in OAuth HTTP Authorization Scheme (OAuth HTTP Authorization Scheme).
- /// </summary>
- AuthorizationHeaderRequest = 0x1,
-
- /// <summary>
- /// As the HTTP POST request body with a content-type of application/x-www-form-urlencoded.
- /// </summary>
- PostRequest = 0x2,
-
- /// <summary>
- /// Added to the URLs in the query part (as defined by [RFC3986] (Berners-Lee, T., “Uniform Resource Identifiers (URI): Generic Syntax,” .) section 3).
- /// </summary>
- GetRequest = 0x4,
-
- /// <summary>
- /// All HTTP requests are acceptable.
- /// </summary>
- All = AuthorizationHeaderRequest | PostRequest | GetRequest,
- }
-}
diff --git a/src/DotNetOAuth/Messaging/HttpRequestInfo.cs b/src/DotNetOAuth/Messaging/HttpRequestInfo.cs
deleted file mode 100644
index 3b037c6..0000000
--- a/src/DotNetOAuth/Messaging/HttpRequestInfo.cs
+++ /dev/null
@@ -1,180 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="HttpRequestInfo.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOAuth.Messaging {
- using System;
- using System.Collections.Specialized;
- using System.Diagnostics;
- using System.IO;
- using System.Net;
- using System.ServiceModel.Channels;
- using System.Web;
-
- /// <summary>
- /// A property store of details of an incoming HTTP request.
- /// </summary>
- /// <remarks>
- /// This serves a very similar purpose to <see cref="HttpRequest"/>, except that
- /// ASP.NET does not let us fully initialize that class, so we have to write one
- /// of our one.
- /// </remarks>
- public class HttpRequestInfo {
- /// <summary>
- /// The key/value pairs found in the entity of a POST request.
- /// </summary>
- private NameValueCollection form;
-
- /// <summary>
- /// The key/value pairs found in the querystring of the incoming request.
- /// </summary>
- private NameValueCollection queryString;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="HttpRequestInfo"/> class.
- /// </summary>
- internal HttpRequestInfo() {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="HttpRequestInfo"/> class.
- /// </summary>
- /// <param name="request">The ASP.NET structure to copy from.</param>
- internal HttpRequestInfo(HttpRequest request) {
- if (request == null) {
- throw new ArgumentNullException("request");
- }
-
- this.HttpMethod = request.HttpMethod;
- this.Url = request.Url;
- this.Headers = GetHeaderCollection(request.Headers);
- this.InputStream = request.InputStream;
-
- // These values would normally be calculated, but we'll reuse them from
- // HttpRequest since they're already calculated, and there's a chance (<g>)
- // that ASP.NET does a better job of being comprehensive about gathering
- // these as well.
- this.form = request.Form;
- this.queryString = request.QueryString;
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="HttpRequestInfo"/> class.
- /// </summary>
- /// <param name="request">The WCF incoming request structure to get the HTTP information from.</param>
- /// <param name="requestUri">The URI of the service endpoint.</param>
- internal HttpRequestInfo(HttpRequestMessageProperty request, Uri requestUri) {
- if (request == null) {
- throw new ArgumentNullException("request");
- }
-
- this.HttpMethod = request.Method;
- this.Headers = request.Headers;
- this.Url = requestUri;
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="HttpRequestInfo"/> class.
- /// </summary>
- /// <param name="request">The HttpWebRequest (that was never used) to copy from.</param>
- internal HttpRequestInfo(WebRequest request) {
- this.HttpMethod = request.Method;
- this.Url = request.RequestUri;
- this.Headers = GetHeaderCollection(request.Headers);
- this.InputStream = null;
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="HttpRequestInfo"/> class.
- /// </summary>
- /// <param name="message">The message being passed in through a mock transport.</param>
- internal HttpRequestInfo(IProtocolMessage message) {
- this.Message = message;
- }
-
- /// <summary>
- /// Gets or sets the message that is being sent over a mock transport (for testing).
- /// </summary>
- internal IProtocolMessage Message { get; set; }
-
- /// <summary>
- /// Gets or sets the verb in the request (i.e. GET, POST, etc.)
- /// </summary>
- internal string HttpMethod { get; set; }
-
- /// <summary>
- /// Gets or sets the entire URL of the request.
- /// </summary>
- internal Uri Url { get; set; }
-
- /// <summary>
- /// Gets the query part of the URL (The ? and everything after it).
- /// </summary>
- internal string Query {
- get { return this.Url != null ? this.Url.Query : null; }
- }
-
- /// <summary>
- /// Gets or sets the collection of headers that came in with the request.
- /// </summary>
- internal WebHeaderCollection Headers { get; set; }
-
- /// <summary>
- /// Gets or sets the entity, or body of the request, if any.
- /// </summary>
- internal Stream InputStream { get; set; }
-
- /// <summary>
- /// Gets the key/value pairs found in the entity of a POST request.
- /// </summary>
- internal NameValueCollection Form {
- get {
- if (this.form == null) {
- if (this.HttpMethod == "POST" && this.Headers[HttpRequestHeader.ContentType] == "application/x-www-form-urlencoded") {
- StreamReader reader = new StreamReader(this.InputStream);
- long originalPosition = this.InputStream.Position;
- this.form = HttpUtility.ParseQueryString(reader.ReadToEnd());
- if (this.InputStream.CanSeek) {
- this.InputStream.Seek(originalPosition, SeekOrigin.Begin);
- }
- } else {
- this.form = new NameValueCollection();
- }
- }
-
- return this.form;
- }
- }
-
- /// <summary>
- /// Gets the key/value pairs found in the querystring of the incoming request.
- /// </summary>
- internal NameValueCollection QueryString {
- get {
- if (this.queryString == null) {
- this.queryString = HttpUtility.ParseQueryString(this.Query);
- }
-
- return this.queryString;
- }
- }
-
- /// <summary>
- /// Converts a NameValueCollection to a WebHeaderCollection.
- /// </summary>
- /// <param name="pairs">The collection a HTTP headers.</param>
- /// <returns>A new collection of the given headers.</returns>
- private static WebHeaderCollection GetHeaderCollection(NameValueCollection pairs) {
- Debug.Assert(pairs != null, "pairs == null");
-
- WebHeaderCollection headers = new WebHeaderCollection();
- foreach (string key in pairs) {
- headers.Add(key, pairs[key]);
- }
-
- return headers;
- }
- }
-}
diff --git a/src/DotNetOAuth/Messaging/IChannelBindingElement.cs b/src/DotNetOAuth/Messaging/IChannelBindingElement.cs
deleted file mode 100644
index a11509d..0000000
--- a/src/DotNetOAuth/Messaging/IChannelBindingElement.cs
+++ /dev/null
@@ -1,48 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="IChannelBindingElement.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOAuth.Messaging {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
-
- /// <summary>
- /// An interface that must be implemented by message transforms/validators in order
- /// to be included in the channel stack.
- /// </summary>
- public interface IChannelBindingElement {
- /// <summary>
- /// Gets the protection offered (if any) by this binding element.
- /// </summary>
- MessageProtections Protection { get; }
-
- /// <summary>
- /// Prepares a message for sending based on the rules of this channel binding element.
- /// </summary>
- /// <param name="message">The message to prepare for sending.</param>
- /// <returns>
- /// True if the <paramref name="message"/> applied to this binding element
- /// and the operation was successful. False otherwise.
- /// </returns>
- bool PrepareMessageForSending(IProtocolMessage message);
-
- /// <summary>
- /// Performs any transformation on an incoming message that may be necessary and/or
- /// validates an incoming message based on the rules of this channel binding element.
- /// </summary>
- /// <param name="message">The incoming message to process.</param>
- /// <returns>
- /// True if the <paramref name="message"/> applied to this binding element
- /// and the operation was successful. False if the operation did not apply to this message.
- /// </returns>
- /// <exception cref="ProtocolException">
- /// Thrown when the binding element rules indicate that this message is invalid and should
- /// NOT be processed.
- /// </exception>
- bool PrepareMessageForReceiving(IProtocolMessage message);
- }
-}
diff --git a/src/DotNetOAuth/Messaging/IDirectedProtocolMessage.cs b/src/DotNetOAuth/Messaging/IDirectedProtocolMessage.cs
deleted file mode 100644
index 8479fef..0000000
--- a/src/DotNetOAuth/Messaging/IDirectedProtocolMessage.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="IDirectedProtocolMessage.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOAuth.Messaging {
- using System;
-
- /// <summary>
- /// Implemented by messages that have explicit recipients
- /// (direct requests and all indirect messages).
- /// </summary>
- public interface IDirectedProtocolMessage : IProtocolMessage {
- /// <summary>
- /// Gets the URL of the intended receiver of this message.
- /// </summary>
- Uri Recipient { get; }
- }
-}
diff --git a/src/DotNetOAuth/Messaging/IMessageTypeProvider.cs b/src/DotNetOAuth/Messaging/IMessageTypeProvider.cs
deleted file mode 100644
index afc0b04..0000000
--- a/src/DotNetOAuth/Messaging/IMessageTypeProvider.cs
+++ /dev/null
@@ -1,41 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="IMessageTypeProvider.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOAuth.Messaging {
- using System;
- using System.Collections.Generic;
-
- /// <summary>
- /// A tool to analyze an incoming message to figure out what concrete class
- /// is designed to deserialize it.
- /// </summary>
- public interface IMessageTypeProvider {
- /// <summary>
- /// Analyzes an incoming request message payload to discover what kind of
- /// message is embedded in it and returns the type, or null if no match is found.
- /// </summary>
- /// <param name="fields">The name/value pairs that make up the message payload.</param>
- /// <returns>
- /// The <see cref="IProtocolMessage"/>-derived concrete class that this message can
- /// deserialize to. Null if the request isn't recognized as a valid protocol message.
- /// </returns>
- Type GetRequestMessageType(IDictionary<string, string> fields);
-
- /// <summary>
- /// Analyzes an incoming request message payload to discover what kind of
- /// message is embedded in it and returns the type, or null if no match is found.
- /// </summary>
- /// <param name="request">
- /// The message that was sent as a request that resulted in the response.
- /// </param>
- /// <param name="fields">The name/value pairs that make up the message payload.</param>
- /// <returns>
- /// The <see cref="IProtocolMessage"/>-derived concrete class that this message can
- /// deserialize to. Null if the request isn't recognized as a valid protocol message.
- /// </returns>
- Type GetResponseMessageType(IProtocolMessage request, IDictionary<string, string> fields);
- }
-}
diff --git a/src/DotNetOAuth/Messaging/IProtocolMessage.cs b/src/DotNetOAuth/Messaging/IProtocolMessage.cs
deleted file mode 100644
index 25779f9..0000000
--- a/src/DotNetOAuth/Messaging/IProtocolMessage.cs
+++ /dev/null
@@ -1,54 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="IProtocolMessage.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOAuth.Messaging {
- using System;
- using System.Collections.Generic;
- using System.Text;
-
- /// <summary>
- /// The interface that classes must implement to be serialized/deserialized
- /// as OAuth messages.
- /// </summary>
- public interface IProtocolMessage {
- /// <summary>
- /// Gets the version of the protocol this message is prepared to implement.
- /// </summary>
- Version ProtocolVersion { get; }
-
- /// <summary>
- /// Gets the level of protection this message requires.
- /// </summary>
- MessageProtections RequiredProtection { get; }
-
- /// <summary>
- /// Gets a value indicating whether this is a direct or indirect message.
- /// </summary>
- MessageTransport Transport { get; }
-
- /// <summary>
- /// Gets the extra, non-OAuth parameters included in the message.
- /// </summary>
- /// <remarks>
- /// Implementations of this interface should ensure that this property never returns null.
- /// </remarks>
- IDictionary<string, string> ExtraData { get; }
-
- /// <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 EnsureValidMessage();
- }
-}
diff --git a/src/DotNetOAuth/Messaging/ITamperProtectionChannelBindingElement.cs b/src/DotNetOAuth/Messaging/ITamperProtectionChannelBindingElement.cs
deleted file mode 100644
index 03478c3..0000000
--- a/src/DotNetOAuth/Messaging/ITamperProtectionChannelBindingElement.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="ITamperProtectionChannelBindingElement.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOAuth.Messaging {
- using System;
- using DotNetOAuth.OAuth.ChannelElements;
-
- /// <summary>
- /// An interface that must be implemented by message transforms/validators in order
- /// to be included in the channel stack.
- /// </summary>
- public interface ITamperProtectionChannelBindingElement : IChannelBindingElement {
- /// <summary>
- /// Gets or sets the delegate that will initialize the non-serialized properties necessary on a
- /// signable message so that its signature can be correctly calculated or verified.
- /// </summary>
- Action<ITamperResistantOAuthMessage> SignatureCallback { get; set; }
-
- /// <summary>
- /// Clones this instance.
- /// </summary>
- /// <returns>The cloned instance.</returns>
- ITamperProtectionChannelBindingElement Clone();
- }
-}
diff --git a/src/DotNetOAuth/Messaging/ITamperResistantProtocolMessage.cs b/src/DotNetOAuth/Messaging/ITamperResistantProtocolMessage.cs
deleted file mode 100644
index 0b6b0d1..0000000
--- a/src/DotNetOAuth/Messaging/ITamperResistantProtocolMessage.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="ITamperResistantProtocolMessage.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOAuth.Messaging {
- /// <summary>
- /// The contract a message that is signed must implement.
- /// </summary>
- /// <remarks>
- /// This type might have appeared in the DotNetOAuth.Messaging.Bindings namespace since
- /// it is only used by types in that namespace, but all those types are internal and this
- /// is the only one that was public.
- /// </remarks>
- public interface ITamperResistantProtocolMessage : IProtocolMessage {
- /// <summary>
- /// Gets or sets the message signature.
- /// </summary>
- string Signature { get; set; }
- }
-}
diff --git a/src/DotNetOAuth/Messaging/MessagePartAttribute.cs b/src/DotNetOAuth/Messaging/MessagePartAttribute.cs
deleted file mode 100644
index 2e089c2..0000000
--- a/src/DotNetOAuth/Messaging/MessagePartAttribute.cs
+++ /dev/null
@@ -1,57 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="MessagePartAttribute.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOAuth.Messaging {
- using System;
- using System.Net.Security;
- using System.Reflection;
-
- /// <summary>
- /// Applied to fields and properties that form a key/value in a protocol message.
- /// </summary>
- [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, Inherited = true, AllowMultiple = false)]
- public sealed class MessagePartAttribute : Attribute {
- /// <summary>
- /// The overridden name to use as the serialized name for the property.
- /// </summary>
- private string name;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="MessagePartAttribute"/> class.
- /// </summary>
- public MessagePartAttribute() {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="MessagePartAttribute"/> class.
- /// </summary>
- /// <param name="name">
- /// A special name to give the value of this member in the serialized message.
- /// When null or empty, the name of the member will be used in the serialized message.
- /// </param>
- public MessagePartAttribute(string name) {
- this.Name = name;
- }
-
- /// <summary>
- /// Gets the name of the serialized form of this member in the message.
- /// </summary>
- public string Name {
- get { return this.name; }
- private set { this.name = string.IsNullOrEmpty(value) ? null : value; }
- }
-
- /// <summary>
- /// Gets or sets the level of protection required by this member in the serialized message.
- /// </summary>
- public ProtectionLevel RequiredProtection { get; set; }
-
- /// <summary>
- /// Gets or sets a value indicating whether this member is a required part of the serialized message.
- /// </summary>
- public bool IsRequired { get; set; }
- }
-}
diff --git a/src/DotNetOAuth/Messaging/MessageProtections.cs b/src/DotNetOAuth/Messaging/MessageProtections.cs
deleted file mode 100644
index 29b60b7..0000000
--- a/src/DotNetOAuth/Messaging/MessageProtections.cs
+++ /dev/null
@@ -1,46 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="MessageProtections.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOAuth.Messaging {
- using System;
-
- /// <summary>
- /// Categorizes the various types of channel binding elements so they can be properly ordered.
- /// </summary>
- /// <remarks>
- /// The order of these enum values is significant.
- /// Each successive value requires the protection offered by all the previous values
- /// in order to be reliable. For example, message expiration is meaningless without
- /// tamper protection to prevent a user from changing the timestamp on a message.
- /// </remarks>
- [Flags]
- public enum MessageProtections {
- /// <summary>
- /// No protection.
- /// </summary>
- None = 0x0,
-
- /// <summary>
- /// A binding element that signs a message before sending and validates its signature upon receiving.
- /// </summary>
- TamperProtection = 0x1,
-
- /// <summary>
- /// A binding element that enforces a maximum message age between sending and processing on the receiving side.
- /// </summary>
- Expiration = 0x2,
-
- /// <summary>
- /// A binding element that prepares messages for replay detection and detects replayed messages on the receiving side.
- /// </summary>
- ReplayProtection = 0x4,
-
- /// <summary>
- /// All forms of protection together.
- /// </summary>
- All = TamperProtection | Expiration | ReplayProtection,
- }
-} \ No newline at end of file
diff --git a/src/DotNetOAuth/Messaging/MessageReceivingEndpoint.cs b/src/DotNetOAuth/Messaging/MessageReceivingEndpoint.cs
deleted file mode 100644
index 2236dd1..0000000
--- a/src/DotNetOAuth/Messaging/MessageReceivingEndpoint.cs
+++ /dev/null
@@ -1,54 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="MessageReceivingEndpoint.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOAuth.Messaging {
- using System;
- using System.Diagnostics;
-
- /// <summary>
- /// An immutable description of a URL that receives messages.
- /// </summary>
- [DebuggerDisplay("{AllowedMethods} {Location}")]
- public class MessageReceivingEndpoint {
- /// <summary>
- /// Initializes a new instance of the <see cref="MessageReceivingEndpoint"/> class.
- /// </summary>
- /// <param name="locationUri">The URL of this endpoint.</param>
- /// <param name="method">The HTTP method(s) allowed.</param>
- public MessageReceivingEndpoint(string locationUri, HttpDeliveryMethods method)
- : this(new Uri(locationUri), method) { }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="MessageReceivingEndpoint"/> class.
- /// </summary>
- /// <param name="location">The URL of this endpoint.</param>
- /// <param name="method">The HTTP method(s) allowed.</param>
- public MessageReceivingEndpoint(Uri location, HttpDeliveryMethods method) {
- if (location == null) {
- throw new ArgumentNullException("location");
- }
- if (method == HttpDeliveryMethods.None) {
- throw new ArgumentOutOfRangeException("method");
- }
- if ((method & (HttpDeliveryMethods.PostRequest | HttpDeliveryMethods.GetRequest)) == 0) {
- throw new ArgumentOutOfRangeException("method", MessagingStrings.GetOrPostFlagsRequired);
- }
-
- this.Location = location;
- this.AllowedMethods = method;
- }
-
- /// <summary>
- /// Gets the URL of this endpoint.
- /// </summary>
- public Uri Location { get; private set; }
-
- /// <summary>
- /// Gets the HTTP method(s) allowed.
- /// </summary>
- public HttpDeliveryMethods AllowedMethods { get; private set; }
- }
-}
diff --git a/src/DotNetOAuth/Messaging/MessageSerializer.cs b/src/DotNetOAuth/Messaging/MessageSerializer.cs
deleted file mode 100644
index 837b582..0000000
--- a/src/DotNetOAuth/Messaging/MessageSerializer.cs
+++ /dev/null
@@ -1,136 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="MessageSerializer.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOAuth.Messaging {
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Globalization;
- using System.Reflection;
- using DotNetOAuth.Messaging.Reflection;
- using DotNetOAuth.OAuth.ChannelElements;
-
- /// <summary>
- /// Serializes/deserializes OAuth messages for/from transit.
- /// </summary>
- internal class MessageSerializer {
- /// <summary>
- /// The specific <see cref="IProtocolMessage"/>-derived type
- /// that will be serialized and deserialized using this class.
- /// </summary>
- private readonly Type messageType;
-
- /// <summary>
- /// Initializes a new instance of the MessageSerializer class.
- /// </summary>
- /// <param name="messageType">The specific <see cref="IProtocolMessage"/>-derived type
- /// that will be serialized and deserialized using this class.</param>
- private MessageSerializer(Type messageType) {
- Debug.Assert(messageType != null, "messageType == null");
-
- if (!typeof(IProtocolMessage).IsAssignableFrom(messageType)) {
- throw new ArgumentException(
- string.Format(
- CultureInfo.CurrentCulture,
- MessagingStrings.UnexpectedType,
- typeof(IProtocolMessage).FullName,
- messageType.FullName),
- "messageType");
- }
-
- this.messageType = messageType;
- }
-
- /// <summary>
- /// Creates or reuses a message serializer for a given message type.
- /// </summary>
- /// <param name="messageType">The type of message that will be serialized/deserialized.</param>
- /// <returns>A message serializer for the given message type.</returns>
- internal static MessageSerializer Get(Type messageType) {
- if (messageType == null) {
- throw new ArgumentNullException("messageType");
- }
-
- return new MessageSerializer(messageType);
- }
-
- /// <summary>
- /// Reads the data from a message instance and returns a series of name=value pairs for the fields that must be included in the message.
- /// </summary>
- /// <param name="message">The message to be serialized.</param>
- /// <returns>The dictionary of values to send for the message.</returns>
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "Parallel design with Deserialize method.")]
- internal IDictionary<string, string> Serialize(IProtocolMessage message) {
- if (message == null) {
- throw new ArgumentNullException("message");
- }
-
- var result = new Reflection.MessageDictionary(message);
-
- return result;
- }
-
- /// <summary>
- /// Reads name=value pairs into an OAuth message.
- /// </summary>
- /// <param name="fields">The name=value pairs that were read in from the transport.</param>
- /// <param name="recipient">The recipient of the message.</param>
- /// <returns>The instantiated and initialized <see cref="IProtocolMessage"/> instance.</returns>
- internal IProtocolMessage Deserialize(IDictionary<string, string> fields, MessageReceivingEndpoint recipient) {
- if (fields == null) {
- throw new ArgumentNullException("fields");
- }
-
- // Before we deserialize the message, make sure all the required parts are present.
- MessageDescription.Get(this.messageType).EnsureRequiredMessagePartsArePresent(fields.Keys);
-
- IProtocolMessage result = this.CreateMessage(recipient);
- foreach (var pair in fields) {
- IDictionary<string, string> dictionary = new MessageDictionary(result);
- dictionary[pair.Key] = pair.Value;
- }
- result.EnsureValidMessage();
- return result;
- }
-
- /// <summary>
- /// Instantiates a new message to deserialize data into.
- /// </summary>
- /// <param name="recipient">The recipient this message is directed to, if any.</param>
- /// <returns>The newly created message object.</returns>
- private IProtocolMessage CreateMessage(MessageReceivingEndpoint recipient) {
- IProtocolMessage result;
- BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
- if (typeof(IOAuthDirectedMessage).IsAssignableFrom(this.messageType)) {
- // Some OAuth messages take just the recipient, while others take the whole endpoint
- ConstructorInfo ctor;
- if ((ctor = this.messageType.GetConstructor(bindingFlags, null, new Type[] { typeof(Uri) }, null)) != null) {
- if (recipient == null) {
- // We need a recipient to deserialize directed messages.
- throw new ArgumentNullException("recipient");
- }
-
- result = (IProtocolMessage)ctor.Invoke(new object[] { recipient.Location });
- } else if ((ctor = this.messageType.GetConstructor(bindingFlags, null, new Type[] { typeof(MessageReceivingEndpoint) }, null)) != null) {
- if (recipient == null) {
- // We need a recipient to deserialize directed messages.
- throw new ArgumentNullException("recipient");
- }
-
- result = (IProtocolMessage)ctor.Invoke(new object[] { recipient });
- } else if ((ctor = this.messageType.GetConstructor(bindingFlags, null, new Type[0], null)) != null) {
- result = (IProtocolMessage)ctor.Invoke(new object[0]);
- } else {
- throw new InvalidOperationException("Unrecognized constructor signature on type " + this.messageType);
- }
- } else {
- result = (IProtocolMessage)Activator.CreateInstance(this.messageType, true);
- }
-
- return result;
- }
- }
-}
diff --git a/src/DotNetOAuth/Messaging/MessageTransport.cs b/src/DotNetOAuth/Messaging/MessageTransport.cs
deleted file mode 100644
index 40e6897..0000000
--- a/src/DotNetOAuth/Messaging/MessageTransport.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="MessageTransport.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOAuth.Messaging {
- /// <summary>
- /// The type of transport mechanism used for a message: either direct or indirect.
- /// </summary>
- public enum MessageTransport {
- /// <summary>
- /// A message that is sent directly from the Consumer to the Service Provider, or vice versa.
- /// </summary>
- Direct,
-
- /// <summary>
- /// A message that is sent from one party to another via a redirect in the user agent.
- /// </summary>
- Indirect,
- }
-}
diff --git a/src/DotNetOAuth/Messaging/Messaging.cd b/src/DotNetOAuth/Messaging/Messaging.cd
deleted file mode 100644
index 48106a8..0000000
--- a/src/DotNetOAuth/Messaging/Messaging.cd
+++ /dev/null
@@ -1,62 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<ClassDiagram MajorVersion="1" MinorVersion="1" GroupingSetting="Access">
- <Class Name="DotNetOAuth.Messaging.Channel">
- <Position X="5.25" Y="0.75" Width="1.75" />
- <Compartments>
- <Compartment Name="Protected" Collapsed="true" />
- <Compartment Name="Internal" Collapsed="true" />
- <Compartment Name="Private" Collapsed="true" />
- <Compartment Name="Fields" Collapsed="true" />
- </Compartments>
- <TypeIdentifier>
- <HashCode>gBgQgAIAAQAEAIgAAEAAAARBIAAQgAAQEEAAAABAMAA=</HashCode>
- <FileName>Messaging\Channel.cs</FileName>
- </TypeIdentifier>
- <ShowAsCollectionAssociation>
- <Property Name="BindingElements" />
- </ShowAsCollectionAssociation>
- </Class>
- <Interface Name="DotNetOAuth.Messaging.IChannelBindingElement">
- <Position X="1.75" Y="1.5" Width="2.25" />
- <TypeIdentifier>
- <HashCode>BAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAEAAAAAAAAA=</HashCode>
- <FileName>Messaging\IChannelBindingElement.cs</FileName>
- </TypeIdentifier>
- <ShowAsAssociation>
- <Property Name="Protection" />
- </ShowAsAssociation>
- </Interface>
- <Interface Name="DotNetOAuth.Messaging.IProtocolMessage">
- <Position X="5.25" Y="3.5" Width="1.75" />
- <TypeIdentifier>
- <HashCode>AAAAAAAAQAAAAAAAAAAAAAYAAAAAAAAAAAACAAAAAAA=</HashCode>
- <FileName>Messaging\IProtocolMessage.cs</FileName>
- </TypeIdentifier>
- <ShowAsAssociation>
- <Property Name="RequiredProtection" />
- <Property Name="Transport" />
- </ShowAsAssociation>
- </Interface>
- <Interface Name="DotNetOAuth.Messaging.IDirectedProtocolMessage">
- <Position X="5" Y="5.25" Width="2.25" />
- <TypeIdentifier>
- <HashCode>AAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
- <FileName>Messaging\IDirectedProtocolMessage.cs</FileName>
- </TypeIdentifier>
- </Interface>
- <Enum Name="DotNetOAuth.Messaging.MessageProtection">
- <Position X="2" Y="3.5" Width="1.75" />
- <TypeIdentifier>
- <HashCode>AIAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAEAAAA=</HashCode>
- <FileName>Messaging\MessageProtection.cs</FileName>
- </TypeIdentifier>
- </Enum>
- <Enum Name="DotNetOAuth.Messaging.MessageTransport">
- <Position X="8" Y="3.5" Width="1.5" />
- <TypeIdentifier>
- <HashCode>AAACAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
- <FileName>Messaging\MessageTransport.cs</FileName>
- </TypeIdentifier>
- </Enum>
- <Font Name="Segoe UI" Size="9" />
-</ClassDiagram> \ No newline at end of file
diff --git a/src/DotNetOAuth/Messaging/MessagingStrings.Designer.cs b/src/DotNetOAuth/Messaging/MessagingStrings.Designer.cs
deleted file mode 100644
index c002ecd..0000000
--- a/src/DotNetOAuth/Messaging/MessagingStrings.Designer.cs
+++ /dev/null
@@ -1,351 +0,0 @@
-//------------------------------------------------------------------------------
-// <auto-generated>
-// This code was generated by a tool.
-// Runtime Version:2.0.50727.3053
-//
-// Changes to this file may cause incorrect behavior and will be lost if
-// the code is regenerated.
-// </auto-generated>
-//------------------------------------------------------------------------------
-
-namespace DotNetOAuth.Messaging {
- using System;
-
-
- /// <summary>
- /// A strongly-typed resource class, for looking up localized strings, etc.
- /// </summary>
- // This class was auto-generated by the StronglyTypedResourceBuilder
- // class via a tool like ResGen or Visual Studio.
- // To add or remove a member, edit your .ResX file then rerun ResGen
- // with the /str option, or rebuild your VS project.
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
- internal class MessagingStrings {
-
- private static global::System.Resources.ResourceManager resourceMan;
-
- private static global::System.Globalization.CultureInfo resourceCulture;
-
- [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
- internal MessagingStrings() {
- }
-
- /// <summary>
- /// Returns the cached ResourceManager instance used by this class.
- /// </summary>
- [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
- internal static global::System.Resources.ResourceManager ResourceManager {
- get {
- if (object.ReferenceEquals(resourceMan, null)) {
- global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DotNetOAuth.Messaging.MessagingStrings", typeof(MessagingStrings).Assembly);
- resourceMan = temp;
- }
- return resourceMan;
- }
- }
-
- /// <summary>
- /// Overrides the current thread's CurrentUICulture property for all
- /// resource lookups using this strongly typed resource class.
- /// </summary>
- [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
- internal static global::System.Globalization.CultureInfo Culture {
- get {
- return resourceCulture;
- }
- set {
- resourceCulture = value;
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to Argument&apos;s {0}.{1} property is required but is empty or null..
- /// </summary>
- internal static string ArgumentPropertyMissing {
- get {
- return ResourceManager.GetString("ArgumentPropertyMissing", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to HttpContext.Current is null. There must be an ASP.NET request in process for this operation to succeed..
- /// </summary>
- internal static string CurrentHttpContextRequired {
- get {
- return ResourceManager.GetString("CurrentHttpContextRequired", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to DataContractSerializer could not be initialized on message type {0}. Is it missing a [DataContract] attribute?.
- /// </summary>
- internal static string DataContractMissingFromMessageType {
- get {
- return ResourceManager.GetString("DataContractMissingFromMessageType", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to DataContractSerializer could not be initialized on message type {0} because the DataContractAttribute.Namespace property is not set..
- /// </summary>
- internal static string DataContractMissingNamespace {
- get {
- return ResourceManager.GetString("DataContractMissingNamespace", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to An instance of type {0} was expected, but received unexpected derived type {1}..
- /// </summary>
- internal static string DerivedTypeNotExpected {
- get {
- return ResourceManager.GetString("DerivedTypeNotExpected", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to The directed message&apos;s Recipient property must not be null..
- /// </summary>
- internal static string DirectedMessageMissingRecipient {
- get {
- return ResourceManager.GetString("DirectedMessageMissingRecipient", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to Error occurred while sending a direct message or getting the response..
- /// </summary>
- internal static string ErrorInRequestReplyMessage {
- get {
- return ResourceManager.GetString("ErrorInRequestReplyMessage", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to This exception was not constructed with a root request message that caused it..
- /// </summary>
- internal static string ExceptionNotConstructedForTransit {
- get {
- return ResourceManager.GetString("ExceptionNotConstructedForTransit", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to Expected message {0} but received no recognizable message..
- /// </summary>
- internal static string ExpectedMessageNotReceived {
- get {
- return ResourceManager.GetString("ExpectedMessageNotReceived", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to The message expired at {0} and it is now {1}..
- /// </summary>
- internal static string ExpiredMessage {
- get {
- return ResourceManager.GetString("ExpiredMessage", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to At least one of GET or POST flags must be present..
- /// </summary>
- internal static string GetOrPostFlagsRequired {
- get {
- return ResourceManager.GetString("GetOrPostFlagsRequired", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to This method requires a current HttpContext. Alternatively, use an overload of this method that allows you to pass in information without an HttpContext..
- /// </summary>
- internal static string HttpContextRequired {
- get {
- return ResourceManager.GetString("HttpContextRequired", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to Messages that indicate indirect transport must implement the {0} interface..
- /// </summary>
- internal static string IndirectMessagesMustImplementIDirectedProtocolMessage {
- get {
- return ResourceManager.GetString("IndirectMessagesMustImplementIDirectedProtocolMessage", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to The message required protections {0} but the channel could only apply {1}..
- /// </summary>
- internal static string InsufficentMessageProtection {
- get {
- return ResourceManager.GetString("InsufficentMessageProtection", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to Some part(s) of the message have invalid values: {0}.
- /// </summary>
- internal static string InvalidMessageParts {
- get {
- return ResourceManager.GetString("InvalidMessageParts", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to The incoming message had an invalid or missing nonce..
- /// </summary>
- internal static string InvalidNonceReceived {
- get {
- return ResourceManager.GetString("InvalidNonceReceived", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to An item with the same key has already been added..
- /// </summary>
- internal static string KeyAlreadyExists {
- get {
- return ResourceManager.GetString("KeyAlreadyExists", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to A message response is already queued for sending in the response stream..
- /// </summary>
- internal static string QueuedMessageResponseAlreadyExists {
- get {
- return ResourceManager.GetString("QueuedMessageResponseAlreadyExists", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to This message has already been processed. This could indicate a replay attack in progress..
- /// </summary>
- internal static string ReplayAttackDetected {
- get {
- return ResourceManager.GetString("ReplayAttackDetected", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to This channel does not support replay protection..
- /// </summary>
- internal static string ReplayProtectionNotSupported {
- get {
- return ResourceManager.GetString("ReplayProtectionNotSupported", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to The following required parameters were missing from the {0} message: {1}.
- /// </summary>
- internal static string RequiredParametersMissing {
- get {
- return ResourceManager.GetString("RequiredParametersMissing", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to The binding element offering the {0} protection requires other protection that is not provided..
- /// </summary>
- internal static string RequiredProtectionMissing {
- get {
- return ResourceManager.GetString("RequiredProtectionMissing", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to The list is empty..
- /// </summary>
- internal static string SequenceContainsNoElements {
- get {
- return ResourceManager.GetString("SequenceContainsNoElements", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to The list contains a null element..
- /// </summary>
- internal static string SequenceContainsNullElement {
- get {
- return ResourceManager.GetString("SequenceContainsNullElement", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to Message signature was incorrect..
- /// </summary>
- internal static string SignatureInvalid {
- get {
- return ResourceManager.GetString("SignatureInvalid", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to This channel does not support signing messages. To support signing messages, a derived Channel type must override the Sign and IsSignatureValid methods..
- /// </summary>
- internal static string SigningNotSupported {
- get {
- return ResourceManager.GetString("SigningNotSupported", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to The stream&apos;s CanRead property returned false..
- /// </summary>
- internal static string StreamUnreadable {
- get {
- return ResourceManager.GetString("StreamUnreadable", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to The stream&apos;s CanWrite property returned false..
- /// </summary>
- internal static string StreamUnwritable {
- get {
- return ResourceManager.GetString("StreamUnwritable", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to Expected at most 1 binding element offering the {0} protection, but found {1}..
- /// </summary>
- internal static string TooManyBindingsOfferingSameProtection {
- get {
- return ResourceManager.GetString("TooManyBindingsOfferingSameProtection", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to Expected message {0} but received {1} instead..
- /// </summary>
- internal static string UnexpectedMessageReceived {
- get {
- return ResourceManager.GetString("UnexpectedMessageReceived", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to The type {0} or a derived type was expected, but {1} was given..
- /// </summary>
- internal static string UnexpectedType {
- get {
- return ResourceManager.GetString("UnexpectedType", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to {0} property has unrecognized value {1}..
- /// </summary>
- internal static string UnrecognizedEnumValue {
- get {
- return ResourceManager.GetString("UnrecognizedEnumValue", resourceCulture);
- }
- }
- }
-}
diff --git a/src/DotNetOAuth/Messaging/MessagingStrings.resx b/src/DotNetOAuth/Messaging/MessagingStrings.resx
deleted file mode 100644
index 255938c..0000000
--- a/src/DotNetOAuth/Messaging/MessagingStrings.resx
+++ /dev/null
@@ -1,216 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<root>
- <!--
- Microsoft ResX Schema
-
- Version 2.0
-
- The primary goals of this format is to allow a simple XML format
- that is mostly human readable. The generation and parsing of the
- various data types are done through the TypeConverter classes
- associated with the data types.
-
- Example:
-
- ... ado.net/XML headers & schema ...
- <resheader name="resmimetype">text/microsoft-resx</resheader>
- <resheader name="version">2.0</resheader>
- <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
- <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
- <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
- <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
- <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
- <value>[base64 mime encoded serialized .NET Framework object]</value>
- </data>
- <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
- <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
- <comment>This is a comment</comment>
- </data>
-
- There are any number of "resheader" rows that contain simple
- name/value pairs.
-
- Each data row contains a name, and value. The row also contains a
- type or mimetype. Type corresponds to a .NET class that support
- text/value conversion through the TypeConverter architecture.
- Classes that don't support this are serialized and stored with the
- mimetype set.
-
- The mimetype is used for serialized objects, and tells the
- ResXResourceReader how to depersist the object. This is currently not
- extensible. For a given mimetype the value must be set accordingly:
-
- Note - application/x-microsoft.net.object.binary.base64 is the format
- that the ResXResourceWriter will generate, however the reader can
- read any of the formats listed below.
-
- mimetype: application/x-microsoft.net.object.binary.base64
- value : The object must be serialized with
- : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
- : and then encoded with base64 encoding.
-
- mimetype: application/x-microsoft.net.object.soap.base64
- value : The object must be serialized with
- : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
- : and then encoded with base64 encoding.
-
- mimetype: application/x-microsoft.net.object.bytearray.base64
- value : The object must be serialized into a byte array
- : using a System.ComponentModel.TypeConverter
- : and then encoded with base64 encoding.
- -->
- <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
- <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
- <xsd:element name="root" msdata:IsDataSet="true">
- <xsd:complexType>
- <xsd:choice maxOccurs="unbounded">
- <xsd:element name="metadata">
- <xsd:complexType>
- <xsd:sequence>
- <xsd:element name="value" type="xsd:string" minOccurs="0" />
- </xsd:sequence>
- <xsd:attribute name="name" use="required" type="xsd:string" />
- <xsd:attribute name="type" type="xsd:string" />
- <xsd:attribute name="mimetype" type="xsd:string" />
- <xsd:attribute ref="xml:space" />
- </xsd:complexType>
- </xsd:element>
- <xsd:element name="assembly">
- <xsd:complexType>
- <xsd:attribute name="alias" type="xsd:string" />
- <xsd:attribute name="name" type="xsd:string" />
- </xsd:complexType>
- </xsd:element>
- <xsd:element name="data">
- <xsd:complexType>
- <xsd:sequence>
- <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
- <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
- </xsd:sequence>
- <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
- <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
- <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
- <xsd:attribute ref="xml:space" />
- </xsd:complexType>
- </xsd:element>
- <xsd:element name="resheader">
- <xsd:complexType>
- <xsd:sequence>
- <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
- </xsd:sequence>
- <xsd:attribute name="name" type="xsd:string" use="required" />
- </xsd:complexType>
- </xsd:element>
- </xsd:choice>
- </xsd:complexType>
- </xsd:element>
- </xsd:schema>
- <resheader name="resmimetype">
- <value>text/microsoft-resx</value>
- </resheader>
- <resheader name="version">
- <value>2.0</value>
- </resheader>
- <resheader name="reader">
- <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
- </resheader>
- <resheader name="writer">
- <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
- </resheader>
- <data name="ArgumentPropertyMissing" xml:space="preserve">
- <value>Argument's {0}.{1} property is required but is empty or null.</value>
- </data>
- <data name="CurrentHttpContextRequired" xml:space="preserve">
- <value>HttpContext.Current is null. There must be an ASP.NET request in process for this operation to succeed.</value>
- </data>
- <data name="DataContractMissingFromMessageType" xml:space="preserve">
- <value>DataContractSerializer could not be initialized on message type {0}. Is it missing a [DataContract] attribute?</value>
- </data>
- <data name="DataContractMissingNamespace" xml:space="preserve">
- <value>DataContractSerializer could not be initialized on message type {0} because the DataContractAttribute.Namespace property is not set.</value>
- </data>
- <data name="DerivedTypeNotExpected" xml:space="preserve">
- <value>An instance of type {0} was expected, but received unexpected derived type {1}.</value>
- </data>
- <data name="DirectedMessageMissingRecipient" xml:space="preserve">
- <value>The directed message's Recipient property must not be null.</value>
- </data>
- <data name="ErrorInRequestReplyMessage" xml:space="preserve">
- <value>Error occurred while sending a direct message or getting the response.</value>
- </data>
- <data name="ExceptionNotConstructedForTransit" xml:space="preserve">
- <value>This exception was not constructed with a root request message that caused it.</value>
- </data>
- <data name="ExpectedMessageNotReceived" xml:space="preserve">
- <value>Expected message {0} but received no recognizable message.</value>
- </data>
- <data name="ExpiredMessage" xml:space="preserve">
- <value>The message expired at {0} and it is now {1}.</value>
- </data>
- <data name="GetOrPostFlagsRequired" xml:space="preserve">
- <value>At least one of GET or POST flags must be present.</value>
- </data>
- <data name="HttpContextRequired" xml:space="preserve">
- <value>This method requires a current HttpContext. Alternatively, use an overload of this method that allows you to pass in information without an HttpContext.</value>
- </data>
- <data name="IndirectMessagesMustImplementIDirectedProtocolMessage" xml:space="preserve">
- <value>Messages that indicate indirect transport must implement the {0} interface.</value>
- </data>
- <data name="InsufficentMessageProtection" xml:space="preserve">
- <value>The message required protections {0} but the channel could only apply {1}.</value>
- </data>
- <data name="InvalidMessageParts" xml:space="preserve">
- <value>Some part(s) of the message have invalid values: {0}</value>
- </data>
- <data name="InvalidNonceReceived" xml:space="preserve">
- <value>The incoming message had an invalid or missing nonce.</value>
- </data>
- <data name="KeyAlreadyExists" xml:space="preserve">
- <value>An item with the same key has already been added.</value>
- </data>
- <data name="QueuedMessageResponseAlreadyExists" xml:space="preserve">
- <value>A message response is already queued for sending in the response stream.</value>
- </data>
- <data name="ReplayAttackDetected" xml:space="preserve">
- <value>This message has already been processed. This could indicate a replay attack in progress.</value>
- </data>
- <data name="ReplayProtectionNotSupported" xml:space="preserve">
- <value>This channel does not support replay protection.</value>
- </data>
- <data name="RequiredParametersMissing" xml:space="preserve">
- <value>The following required parameters were missing from the {0} message: {1}</value>
- </data>
- <data name="RequiredProtectionMissing" xml:space="preserve">
- <value>The binding element offering the {0} protection requires other protection that is not provided.</value>
- </data>
- <data name="SequenceContainsNoElements" xml:space="preserve">
- <value>The list is empty.</value>
- </data>
- <data name="SequenceContainsNullElement" xml:space="preserve">
- <value>The list contains a null element.</value>
- </data>
- <data name="SignatureInvalid" xml:space="preserve">
- <value>Message signature was incorrect.</value>
- </data>
- <data name="SigningNotSupported" xml:space="preserve">
- <value>This channel does not support signing messages. To support signing messages, a derived Channel type must override the Sign and IsSignatureValid methods.</value>
- </data>
- <data name="StreamUnreadable" xml:space="preserve">
- <value>The stream's CanRead property returned false.</value>
- </data>
- <data name="StreamUnwritable" xml:space="preserve">
- <value>The stream's CanWrite property returned false.</value>
- </data>
- <data name="TooManyBindingsOfferingSameProtection" xml:space="preserve">
- <value>Expected at most 1 binding element offering the {0} protection, but found {1}.</value>
- </data>
- <data name="UnexpectedMessageReceived" xml:space="preserve">
- <value>Expected message {0} but received {1} instead.</value>
- </data>
- <data name="UnexpectedType" xml:space="preserve">
- <value>The type {0} or a derived type was expected, but {1} was given.</value>
- </data>
- <data name="UnrecognizedEnumValue" xml:space="preserve">
- <value>{0} property has unrecognized value {1}.</value>
- </data>
-</root> \ No newline at end of file
diff --git a/src/DotNetOAuth/Messaging/MessagingUtilities.cs b/src/DotNetOAuth/Messaging/MessagingUtilities.cs
deleted file mode 100644
index 8a4034e..0000000
--- a/src/DotNetOAuth/Messaging/MessagingUtilities.cs
+++ /dev/null
@@ -1,271 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="MessagingUtilities.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOAuth.Messaging {
- using System;
- using System.Collections.Generic;
- using System.Collections.Specialized;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Text;
- using System.Web;
- using DotNetOAuth.Messaging.Reflection;
-
- /// <summary>
- /// A grab-bag of utility methods useful for the channel stack of the protocol.
- /// </summary>
- public static class MessagingUtilities {
- /// <summary>
- /// Adds a set of HTTP headers to an <see cref="HttpResponse"/> instance,
- /// taking care to set some headers to the appropriate properties of
- /// <see cref="HttpResponse" />
- /// </summary>
- /// <param name="headers">The headers to add.</param>
- /// <param name="response">The <see cref="HttpResponse"/> instance to set the appropriate values to.</param>
- internal static void ApplyHeadersToResponse(WebHeaderCollection headers, HttpResponse response) {
- if (headers == null) {
- throw new ArgumentNullException("headers");
- }
- if (response == null) {
- throw new ArgumentNullException("response");
- }
- foreach (string headerName in headers) {
- switch (headerName) {
- case "Content-Type":
- response.ContentType = headers[HttpResponseHeader.ContentType];
- break;
-
- // Add more special cases here as necessary.
- default:
- response.AddHeader(headerName, headers[headerName]);
- break;
- }
- }
- }
-
- /// <summary>
- /// Copies the contents of one stream to another.
- /// </summary>
- /// <param name="copyFrom">The stream to copy from, at the position where copying should begin.</param>
- /// <param name="copyTo">The stream to copy to, at the position where bytes should be written.</param>
- /// <remarks>
- /// Copying begins at the streams' current positions.
- /// The positions are NOT reset after copying is complete.
- /// </remarks>
- internal static void CopyTo(this Stream copyFrom, Stream copyTo) {
- if (copyFrom == null) {
- throw new ArgumentNullException("copyFrom");
- }
- if (copyTo == null) {
- throw new ArgumentNullException("copyTo");
- }
- if (!copyFrom.CanRead) {
- throw new ArgumentException(MessagingStrings.StreamUnreadable, "copyFrom");
- }
- if (!copyTo.CanWrite) {
- throw new ArgumentException(MessagingStrings.StreamUnwritable, "copyTo");
- }
-
- byte[] buffer = new byte[1024];
- int readBytes;
- while ((readBytes = copyFrom.Read(buffer, 0, 1024)) > 0) {
- copyTo.Write(buffer, 0, readBytes);
- }
- }
-
- /// <summary>
- /// Concatenates a list of name-value pairs as key=value&amp;key=value,
- /// taking care to properly encode each key and value for URL
- /// transmission. No ? is prefixed to the string.
- /// </summary>
- /// <param name="args">The dictionary of key/values to read from.</param>
- /// <returns>The formulated querystring style string.</returns>
- internal static string CreateQueryString(IDictionary<string, string> args) {
- if (args == null) {
- throw new ArgumentNullException("args");
- }
- if (args.Count == 0) {
- return string.Empty;
- }
- StringBuilder sb = new StringBuilder(args.Count * 10);
-
- foreach (var p in args) {
- sb.Append(HttpUtility.UrlEncode(p.Key));
- sb.Append('=');
- sb.Append(HttpUtility.UrlEncode(p.Value));
- sb.Append('&');
- }
- sb.Length--; // remove trailing &
-
- return sb.ToString();
- }
-
- /// <summary>
- /// Adds a set of name-value pairs to the end of a given URL
- /// as part of the querystring piece. Prefixes a ? or &amp; before
- /// first element as necessary.
- /// </summary>
- /// <param name="builder">The UriBuilder to add arguments to.</param>
- /// <param name="args">
- /// The arguments to add to the query.
- /// If null, <paramref name="builder"/> is not changed.
- /// </param>
- internal static void AppendQueryArgs(UriBuilder builder, IDictionary<string, string> args) {
- if (builder == null) {
- throw new ArgumentNullException("builder");
- }
-
- if (args != null && args.Count > 0) {
- StringBuilder sb = new StringBuilder(50 + (args.Count * 10));
- if (!string.IsNullOrEmpty(builder.Query)) {
- sb.Append(builder.Query.Substring(1));
- sb.Append('&');
- }
- sb.Append(CreateQueryString(args));
-
- builder.Query = sb.ToString();
- }
- }
-
- /// <summary>
- /// Gets the original request URL, as seen from the browser before any URL rewrites on the server if any.
- /// Cookieless session directory (if applicable) is also included.
- /// </summary>
- /// <returns>The URL in the user agent's Location bar.</returns>
- public static Uri GetRequestUrlFromContext() {
- HttpContext context = HttpContext.Current;
- if (context == null) {
- throw new InvalidOperationException(MessagingStrings.CurrentHttpContextRequired);
- }
-
- // We use Request.Url for the full path to the server, and modify it
- // with Request.RawUrl to capture both the cookieless session "directory" if it exists
- // and the original path in case URL rewriting is going on. We don't want to be
- // fooled by URL rewriting because we're comparing the actual URL with what's in
- // the return_to parameter in some cases.
- // Response.ApplyAppPathModifier(builder.Path) would have worked for the cookieless
- // session, but not the URL rewriting problem.
- return new Uri(context.Request.Url, context.Request.RawUrl);
- }
-
- /// <summary>
- /// Strips any and all URI query parameters that start with some prefix.
- /// </summary>
- /// <param name="uri">The URI that may have a query with parameters to remove.</param>
- /// <param name="prefix">The prefix for parameters to remove.</param>
- /// <returns>Either a new Uri with the parameters removed if there were any to remove, or the same Uri instance if no parameters needed to be removed.</returns>
- public static Uri StripQueryArgumentsWithPrefix(this Uri uri, string prefix) {
- NameValueCollection queryArgs = HttpUtility.ParseQueryString(uri.Query);
- var matchingKeys = queryArgs.Keys.OfType<string>().Where(key => key.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)).ToList();
- if (matchingKeys.Count > 0) {
- UriBuilder builder = new UriBuilder(uri);
- foreach (string key in matchingKeys) {
- queryArgs.Remove(key);
- }
- builder.Query = CreateQueryString(queryArgs.ToDictionary());
- return builder.Uri;
- } else {
- return uri;
- }
- }
-
- /// <summary>
- /// Extracts the recipient from an HttpRequestInfo.
- /// </summary>
- /// <param name="request">The request to get recipient information from.</param>
- /// <returns>The recipient.</returns>
- internal static MessageReceivingEndpoint GetRecipient(this HttpRequestInfo request) {
- return new MessageReceivingEndpoint(request.Url, request.HttpMethod == "GET" ? HttpDeliveryMethods.GetRequest : HttpDeliveryMethods.PostRequest);
- }
-
- /// <summary>
- /// Copies some extra parameters into a message.
- /// </summary>
- /// <param name="message">The message to copy the extra data into.</param>
- /// <param name="extraParameters">The extra data to copy into the message. May be null to do nothing.</param>
- internal static void AddNonOAuthParameters(this IProtocolMessage message, IDictionary<string, string> extraParameters) {
- if (message == null) {
- throw new ArgumentNullException("message");
- }
-
- if (extraParameters != null) {
- MessageDictionary messageDictionary = new MessageDictionary(message);
- foreach (var pair in extraParameters) {
- messageDictionary.Add(pair);
- }
- }
- }
-
- /// <summary>
- /// Converts a <see cref="NameValueCollection"/> to an IDictionary&lt;string, string&gt;.
- /// </summary>
- /// <param name="nvc">The NameValueCollection to convert. May be null.</param>
- /// <returns>The generated dictionary, or null if <paramref name="nvc"/> is null.</returns>
- internal static Dictionary<string, string> ToDictionary(this NameValueCollection nvc) {
- if (nvc == null) {
- return null;
- }
-
- var dictionary = new Dictionary<string, string>();
- foreach (string key in nvc) {
- dictionary.Add(key, nvc[key]);
- }
-
- return dictionary;
- }
-
- /// <summary>
- /// Sorts the elements of a sequence in ascending order by using a specified comparer.
- /// </summary>
- /// <typeparam name="TSource">The type of the elements of source.</typeparam>
- /// <typeparam name="TKey">The type of the key returned by keySelector.</typeparam>
- /// <param name="source">A sequence of values to order.</param>
- /// <param name="keySelector">A function to extract a key from an element.</param>
- /// <param name="comparer">A comparison function to compare keys.</param>
- /// <returns>An System.Linq.IOrderedEnumerable&lt;TElement&gt; whose elements are sorted according to a key.</returns>
- internal static IOrderedEnumerable<TSource> OrderBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Comparison<TKey> comparer) {
- return System.Linq.Enumerable.OrderBy<TSource, TKey>(source, keySelector, new ComparisonHelper<TKey>(comparer));
- }
-
- /// <summary>
- /// A class to convert a <see cref="Comparison&lt;T&gt;"/> into an <see cref="IComparer&lt;T&gt;"/>.
- /// </summary>
- /// <typeparam name="T">The type of objects being compared.</typeparam>
- private class ComparisonHelper<T> : IComparer<T> {
- /// <summary>
- /// The comparison method to use.
- /// </summary>
- private Comparison<T> comparison;
-
- /// <summary>
- /// Initializes a new instance of the ComparisonHelper class.
- /// </summary>
- /// <param name="comparison">The comparison method to use.</param>
- internal ComparisonHelper(Comparison<T> comparison) {
- if (comparison == null) {
- throw new ArgumentNullException("comparison");
- }
-
- this.comparison = comparison;
- }
-
- #region IComparer<T> Members
-
- /// <summary>
- /// Compares two instances of <typeparamref name="T"/>.
- /// </summary>
- /// <param name="x">The first object to compare.</param>
- /// <param name="y">The second object to compare.</param>
- /// <returns>Any of -1, 0, or 1 according to standard comparison rules.</returns>
- public int Compare(T x, T y) {
- return this.comparison(x, y);
- }
-
- #endregion
- }
- }
-}
diff --git a/src/DotNetOAuth/Messaging/ProtocolException.cs b/src/DotNetOAuth/Messaging/ProtocolException.cs
deleted file mode 100644
index 0c31308..0000000
--- a/src/DotNetOAuth/Messaging/ProtocolException.cs
+++ /dev/null
@@ -1,254 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="ProtocolException.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOAuth.Messaging {
- using System;
- using System.Collections.Generic;
- using System.Security.Permissions;
-
- /// <summary>
- /// An exception to represent errors in the local or remote implementation of the protocol.
- /// </summary>
- [Serializable]
- public class ProtocolException : Exception, IDirectedProtocolMessage {
- /// <summary>
- /// The request message being processed when this exception was generated, if any.
- /// </summary>
- private IProtocolMessage inResponseTo;
-
- /// <summary>
- /// The indirect message receiver this exception should be delivered to, if any.
- /// </summary>
- private Uri recipient;
-
- /// <summary>
- /// A cache for extra name/value pairs tacked on as data when this exception is sent as a message.
- /// </summary>
- private Dictionary<string, string> extraData = new Dictionary<string, string>();
-
- /// <summary>
- /// Initializes a new instance of the <see cref="ProtocolException"/> class.
- /// </summary>
- public ProtocolException() { }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="ProtocolException"/> class.
- /// </summary>
- /// <param name="message">A message describing the specific error the occurred or was detected.</param>
- public ProtocolException(string message) : base(message) { }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="ProtocolException"/> class.
- /// </summary>
- /// <param name="message">A message describing the specific error the occurred or was detected.</param>
- /// <param name="inner">The inner exception to include.</param>
- public ProtocolException(string message, Exception inner) : base(message, inner) { }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="ProtocolException"/> class
- /// such that it can be sent as a protocol message response to a remote caller.
- /// </summary>
- /// <param name="message">The human-readable exception message.</param>
- /// <param name="faultedMessage">The message that was the cause of the exception. May not be null.</param>
- internal ProtocolException(string message, IProtocolMessage faultedMessage)
- : base(message) {
- if (faultedMessage == null) {
- throw new ArgumentNullException("faultedMessage");
- }
-
- this.FaultedMessage = faultedMessage;
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="ProtocolException"/> class
- /// such that it can be sent as a protocol message response to a remote caller.
- /// </summary>
- /// <param name="message">The human-readable exception message.</param>
- /// <param name="inResponseTo">
- /// If <paramref name="message"/> is a response to an incoming message, this is the incoming message.
- /// This is useful for error scenarios in deciding just how to send the response message.
- /// May be null.
- /// </param>
- /// <param name="remoteIndirectReceiver">
- /// In the case of exceptions that will be sent as indirect messages to the original calling
- /// remote party, this is the URI of that remote site's receiver.
- /// May be null only if the <paramref name="inResponseTo"/> message is a direct request.
- /// </param>
- internal ProtocolException(string message, IProtocolMessage inResponseTo, Uri remoteIndirectReceiver)
- : this(message) {
- if (inResponseTo == null) {
- throw new ArgumentNullException("inResponseTo");
- }
- this.inResponseTo = inResponseTo;
- this.FaultedMessage = inResponseTo;
-
- if (remoteIndirectReceiver == null && inResponseTo.Transport != MessageTransport.Direct) {
- // throw an exception, with ourselves as the inner exception (as fully initialized as we can be).
- throw new ArgumentNullException("remoteIndirectReceiver");
- }
- this.recipient = remoteIndirectReceiver;
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="ProtocolException"/> class.
- /// </summary>
- /// <param name="info">The <see cref="System.Runtime.Serialization.SerializationInfo"/>
- /// that holds the serialized object data about the exception being thrown.</param>
- /// <param name="context">The System.Runtime.Serialization.StreamingContext
- /// that contains contextual information about the source or destination.</param>
- protected ProtocolException(
- System.Runtime.Serialization.SerializationInfo info,
- System.Runtime.Serialization.StreamingContext context)
- : base(info, context) {
- throw new NotImplementedException();
- }
-
- #region IProtocolMessage Properties
-
- /// <summary>
- /// Gets the version of the protocol this message is prepared to implement.
- /// </summary>
- Version IProtocolMessage.ProtocolVersion {
- get { return this.ProtocolVersion; }
- }
-
- /// <summary>
- /// Gets the level of protection this exception requires when transmitted as a message.
- /// </summary>
- MessageProtections IProtocolMessage.RequiredProtection {
- get { return RequiredProtection; }
- }
-
- /// <summary>
- /// Gets whether this is a direct or indirect message.
- /// </summary>
- MessageTransport IProtocolMessage.Transport {
- get { return this.Transport; }
- }
-
- #endregion
-
- #region IDirectedProtocolMessage Members
-
- /// <summary>
- /// Gets the URL of the intended receiver of this message.
- /// </summary>
- /// <remarks>
- /// This property should only be called when the error is being sent as an indirect response.
- /// </remarks>
- Uri IDirectedProtocolMessage.Recipient {
- get { return this.Recipient; }
- }
-
- #endregion
-
- /// <summary>
- /// Gets the dictionary of additional name/value fields tacked on to this message.
- /// </summary>
- IDictionary<string, string> IProtocolMessage.ExtraData {
- get { return this.ExtraData; }
- }
-
- /// <summary>
- /// Gets the message that caused the exception.
- /// </summary>
- internal IProtocolMessage FaultedMessage {
- get;
- private set;
- }
-
- /// <summary>
- /// Gets the level of protection this exception requires when transmitted as a message.
- /// </summary>
- protected static MessageProtections RequiredProtection {
- get { return MessageProtections.None; }
- }
-
- /// <summary>
- /// Gets the URL of the intended receiver of this message.
- /// </summary>
- /// <remarks>
- /// This property should only be called when the error is being sent as an indirect response.
- /// </remarks>
- protected Uri Recipient {
- get {
- if (this.inResponseTo == null) {
- throw new InvalidOperationException(MessagingStrings.ExceptionNotConstructedForTransit);
- }
- return this.recipient;
- }
- }
-
- /// <summary>
- /// Gets the version of the protocol this message is prepared to implement.
- /// </summary>
- protected Version ProtocolVersion {
- get {
- if (this.inResponseTo == null) {
- throw new InvalidOperationException(MessagingStrings.ExceptionNotConstructedForTransit);
- }
- return this.inResponseTo.ProtocolVersion;
- }
- }
-
- /// <summary>
- /// Gets whether this is a direct or indirect message.
- /// </summary>
- protected MessageTransport Transport {
- get {
- if (this.inResponseTo == null) {
- throw new InvalidOperationException(MessagingStrings.ExceptionNotConstructedForTransit);
- }
- return this.inResponseTo.Transport;
- }
- }
-
- /// <summary>
- /// Gets the dictionary of additional name/value fields tacked on to this message.
- /// </summary>
- protected IDictionary<string, string> ExtraData {
- get { return this.extraData; }
- }
-
- /// <summary>
- /// When overridden in a derived class, sets the <see cref="T:System.Runtime.Serialization.SerializationInfo"/> with information about the exception.
- /// </summary>
- /// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
- /// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext"/> that contains contextual information about the source or destination.</param>
- /// <exception cref="T:System.ArgumentNullException">
- /// The <paramref name="info"/> parameter is a null reference (Nothing in Visual Basic).
- /// </exception>
- /// <PermissionSet>
- /// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Read="*AllFiles*" PathDiscovery="*AllFiles*"/>
- /// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="SerializationFormatter"/>
- /// </PermissionSet>
- [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
- public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) {
- base.GetObjectData(info, context);
- throw new NotImplementedException();
- }
-
- #region IProtocolMessage Methods
-
- /// <summary>
- /// See <see cref="IProtocolMessage.EnsureValidMessage"/>.
- /// </summary>
- void IProtocolMessage.EnsureValidMessage() {
- this.EnsureValidMessage();
- }
-
- /// <summary>
- /// See <see cref="IProtocolMessage.EnsureValidMessage"/>.
- /// </summary>
- protected virtual void EnsureValidMessage() {
- if (this.inResponseTo == null) {
- throw new InvalidOperationException(MessagingStrings.ExceptionNotConstructedForTransit);
- }
- }
-
- #endregion
- }
-}
diff --git a/src/DotNetOAuth/Messaging/Reflection/MessageDescription.cs b/src/DotNetOAuth/Messaging/Reflection/MessageDescription.cs
deleted file mode 100644
index 0f180c9..0000000
--- a/src/DotNetOAuth/Messaging/Reflection/MessageDescription.cs
+++ /dev/null
@@ -1,128 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="MessageDescription.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOAuth.Messaging.Reflection {
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Globalization;
- using System.Linq;
- using System.Reflection;
-
- /// <summary>
- /// A mapping between serialized key names and <see cref="MessagePart"/> instances describing
- /// those key/values pairs.
- /// </summary>
- internal class MessageDescription {
- /// <summary>
- /// A dictionary of reflected message types and the generated reflection information.
- /// </summary>
- private static Dictionary<Type, MessageDescription> reflectedMessageTypes = new Dictionary<Type, MessageDescription>();
-
- /// <summary>
- /// The type of message this instance was generated from.
- /// </summary>
- private Type messageType;
-
- /// <summary>
- /// A mapping between the serialized key names and their
- /// describing <see cref="MessagePart"/> instances.
- /// </summary>
- private Dictionary<string, MessagePart> mapping;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="MessageDescription"/> class.
- /// </summary>
- /// <param name="messageType">The type of message to reflect over.</param>
- private MessageDescription(Type messageType) {
- Debug.Assert(messageType != null, "messageType == null");
-
- if (!typeof(IProtocolMessage).IsAssignableFrom(messageType)) {
- throw new ArgumentException(string.Format(
- CultureInfo.CurrentCulture,
- MessagingStrings.UnexpectedType,
- typeof(IProtocolMessage),
- messageType));
- }
-
- this.messageType = messageType;
- this.ReflectMessageType();
- }
-
- /// <summary>
- /// Gets the mapping between the serialized key names and their describing
- /// <see cref="MessagePart"/> instances.
- /// </summary>
- internal IDictionary<string, MessagePart> Mapping {
- get { return this.mapping; }
- }
-
- /// <summary>
- /// Gets a <see cref="MessageDescription"/> instance prepared for the
- /// given message type.
- /// </summary>
- /// <param name="messageType">A type that implements <see cref="IProtocolMessage"/>.</param>
- /// <returns>A <see cref="MessageDescription"/> instance.</returns>
- internal static MessageDescription Get(Type messageType) {
- if (messageType == null) {
- throw new ArgumentNullException("messageType");
- }
-
- MessageDescription result;
- if (!reflectedMessageTypes.TryGetValue(messageType, out result)) {
- lock (reflectedMessageTypes) {
- if (!reflectedMessageTypes.TryGetValue(messageType, out result)) {
- reflectedMessageTypes[messageType] = result = new MessageDescription(messageType);
- }
- }
- }
-
- return result;
- }
-
- /// <summary>
- /// Reflects over some <see cref="IProtocolMessage"/>-implementing type
- /// and prepares to serialize/deserialize instances of that type.
- /// </summary>
- internal void ReflectMessageType() {
- this.mapping = new Dictionary<string, MessagePart>();
-
- Type currentType = this.messageType;
- do {
- foreach (MemberInfo member in currentType.GetMembers(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly)) {
- if (member is PropertyInfo || member is FieldInfo) {
- MessagePartAttribute partAttribute = member.GetCustomAttributes(typeof(MessagePartAttribute), true).OfType<MessagePartAttribute>().FirstOrDefault();
- if (partAttribute != null) {
- MessagePart part = new MessagePart(member, partAttribute);
- this.mapping.Add(part.Name, part);
- }
- }
- }
- currentType = currentType.BaseType;
- } while (currentType != null);
- }
-
- /// <summary>
- /// Verifies that a given set of keys include all the required parameters
- /// for this message type or throws an exception.
- /// </summary>
- /// <param name="keys">The names of all parameters included in a message.</param>
- /// <exception cref="ProtocolException">Thrown when required parts of a message are not in <paramref name="keys"/></exception>
- internal void EnsureRequiredMessagePartsArePresent(IEnumerable<string> keys) {
- var missingKeys = (from part in Mapping.Values
- where part.IsRequired && !keys.Contains(part.Name)
- select part.Name).ToArray();
- if (missingKeys.Length > 0) {
- throw new ProtocolException(
- string.Format(
- CultureInfo.CurrentCulture,
- MessagingStrings.RequiredParametersMissing,
- this.messageType.FullName,
- string.Join(", ", missingKeys)));
- }
- }
- }
-}
diff --git a/src/DotNetOAuth/Messaging/Reflection/MessageDictionary.cs b/src/DotNetOAuth/Messaging/Reflection/MessageDictionary.cs
deleted file mode 100644
index 5416e5f..0000000
--- a/src/DotNetOAuth/Messaging/Reflection/MessageDictionary.cs
+++ /dev/null
@@ -1,320 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="MessageDictionary.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOAuth.Messaging.Reflection {
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Diagnostics;
-
- /// <summary>
- /// Wraps an <see cref="IProtocolMessage"/> instance in a dictionary that
- /// provides access to both well-defined message properties and "extra"
- /// name/value pairs that have no properties associated with them.
- /// </summary>
- internal class MessageDictionary : IDictionary<string, string> {
- /// <summary>
- /// The <see cref="IProtocolMessage"/> instance manipulated by this dictionary.
- /// </summary>
- private IProtocolMessage message;
-
- /// <summary>
- /// The <see cref="MessageDescription"/> instance that describes the message type.
- /// </summary>
- private MessageDescription description;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="MessageDictionary"/> class.
- /// </summary>
- /// <param name="message">The message instance whose values will be manipulated by this dictionary.</param>
- internal MessageDictionary(IProtocolMessage message) {
- if (message == null) {
- throw new ArgumentNullException("message");
- }
-
- this.message = message;
- this.description = MessageDescription.Get(message.GetType());
- }
-
- #region ICollection<KeyValuePair<string,string>> Properties
-
- /// <summary>
- /// Gets the number of explicitly set values in the message.
- /// </summary>
- public int Count {
- get { return this.Keys.Count; }
- }
-
- /// <summary>
- /// Gets a value indicating whether this message is read only.
- /// </summary>
- bool ICollection<KeyValuePair<string, string>>.IsReadOnly {
- get { return false; }
- }
-
- #endregion
-
- #region IDictionary<string,string> Properties
-
- /// <summary>
- /// Gets all the keys that have values associated with them.
- /// </summary>
- public ICollection<string> Keys {
- get {
- List<string> keys = new List<string>(this.message.ExtraData.Count + this.description.Mapping.Count);
- keys.AddRange(this.DeclaredKeys);
- keys.AddRange(this.AdditionalKeys);
- return keys.AsReadOnly();
- }
- }
-
- /// <summary>
- /// Gets the set of official OAuth keys that have non-null values associated with them.
- /// </summary>
- public ICollection<string> DeclaredKeys {
- get {
- List<string> keys = new List<string>(this.description.Mapping.Count);
- foreach (var pair in this.description.Mapping) {
- // Don't include keys with null values, but default values for structs is ok
- if (pair.Value.GetValue(this.message) != null) {
- keys.Add(pair.Key);
- }
- }
-
- return keys.AsReadOnly();
- }
- }
-
- /// <summary>
- /// Gets the keys that are in the message but not declared as official OAuth properties.
- /// </summary>
- public ICollection<string> AdditionalKeys {
- get { return this.message.ExtraData.Keys; }
- }
-
- /// <summary>
- /// Gets all the values.
- /// </summary>
- public ICollection<string> Values {
- get {
- List<string> values = new List<string>(this.message.ExtraData.Count + this.description.Mapping.Count);
- foreach (MessagePart part in this.description.Mapping.Values) {
- if (part.GetValue(this.message) != null) {
- values.Add(part.GetValue(this.message));
- }
- }
-
- foreach (string value in this.message.ExtraData.Values) {
- Debug.Assert(value != null, "Null values should never be allowed in the extra data dictionary.");
- values.Add(value);
- }
-
- return values.AsReadOnly();
- }
- }
-
- /// <summary>
- /// Gets or sets a value for some named value.
- /// </summary>
- /// <param name="key">The serialized form of a name for the value to read or write.</param>
- /// <returns>The named value.</returns>
- /// <remarks>
- /// If the key matches a declared property or field on the message type,
- /// that type member is set. Otherwise the key/value is stored in a
- /// dictionary for extra (weakly typed) strings.
- /// </remarks>
- public string this[string key] {
- get {
- MessagePart part;
- if (this.description.Mapping.TryGetValue(key, out part)) {
- // Never throw KeyNotFoundException for declared properties.
- return part.GetValue(this.message);
- } else {
- return this.message.ExtraData[key];
- }
- }
-
- set {
- MessagePart part;
- if (this.description.Mapping.TryGetValue(key, out part)) {
- part.SetValue(this.message, value);
- } else {
- if (value == null) {
- this.message.ExtraData.Remove(key);
- } else {
- this.message.ExtraData[key] = value;
- }
- }
- }
- }
-
- #endregion
-
- #region IDictionary<string,string> Methods
-
- /// <summary>
- /// Adds a named value to the message.
- /// </summary>
- /// <param name="key">The serialized form of the name whose value is being set.</param>
- /// <param name="value">The serialized form of the value.</param>
- /// <exception cref="ArgumentException">
- /// Thrown if <paramref name="key"/> already has a set value in this message.
- /// </exception>
- /// <exception cref="ArgumentNullException">
- /// Thrown if <paramref name="value"/> is null.
- /// </exception>
- public void Add(string key, string value) {
- if (value == null) {
- throw new ArgumentNullException("value");
- }
-
- MessagePart part;
- if (this.description.Mapping.TryGetValue(key, out part)) {
- if (part.IsNondefaultValueSet(this.message)) {
- throw new ArgumentException(MessagingStrings.KeyAlreadyExists);
- }
- part.SetValue(this.message, value);
- } else {
- this.message.ExtraData.Add(key, value);
- }
- }
-
- /// <summary>
- /// Checks whether some named parameter has a value set in the message.
- /// </summary>
- /// <param name="key">The serialized form of the message part's name.</param>
- /// <returns>True if the parameter by the given name has a set value. False otherwise.</returns>
- public bool ContainsKey(string key) {
- return this.message.ExtraData.ContainsKey(key) ||
- (this.description.Mapping.ContainsKey(key) && this.description.Mapping[key].GetValue(this.message) != null);
- }
-
- /// <summary>
- /// Removes a name and value from the message given its name.
- /// </summary>
- /// <param name="key">The serialized form of the name to remove.</param>
- /// <returns>True if a message part by the given name was found and removed. False otherwise.</returns>
- public bool Remove(string key) {
- if (this.message.ExtraData.Remove(key)) {
- return true;
- } else {
- MessagePart part;
- if (this.description.Mapping.TryGetValue(key, out part)) {
- if (part.GetValue(this.message) != null) {
- part.SetValue(this.message, null);
- return true;
- }
- }
- return false;
- }
- }
-
- /// <summary>
- /// Gets some named value if the key has a value.
- /// </summary>
- /// <param name="key">The name (in serialized form) of the value being sought.</param>
- /// <param name="value">The variable where the value will be set.</param>
- /// <returns>True if the key was found and <paramref name="value"/> was set. False otherwise.</returns>
- public bool TryGetValue(string key, out string value) {
- MessagePart part;
- if (this.description.Mapping.TryGetValue(key, out part)) {
- value = part.GetValue(this.message);
- return true;
- }
- return this.message.ExtraData.TryGetValue(key, out value);
- }
-
- #endregion
-
- #region ICollection<KeyValuePair<string,string>> Methods
-
- /// <summary>
- /// Sets a named value in the message.
- /// </summary>
- /// <param name="item">The name-value pair to add. The name is the serialized form of the key.</param>
- public void Add(KeyValuePair<string, string> item) {
- this.Add(item.Key, item.Value);
- }
-
- /// <summary>
- /// Removes all values in the message.
- /// </summary>
- public void Clear() {
- foreach (string key in this.Keys) {
- this.Remove(key);
- }
- }
-
- /// <summary>
- /// Checks whether a named value has been set on the message.
- /// </summary>
- /// <param name="item">The name/value pair.</param>
- /// <returns>True if the key exists and has the given value. False otherwise.</returns>
- public bool Contains(KeyValuePair<string, string> item) {
- MessagePart part;
- if (this.description.Mapping.TryGetValue(item.Key, out part)) {
- return string.Equals(part.GetValue(this.message), item.Value, StringComparison.Ordinal);
- } else {
- return this.message.ExtraData.Contains(item);
- }
- }
-
- /// <summary>
- /// Copies all the serializable data from the message to a key/value array.
- /// </summary>
- /// <param name="array">The array to copy to.</param>
- /// <param name="arrayIndex">The index in the <paramref name="array"/> to begin copying to.</param>
- void ICollection<KeyValuePair<string, string>>.CopyTo(KeyValuePair<string, string>[] array, int arrayIndex) {
- foreach (var pair in (IDictionary<string, string>)this) {
- array[arrayIndex++] = pair;
- }
- }
-
- /// <summary>
- /// Removes a named value from the message if it exists.
- /// </summary>
- /// <param name="item">The serialized form of the name and value to remove.</param>
- /// <returns>True if the name/value was found and removed. False otherwise.</returns>
- public bool Remove(KeyValuePair<string, string> item) {
- // We use contains because that checks that the value is equal as well.
- if (((ICollection<KeyValuePair<string, string>>)this).Contains(item)) {
- ((IDictionary<string, string>)this).Remove(item.Key);
- return true;
- }
- return false;
- }
-
- #endregion
-
- #region IEnumerable<KeyValuePair<string,string>> Members
-
- /// <summary>
- /// Gets an enumerator that generates KeyValuePair&lt;string, string&gt; instances
- /// for all the key/value pairs that are set in the message.
- /// </summary>
- /// <returns>The enumerator that can generate the name/value pairs.</returns>
- public IEnumerator<KeyValuePair<string, string>> GetEnumerator() {
- foreach (string key in this.Keys) {
- yield return new KeyValuePair<string, string>(key, this[key]);
- }
- }
-
- #endregion
-
- #region IEnumerable Members
-
- /// <summary>
- /// Gets an enumerator that generates KeyValuePair&lt;string, string&gt; instances
- /// for all the key/value pairs that are set in the message.
- /// </summary>
- /// <returns>The enumerator that can generate the name/value pairs.</returns>
- IEnumerator System.Collections.IEnumerable.GetEnumerator() {
- return ((IEnumerable<KeyValuePair<string, string>>)this).GetEnumerator();
- }
-
- #endregion
- }
-}
diff --git a/src/DotNetOAuth/Messaging/Reflection/MessagePart.cs b/src/DotNetOAuth/Messaging/Reflection/MessagePart.cs
deleted file mode 100644
index 8d409d4..0000000
--- a/src/DotNetOAuth/Messaging/Reflection/MessagePart.cs
+++ /dev/null
@@ -1,251 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="MessagePart.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOAuth.Messaging.Reflection {
- using System;
- using System.Collections.Generic;
- using System.Diagnostics.CodeAnalysis;
- using System.Globalization;
- using System.Net.Security;
- using System.Reflection;
- using System.Xml;
-
- /// <summary>
- /// Describes an individual member of a message and assists in its serialization.
- /// </summary>
- internal class MessagePart {
- /// <summary>
- /// A map of converters that help serialize custom objects to string values and back again.
- /// </summary>
- private static readonly Dictionary<Type, ValueMapping> converters = new Dictionary<Type, ValueMapping>();
-
- /// <summary>
- /// The string-object conversion routines to use for this individual message part.
- /// </summary>
- private ValueMapping converter;
-
- /// <summary>
- /// The property that this message part is associated with, if aplicable.
- /// </summary>
- private PropertyInfo property;
-
- /// <summary>
- /// The field that this message part is associated with, if aplicable.
- /// </summary>
- private FieldInfo field;
-
- /// <summary>
- /// The type of the message part. (Not the type of the message itself).
- /// </summary>
- private Type memberDeclaredType;
-
- /// <summary>
- /// The default (uninitialized) value of the member inherent in its type.
- /// </summary>
- private object defaultMemberValue;
-
- /// <summary>
- /// Initializes static members of the <see cref="MessagePart"/> class.
- /// </summary>
- [SuppressMessage("Microsoft.Performance", "CA1810:InitializeReferenceTypeStaticFieldsInline", Justification = "Much more efficient initialization when we can call methods.")]
- static MessagePart() {
- Map<Uri>(uri => uri.AbsoluteUri, str => new Uri(str));
- Map<DateTime>(dt => XmlConvert.ToString(dt, XmlDateTimeSerializationMode.Utc), str => XmlConvert.ToDateTime(str, XmlDateTimeSerializationMode.Utc));
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="MessagePart"/> class.
- /// </summary>
- /// <param name="member">
- /// A property or field of an <see cref="IProtocolMessage"/> implementing type
- /// that has a <see cref="MessagePartAttribute"/> attached to it.
- /// </param>
- /// <param name="attribute">
- /// The attribute discovered on <paramref name="member"/> that describes the
- /// serialization requirements of the message part.
- /// </param>
- internal MessagePart(MemberInfo member, MessagePartAttribute attribute) {
- if (member == null) {
- throw new ArgumentNullException("member");
- }
-
- this.field = member as FieldInfo;
- this.property = member as PropertyInfo;
- if (this.field == null && this.property == null) {
- throw new ArgumentException(
- string.Format(
- CultureInfo.CurrentCulture,
- MessagingStrings.UnexpectedType,
- typeof(FieldInfo).Name + ", " + typeof(PropertyInfo).Name,
- member.GetType().Name),
- "member");
- }
-
- if (attribute == null) {
- throw new ArgumentNullException("attribute");
- }
-
- this.Name = attribute.Name ?? member.Name;
- this.RequiredProtection = attribute.RequiredProtection;
- this.IsRequired = attribute.IsRequired;
- this.memberDeclaredType = (this.field != null) ? this.field.FieldType : this.property.PropertyType;
- this.defaultMemberValue = DeriveDefaultValue(this.memberDeclaredType);
-
- if (!converters.TryGetValue(this.memberDeclaredType, out this.converter)) {
- this.converter = new ValueMapping(
- obj => obj != null ? obj.ToString() : null,
- str => str != null ? Convert.ChangeType(str, this.memberDeclaredType, CultureInfo.InvariantCulture) : null);
- }
-
- // Validate a sane combination of settings
- this.ValidateSettings();
- }
-
- /// <summary>
- /// Gets or sets the name to use when serializing or deserializing this parameter in a message.
- /// </summary>
- internal string Name { get; set; }
-
- /// <summary>
- /// Gets or sets whether this message part must be signed.
- /// </summary>
- internal ProtectionLevel RequiredProtection { get; set; }
-
- /// <summary>
- /// Gets or sets a value indicating whether this message part is required for the
- /// containing message to be valid.
- /// </summary>
- internal bool IsRequired { get; set; }
-
- /// <summary>
- /// Sets the member of a given message to some given value.
- /// Used in deserialization.
- /// </summary>
- /// <param name="message">The message instance containing the member whose value should be set.</param>
- /// <param name="value">The string representation of the value to set.</param>
- internal void SetValue(IProtocolMessage message, string value) {
- if (this.property != null) {
- this.property.SetValue(message, this.ToValue(value), null);
- } else {
- this.field.SetValue(message, this.ToValue(value));
- }
- }
-
- /// <summary>
- /// Gets the value of a member of a given message.
- /// Used in serialization.
- /// </summary>
- /// <param name="message">The message instance to read the value from.</param>
- /// <returns>The string representation of the member's value.</returns>
- internal string GetValue(IProtocolMessage message) {
- return this.ToString(this.GetValueAsObject(message));
- }
-
- /// <summary>
- /// Gets whether the value has been set to something other than its CLR type default value.
- /// </summary>
- /// <param name="message">The message instance to check the value on.</param>
- /// <returns>True if the value is not the CLR default value.</returns>
- internal bool IsNondefaultValueSet(IProtocolMessage message) {
- if (this.memberDeclaredType.IsValueType) {
- return !this.GetValueAsObject(message).Equals(this.defaultMemberValue);
- } else {
- return this.defaultMemberValue != this.GetValueAsObject(message);
- }
- }
-
- /// <summary>
- /// Figures out the CLR default value for a given type.
- /// </summary>
- /// <param name="type">The type whose default value is being sought.</param>
- /// <returns>Either null, or some default value like 0 or 0.0.</returns>
- private static object DeriveDefaultValue(Type type) {
- if (type.IsValueType) {
- return Activator.CreateInstance(type);
- } else {
- return null;
- }
- }
-
- /// <summary>
- /// Adds a pair of type conversion functions to the static converstion map.
- /// </summary>
- /// <typeparam name="T">The custom type to convert to and from strings.</typeparam>
- /// <param name="toString">The function to convert the custom type to a string.</param>
- /// <param name="toValue">The function to convert a string to the custom type.</param>
- private static void Map<T>(Func<T, string> toString, Func<string, T> toValue) {
- Func<object, string> safeToString = obj => obj != null ? toString((T)obj) : null;
- Func<string, object> safeToT = str => str != null ? toValue(str) : default(T);
- converters.Add(typeof(T), new ValueMapping(safeToString, safeToT));
- }
-
- /// <summary>
- /// Checks whether a type is a nullable value type (i.e. int?)
- /// </summary>
- /// <param name="type">The type in question.</param>
- /// <returns>True if this is a nullable value type.</returns>
- private static bool IsNonNullableValueType(Type type) {
- if (!type.IsValueType) {
- return false;
- }
-
- if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>)) {
- return false;
- }
-
- return true;
- }
-
- /// <summary>
- /// Converts a string representation of the member's value to the appropriate type.
- /// </summary>
- /// <param name="value">The string representation of the member's value.</param>
- /// <returns>An instance of the appropriate type for setting the member.</returns>
- private object ToValue(string value) {
- return this.converter.StringToValue(value);
- }
-
- /// <summary>
- /// Converts the member's value to its string representation.
- /// </summary>
- /// <param name="value">The value of the member.</param>
- /// <returns>The string representation of the member's value.</returns>
- private string ToString(object value) {
- return this.converter.ValueToString(value);
- }
-
- /// <summary>
- /// Gets the value of the message part, without converting it to/from a string.
- /// </summary>
- /// <param name="message">The message instance to read from.</param>
- /// <returns>The value of the member.</returns>
- private object GetValueAsObject(IProtocolMessage message) {
- if (this.property != null) {
- return this.property.GetValue(message, null);
- } else {
- return this.field.GetValue(message);
- }
- }
-
- /// <summary>
- /// Validates that the message part and its attribute have agreeable settings.
- /// </summary>
- /// <exception cref="ArgumentException">
- /// Thrown when a non-nullable value type is set as optional.
- /// </exception>
- private void ValidateSettings() {
- if (!this.IsRequired && IsNonNullableValueType(this.memberDeclaredType)) {
- MemberInfo member = (MemberInfo)this.field ?? this.property;
- throw new ArgumentException(
- string.Format(
- CultureInfo.CurrentCulture,
- "Invalid combination: {0} on message type {1} is a non-nullable value type but is marked as optional.",
- member.Name,
- member.DeclaringType));
- }
- }
- }
-}
diff --git a/src/DotNetOAuth/Messaging/Reflection/ValueMapping.cs b/src/DotNetOAuth/Messaging/Reflection/ValueMapping.cs
deleted file mode 100644
index e2d869b..0000000
--- a/src/DotNetOAuth/Messaging/Reflection/ValueMapping.cs
+++ /dev/null
@@ -1,42 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="ValueMapping.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOAuth.Messaging.Reflection {
- using System;
-
- /// <summary>
- /// A pair of conversion functions to map some type to a string and back again.
- /// </summary>
- internal struct ValueMapping {
- /// <summary>
- /// The mapping function that converts some custom type to a string.
- /// </summary>
- internal Func<object, string> ValueToString;
-
- /// <summary>
- /// The mapping function that converts a string to some custom type.
- /// </summary>
- internal Func<string, object> StringToValue;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="ValueMapping"/> struct.
- /// </summary>
- /// <param name="toString">The mapping function that converts some custom type to a string.</param>
- /// <param name="toValue">The mapping function that converts a string to some custom type.</param>
- internal ValueMapping(Func<object, string> toString, Func<string, object> toValue) {
- if (toString == null) {
- throw new ArgumentNullException("toString");
- }
-
- if (toValue == null) {
- throw new ArgumentNullException("toValue");
- }
-
- this.ValueToString = toString;
- this.StringToValue = toValue;
- }
- }
-}
diff --git a/src/DotNetOAuth/Messaging/Response.cs b/src/DotNetOAuth/Messaging/Response.cs
deleted file mode 100644
index 2bce887..0000000
--- a/src/DotNetOAuth/Messaging/Response.cs
+++ /dev/null
@@ -1,178 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="Response.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOAuth.Messaging {
- using System;
- using System.Diagnostics.CodeAnalysis;
- using System.IO;
- using System.Net;
- using System.Text;
- using System.Web;
-
- /// <summary>
- /// A protocol message (request or response) that passes between Consumer and Service Provider
- /// via the user agent using a redirect or form POST submission,
- /// OR a direct message response.
- /// </summary>
- /// <remarks>
- /// <para>An instance of this type describes the HTTP response that must be sent
- /// in response to the current HTTP request.</para>
- /// <para>It is important that this response make up the entire HTTP response.
- /// A hosting ASPX page should not be allowed to render its normal HTML output
- /// after this response is sent. The normal rendered output of an ASPX page
- /// can be canceled by calling <see cref="HttpResponse.End"/> after this message
- /// is sent on the response stream.</para>
- /// </remarks>
- public class Response {
- /// <summary>
- /// Initializes a new instance of the <see cref="Response"/> class.
- /// </summary>
- internal Response() {
- this.Status = HttpStatusCode.OK;
- this.Headers = new WebHeaderCollection();
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="Response"/> class
- /// based on the contents of an <see cref="HttpWebResponse"/>.
- /// </summary>
- /// <param name="response">The <see cref="HttpWebResponse"/> to clone.</param>
- internal Response(HttpWebResponse response) {
- this.Status = response.StatusCode;
- this.Headers = response.Headers;
- this.ResponseStream = new MemoryStream();
- using (Stream responseStream = response.GetResponseStream()) {
- responseStream.CopyTo(this.ResponseStream);
- this.ResponseStream.Seek(0, SeekOrigin.Begin);
- }
- }
-
- /// <summary>
- /// Gets the headers that must be included in the response to the user agent.
- /// </summary>
- /// <remarks>
- /// The headers in this collection are not meant to be a comprehensive list
- /// of exactly what should be sent, but are meant to augment whatever headers
- /// are generally included in a typical response.
- /// </remarks>
- public WebHeaderCollection Headers { get; internal set; }
-
- /// <summary>
- /// Gets the body of the HTTP response.
- /// </summary>
- public Stream ResponseStream { get; internal set; }
-
- /// <summary>
- /// Gets a value indicating whether the response stream is incomplete due
- /// to a length limitation imposed by the HttpWebRequest or calling method.
- /// </summary>
- public bool IsResponseTruncated { get; internal set; }
-
- /// <summary>
- /// Gets or sets the body of the response as a string.
- /// </summary>
- public string Body {
- get { return this.ResponseStream != null ? this.GetResponseReader().ReadToEnd() : null; }
- set { this.SetResponse(value); }
- }
-
- /// <summary>
- /// Gets the HTTP status code to use in the HTTP response.
- /// </summary>
- public HttpStatusCode Status { get; internal set; }
-
- /// <summary>
- /// Gets or sets a reference to the actual protocol message that
- /// is being sent via the user agent.
- /// </summary>
- internal IProtocolMessage OriginalMessage { get; set; }
-
- /// <summary>
- /// Gets the URI that, when requested with an HTTP GET request,
- /// would transmit the message that normally would be transmitted via a user agent redirect.
- /// </summary>
- /// <remarks>
- /// This is useful for desktop applications that will spawn a user agent to transmit the message
- /// rather than cause a redirect.
- /// </remarks>
- internal Uri DirectUriRequest {
- get {
- var message = this.OriginalMessage as IDirectedProtocolMessage;
- if (message == null) {
- throw new InvalidOperationException(); // this only makes sense for directed messages (indirect responses)
- }
-
- var serializer = MessageSerializer.Get(message.GetType());
- var fields = serializer.Serialize(message);
- UriBuilder builder = new UriBuilder(message.Recipient);
- MessagingUtilities.AppendQueryArgs(builder, fields);
- return builder.Uri;
- }
- }
-
- /// <summary>
- /// Creates a text reader for the response stream.
- /// </summary>
- /// <returns>The text reader, initialized for the proper encoding.</returns>
- [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "Costly operation")]
- public StreamReader GetResponseReader() {
- this.ResponseStream.Seek(0, SeekOrigin.Begin);
- string contentEncoding = this.Headers[HttpResponseHeader.ContentEncoding];
- if (string.IsNullOrEmpty(contentEncoding)) {
- return new StreamReader(this.ResponseStream);
- } else {
- return new StreamReader(this.ResponseStream, Encoding.GetEncoding(contentEncoding));
- }
- }
-
- /// <summary>
- /// Automatically sends the appropriate response to the user agent.
- /// Requires a current HttpContext.
- /// </summary>
- public void Send() {
- if (HttpContext.Current == null) {
- throw new InvalidOperationException(MessagingStrings.CurrentHttpContextRequired);
- }
-
- HttpContext.Current.Response.Clear();
- HttpContext.Current.Response.StatusCode = (int)this.Status;
- MessagingUtilities.ApplyHeadersToResponse(this.Headers, HttpContext.Current.Response);
- if (this.ResponseStream != null) {
- try {
- this.ResponseStream.CopyTo(HttpContext.Current.Response.OutputStream);
- } catch (HttpException ex) {
- if (ex.ErrorCode == -2147467259 && HttpContext.Current.Response.Output != null) {
- // Test scenarios can generate this, since the stream is being spoofed:
- // System.Web.HttpException: OutputStream is not available when a custom TextWriter is used.
- HttpContext.Current.Response.Output.Write(this.Body);
- } else {
- throw;
- }
- }
- }
- HttpContext.Current.Response.End();
- }
-
- /// <summary>
- /// Sets the response to some string, encoded as UTF-8.
- /// </summary>
- /// <param name="body">The string to set the response to.</param>
- internal void SetResponse(string body) {
- if (body == null) {
- this.ResponseStream = null;
- return;
- }
-
- Encoding encoding = Encoding.UTF8;
- this.Headers[HttpResponseHeader.ContentEncoding] = encoding.HeaderName;
- this.ResponseStream = new MemoryStream();
- StreamWriter writer = new StreamWriter(this.ResponseStream, encoding);
- writer.Write(body);
- writer.Flush();
- this.ResponseStream.Seek(0, SeekOrigin.Begin);
- }
- }
-}
diff --git a/src/DotNetOAuth/Messaging/UnprotectedMessageException.cs b/src/DotNetOAuth/Messaging/UnprotectedMessageException.cs
deleted file mode 100644
index 3e824f2..0000000
--- a/src/DotNetOAuth/Messaging/UnprotectedMessageException.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="UnprotectedMessageException.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOAuth.Messaging {
- using System;
- using System.Globalization;
-
- /// <summary>
- /// An exception thrown when messages cannot receive all the protections they require.
- /// </summary>
- [Serializable]
- internal class UnprotectedMessageException : ProtocolException {
- /// <summary>
- /// Initializes a new instance of the <see cref="UnprotectedMessageException"/> class.
- /// </summary>
- /// <param name="faultedMessage">The message whose protection requirements could not be met.</param>
- /// <param name="appliedProtection">The protection requirements that were fulfilled.</param>
- internal UnprotectedMessageException(IProtocolMessage faultedMessage, MessageProtections appliedProtection)
- : base(string.Format(CultureInfo.CurrentCulture, MessagingStrings.InsufficentMessageProtection, faultedMessage.RequiredProtection, appliedProtection), faultedMessage) {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="UnprotectedMessageException"/> class.
- /// </summary>
- /// <param name="info">The <see cref="System.Runtime.Serialization.SerializationInfo"/>
- /// that holds the serialized object data about the exception being thrown.</param>
- /// <param name="context">The System.Runtime.Serialization.StreamingContext
- /// that contains contextual information about the source or destination.</param>
- protected UnprotectedMessageException(
- System.Runtime.Serialization.SerializationInfo info,
- System.Runtime.Serialization.StreamingContext context)
- : base(info, context) { }
- }
-}