diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2008-11-18 22:26:32 -0800 |
---|---|---|
committer | Andrew <andrewarnott@gmail.com> | 2008-11-18 22:26:32 -0800 |
commit | 9374f87b8e56f17a1b386547faf40ea5e5ffbd7d (patch) | |
tree | 902eec70793cc5e5cdf8e1a8120ae7c21ceefbff /src | |
parent | 881003619a0b2fd3a9d61a7ee9df42d087dfdf27 (diff) | |
download | DotNetOpenAuth-9374f87b8e56f17a1b386547faf40ea5e5ffbd7d.zip DotNetOpenAuth-9374f87b8e56f17a1b386547faf40ea5e5ffbd7d.tar.gz DotNetOpenAuth-9374f87b8e56f17a1b386547faf40ea5e5ffbd7d.tar.bz2 |
FxCop message fixes.
Diffstat (limited to 'src')
19 files changed, 138 insertions, 97 deletions
diff --git a/src/DotNetOpenAuth.Test/OpenId/ChannelElements/KeyValueFormEncodingTests.cs b/src/DotNetOpenAuth.Test/OpenId/ChannelElements/KeyValueFormEncodingTests.cs index fff1392..7b98ac2 100644 --- a/src/DotNetOpenAuth.Test/OpenId/ChannelElements/KeyValueFormEncodingTests.cs +++ b/src/DotNetOpenAuth.Test/OpenId/ChannelElements/KeyValueFormEncodingTests.cs @@ -35,9 +35,7 @@ namespace DotNetOpenAuth.Test.OpenId.ChannelElements { [TestMethod] public void BasicEncodingTest() { - var kvf = new KeyValueFormEncoding(); - - byte[] kvfBytes = kvf.GetBytes(this.sampleData); + byte[] kvfBytes = KeyValueFormEncoding.GetBytes(this.sampleData); string responseString = Encoding.UTF8.GetString(kvfBytes); Assert.IsFalse(responseString.Contains("\n\n")); @@ -66,7 +64,7 @@ namespace DotNetOpenAuth.Test.OpenId.ChannelElements { } } if ((mode & TestMode.Encoder) == TestMode.Encoder) { - var e = this.keyValueForm.GetBytes(dict); + var e = KeyValueFormEncoding.GetBytes(dict); Assert.IsTrue(MessagingUtilities.AreEquivalent(e, kvform), "Encoder did not produced expected result."); } } diff --git a/src/DotNetOpenAuth.Test/OpenId/ChannelElements/OpenIdChannelTests.cs b/src/DotNetOpenAuth.Test/OpenId/ChannelElements/OpenIdChannelTests.cs index ef0ec53..cd4b4b6 100644 --- a/src/DotNetOpenAuth.Test/OpenId/ChannelElements/OpenIdChannelTests.cs +++ b/src/DotNetOpenAuth.Test/OpenId/ChannelElements/OpenIdChannelTests.cs @@ -60,7 +60,7 @@ namespace DotNetOpenAuth.Test.OpenId.ChannelElements { public void DirectResponsesSentUsingKeyValueForm() { IProtocolMessage message = MessagingTestBase.GetStandardTestMessage(MessagingTestBase.FieldFill.AllRequired); MessageDictionary messageFields = new MessageDictionary(message); - byte[] expectedBytes = new KeyValueFormEncoding().GetBytes(messageFields); + byte[] expectedBytes = KeyValueFormEncoding.GetBytes(messageFields); string expectedContentType = OpenIdChannel_Accessor.KeyValueFormContentType; Response directResponse = this.accessor.SendDirectMessageResponse(message); @@ -79,9 +79,8 @@ namespace DotNetOpenAuth.Test.OpenId.ChannelElements { { "var1", "value1" }, { "var2", "value2" }, }; - KeyValueFormEncoding kvf = new KeyValueFormEncoding(); Response response = new Response { - ResponseStream = new MemoryStream(kvf.GetBytes(fields)), + ResponseStream = new MemoryStream(KeyValueFormEncoding.GetBytes(fields)), }; Assert.IsTrue(MessagingUtilities.AreEquivalent(fields, this.accessor.ReadFromResponseInternal(response))); } diff --git a/src/DotNetOpenAuth.Test/OpenId/OpenIdScenarioTests.cs b/src/DotNetOpenAuth.Test/OpenId/OpenIdScenarioTests.cs index f56f576..db0bf27 100644 --- a/src/DotNetOpenAuth.Test/OpenId/OpenIdScenarioTests.cs +++ b/src/DotNetOpenAuth.Test/OpenId/OpenIdScenarioTests.cs @@ -26,7 +26,6 @@ namespace DotNetOpenAuth.Test.OpenId { OpenIdCoordinator coordinator = new OpenIdCoordinator( rp => { rpAssociation = rp.GetAssociation(opDescription); - Assert.IsNotNull(rpAssociation); }, op => { op.AutoRespond(); @@ -39,6 +38,7 @@ namespace DotNetOpenAuth.Test.OpenId { } }; coordinator.Run(); + Assert.IsNotNull(rpAssociation); Assert.AreSame(rpAssociation, coordinator.RelyingParty.AssociationStore.GetAssociation(opDescription.Endpoint, rpAssociation.Handle)); opAssociation = coordinator.Provider.AssociationStore.GetAssociation(AssociationRelyingPartyType.Smart, rpAssociation.Handle); Assert.IsNotNull(opAssociation, "The Provider should have stored the association."); @@ -58,7 +58,6 @@ namespace DotNetOpenAuth.Test.OpenId { OpenIdCoordinator coordinator = new OpenIdCoordinator( rp => { rpAssociation = rp.GetAssociation(opDescription); - Assert.IsNotNull(rpAssociation); }, op => { op.AutoRespond(); @@ -75,6 +74,7 @@ namespace DotNetOpenAuth.Test.OpenId { unencryptedRequestSent |= message is AssociateUnencryptedRequest; }; coordinator.Run(); + Assert.IsNotNull(rpAssociation); Assert.AreSame(rpAssociation, coordinator.RelyingParty.AssociationStore.GetAssociation(opDescription.Endpoint, rpAssociation.Handle)); opAssociation = coordinator.Provider.AssociationStore.GetAssociation(AssociationRelyingPartyType.Smart, rpAssociation.Handle); Assert.IsNotNull(opAssociation, "The Provider should have stored the association."); diff --git a/src/DotNetOpenAuth/GlobalSuppressions.cs b/src/DotNetOpenAuth/GlobalSuppressions.cs index 487cc0c..aed15eb 100644 --- a/src/DotNetOpenAuth/GlobalSuppressions.cs +++ b/src/DotNetOpenAuth/GlobalSuppressions.cs @@ -9,7 +9,19 @@ // "In Project Suppression File". // You do not need to add suppressions to this file manually. -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Sha", Scope = "type", Target = "DotNetOAuth.OAuth.ChannelElements.HmacSha1SigningBindingElement")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Hmac", Scope = "type", Target = "DotNetOAuth.OAuth.ChannelElements.HmacSha1SigningBindingElement")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Rsa", Scope = "type", Target = "DotNetOAuth.OAuth.ChannelElements.RsaSha1SigningBindingElement")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Sha", Scope = "type", Target = "DotNetOAuth.OAuth.ChannelElements.RsaSha1SigningBindingElement")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Sha", Scope = "type", Target = "DotNetOpenAuth.OAuth.ChannelElements.HmacSha1SigningBindingElement")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Hmac", Scope = "type", Target = "DotNetOpenAuth.OAuth.ChannelElements.HmacSha1SigningBindingElement")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Rsa", Scope = "type", Target = "DotNetOpenAuth.OAuth.ChannelElements.RsaSha1SigningBindingElement")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Sha", Scope = "type", Target = "DotNetOpenAuth.OAuth.ChannelElements.RsaSha1SigningBindingElement")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1703:ResourceStringsShouldBeSpelledCorrectly", MessageId = "Diffie-Hellman", Scope = "resource", Target = "DotNetOpenAuth.OpenId.OpenIdStrings.resources")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "checkInput", Scope = "member", Target = "Org.Mentalis.Security.Cryptography.DiffieHellmanManaged.#Initialize(Mono.Math.BigInteger,Mono.Math.BigInteger,Mono.Math.BigInteger,System.Int32,System.Boolean)")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2208:InstantiateArgumentExceptionsCorrectly", Scope = "member", Target = "Org.Mentalis.Security.Cryptography.DiffieHellmanManaged.#.ctor(System.Int32,System.Int32,Org.Mentalis.Security.Cryptography.DHKeyGeneration)")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2208:InstantiateArgumentExceptionsCorrectly", Scope = "member", Target = "Org.Mentalis.Security.Cryptography.DiffieHellmanManaged.#.ctor(System.Byte[],System.Byte[],System.Int32)")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2208:InstantiateArgumentExceptionsCorrectly", Scope = "member", Target = "Org.Mentalis.Security.Cryptography.DiffieHellmanManaged.#.ctor(System.Byte[],System.Byte[],System.Byte[])")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2208:InstantiateArgumentExceptionsCorrectly", Scope = "member", Target = "Org.Mentalis.Security.Cryptography.DiffieHellman.#FromXmlString(System.String)")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1804:RemoveUnusedLocals", MessageId = "PostTrialDivisionTest", Scope = "member", Target = "Mono.Math.Prime.Generator.SequentialSearchPrimeGeneratorBase.#GenerateNewPrime(System.Int32,System.Object)")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2201:DoNotRaiseReservedExceptionTypes", Scope = "member", Target = "Mono.Math.Prime.PrimalityTests.#GetSPPRounds(Mono.Math.BigInteger,Mono.Math.Prime.ConfidenceFactor)")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2201:DoNotRaiseReservedExceptionTypes", Scope = "member", Target = "Mono.Math.BigInteger+ModulusRing.#BarrettReduction(Mono.Math.BigInteger)")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2201:DoNotRaiseReservedExceptionTypes", Scope = "member", Target = "Mono.Math.BigInteger.#op_Multiply(Mono.Math.BigInteger,Mono.Math.BigInteger)")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "sign", Scope = "member", Target = "Mono.Math.BigInteger.#.ctor(Mono.Math.BigInteger+Sign,System.UInt32)")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "notUsed", Scope = "member", Target = "Mono.Math.BigInteger.#isProbablePrime(System.Int32)")] diff --git a/src/DotNetOpenAuth/Messaging/Channel.cs b/src/DotNetOpenAuth/Messaging/Channel.cs index e6a8ed0..190fd36 100644 --- a/src/DotNetOpenAuth/Messaging/Channel.cs +++ b/src/DotNetOpenAuth/Messaging/Channel.cs @@ -9,6 +9,7 @@ namespace DotNetOpenAuth.Messaging { using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; + using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; using System.Linq; @@ -173,7 +174,7 @@ namespace DotNetOpenAuth.Messaging { /// <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> + /// <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> @@ -181,35 +182,35 @@ namespace DotNetOpenAuth.Messaging { /// </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); + 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> + /// <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 { + 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; + request = untypedRequest as TRequest; if (request == null) { throw new ProtocolException( string.Format( CultureInfo.CurrentCulture, MessagingStrings.UnexpectedMessageReceived, - typeof(TREQUEST), + typeof(TRequest), untypedRequest.GetType())); } @@ -219,36 +220,38 @@ namespace DotNetOpenAuth.Messaging { /// <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> + /// <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()); + [SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter", Justification = "This returns and verifies the appropriate message type.")] + 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> + /// <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)) { + [SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter", Justification = "This returns and verifies the appropriate message type.")] + 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))); + typeof(TRequest))); } } @@ -270,20 +273,21 @@ namespace DotNetOpenAuth.Messaging { /// <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> + /// <typeparam name="TResponse">The expected type of the message to be received.</typeparam> + /// <param name="requestMessage">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); - ErrorUtilities.VerifyProtocol(response != null, MessagingStrings.ExpectedMessageNotReceived, typeof(TRESPONSE)); + [SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter", Justification = "This returns and verifies the appropriate message type.")] + public TResponse Request<TResponse>(IDirectedProtocolMessage requestMessage) + where TResponse : class, IProtocolMessage { + IProtocolMessage response = this.Request(requestMessage); + ErrorUtilities.VerifyProtocol(response != null, MessagingStrings.ExpectedMessageNotReceived, typeof(TResponse)); - var expectedResponse = response as TRESPONSE; - ErrorUtilities.VerifyProtocol(expectedResponse != null, MessagingStrings.UnexpectedMessageReceived, typeof(TRESPONSE), response.GetType()); + var expectedResponse = response as TResponse; + ErrorUtilities.VerifyProtocol(expectedResponse != null, MessagingStrings.UnexpectedMessageReceived, typeof(TResponse), response.GetType()); return expectedResponse; } @@ -291,17 +295,17 @@ namespace DotNetOpenAuth.Messaging { /// <summary> /// Sends a direct message to a remote party and waits for the response. /// </summary> - /// <param name="request">The message to send.</param> + /// <param name="requestMessage">The message to send.</param> /// <returns>The remote party's response. Guaranteed to never be null.</returns> /// <exception cref="ProtocolException">Thrown if the response does not include a protocol message.</exception> - public IProtocolMessage Request(IDirectedProtocolMessage request) { - if (request == null) { - throw new ArgumentNullException("request"); + public IProtocolMessage Request(IDirectedProtocolMessage requestMessage) { + if (requestMessage == null) { + throw new ArgumentNullException("requestMessage"); } - this.PrepareMessageForSending(request); - Logger.DebugFormat("Sending request: {0}", request); - var responseMessage = this.RequestInternal(request); + this.PrepareMessageForSending(requestMessage); + Logger.DebugFormat("Sending request: {0}", requestMessage); + var responseMessage = this.RequestInternal(requestMessage); ErrorUtilities.VerifyProtocol(responseMessage != null, MessagingStrings.ExpectedMessageNotReceived, typeof(IProtocolMessage).Name); Logger.DebugFormat("Received message response: {0}", responseMessage); @@ -318,6 +322,7 @@ namespace DotNetOpenAuth.Messaging { /// Requires an HttpContext.Current context. /// </remarks> /// <exception cref="InvalidOperationException">Thrown when <see cref="HttpContext.Current"/> is null.</exception> + [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "Costly call should not be a property.")] protected internal virtual HttpRequestInfo GetRequestFromContext() { if (HttpContext.Current == null) { throw new InvalidOperationException(MessagingStrings.HttpContextRequired); diff --git a/src/DotNetOpenAuth/Messaging/InternalErrorException.cs b/src/DotNetOpenAuth/Messaging/InternalErrorException.cs index 12147f5..32b44f2 100644 --- a/src/DotNetOpenAuth/Messaging/InternalErrorException.cs +++ b/src/DotNetOpenAuth/Messaging/InternalErrorException.cs @@ -6,9 +6,7 @@ namespace DotNetOpenAuth.Messaging { using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; + using System.Diagnostics.CodeAnalysis; /// <summary> /// An internal exception to throw if an internal error within the library requires @@ -18,7 +16,8 @@ namespace DotNetOpenAuth.Messaging { /// This exception is internal to prevent clients of the library from catching what is /// really an unexpected, potentially unrecoverable exception. /// </remarks> - [global::System.Serializable] + [SuppressMessage("Microsoft.Design", "CA1064:ExceptionsShouldBePublic", Justification = "We want this to be internal so clients cannot catch it.")] + [Serializable] internal class InternalErrorException : Exception { /// <summary> /// Initializes a new instance of the <see cref="InternalErrorException"/> class. diff --git a/src/DotNetOpenAuth/Messaging/MessagingUtilities.cs b/src/DotNetOpenAuth/Messaging/MessagingUtilities.cs index af59b40..042d531 100644 --- a/src/DotNetOpenAuth/Messaging/MessagingUtilities.cs +++ b/src/DotNetOpenAuth/Messaging/MessagingUtilities.cs @@ -8,6 +8,7 @@ namespace DotNetOpenAuth.Messaging { using System; using System.Collections.Generic; using System.Collections.Specialized; + using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; using System.Net; @@ -31,6 +32,8 @@ namespace DotNetOpenAuth.Messaging { /// Cookieless session directory (if applicable) is also included. /// </summary> /// <returns>The URL in the user agent's Location bar.</returns> + [SuppressMessage("Microsoft.Usage", "CA2234:PassSystemUriObjectsInsteadOfStrings", Justification = "The Uri merging requires use of a string value.")] + [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "Expensive call should not be a property.")] public static Uri GetRequestUrlFromContext() { HttpContext context = HttpContext.Current; if (context == null) { diff --git a/src/DotNetOpenAuth/Messaging/ProtocolException.cs b/src/DotNetOpenAuth/Messaging/ProtocolException.cs index e4a0a44..db79b00 100644 --- a/src/DotNetOpenAuth/Messaging/ProtocolException.cs +++ b/src/DotNetOpenAuth/Messaging/ProtocolException.cs @@ -184,6 +184,13 @@ namespace DotNetOpenAuth.Messaging { } /// <summary> + /// Gets the preferred method of transport for the message. + /// </summary> + protected HttpDeliveryMethods HttpMethods { + get { return ((IDirectedProtocolMessage)this).HttpMethods; } + } + + /// <summary> /// Gets the URL of the intended receiver of this message. /// </summary> /// <remarks> @@ -230,6 +237,14 @@ namespace DotNetOpenAuth.Messaging { } /// <summary> + /// Gets or sets a value indicating whether this message was deserialized as an incoming message. + /// </summary> + protected bool Incoming { + get { return ((IProtocolMessage)this).Incoming; } + set { ((IProtocolMessage)this).Incoming = value; } + } + + /// <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> diff --git a/src/DotNetOpenAuth/OAuth/ChannelElements/StandardTokenGenerator.cs b/src/DotNetOpenAuth/OAuth/ChannelElements/StandardTokenGenerator.cs index 6d399a4..d18f5fe 100644 --- a/src/DotNetOpenAuth/OAuth/ChannelElements/StandardTokenGenerator.cs +++ b/src/DotNetOpenAuth/OAuth/ChannelElements/StandardTokenGenerator.cs @@ -25,7 +25,7 @@ namespace DotNetOpenAuth.OAuth.ChannelElements { /// This will be done in <see cref="ITokenManager.StoreNewRequestToken"/>. /// </remarks> public string GenerateRequestToken(string consumerKey) { - return this.GenerateCryptographicallyStrongString(); + return GenerateCryptographicallyStrongString(); } /// <summary> @@ -38,7 +38,7 @@ namespace DotNetOpenAuth.OAuth.ChannelElements { /// This will be done in <see cref="ITokenManager.ExpireRequestTokenAndStoreNewAccessToken"/>. /// </remarks> public string GenerateAccessToken(string consumerKey) { - return this.GenerateCryptographicallyStrongString(); + return GenerateCryptographicallyStrongString(); } /// <summary> @@ -46,7 +46,7 @@ namespace DotNetOpenAuth.OAuth.ChannelElements { /// </summary> /// <returns>The generated string.</returns> public string GenerateSecret() { - return this.GenerateCryptographicallyStrongString(); + return GenerateCryptographicallyStrongString(); } #endregion @@ -55,7 +55,7 @@ namespace DotNetOpenAuth.OAuth.ChannelElements { /// Returns a new random string. /// </summary> /// <returns>The new random string.</returns> - private string GenerateCryptographicallyStrongString() { + private static string GenerateCryptographicallyStrongString() { byte[] buffer = new byte[20]; MessagingUtilities.CryptoRandomDataGenerator.GetBytes(buffer); return Convert.ToBase64String(buffer); diff --git a/src/DotNetOpenAuth/OAuth/Messages/MessageBase.cs b/src/DotNetOpenAuth/OAuth/Messages/MessageBase.cs index f9844e4..4cf04db 100644 --- a/src/DotNetOpenAuth/OAuth/Messages/MessageBase.cs +++ b/src/DotNetOpenAuth/OAuth/Messages/MessageBase.cs @@ -162,6 +162,14 @@ namespace DotNetOpenAuth.OAuth.Messages { } /// <summary> + /// Gets or sets a value indicating whether this message was deserialized as an incoming message. + /// </summary> + protected bool Incoming { + get { return ((IProtocolMessage)this).Incoming; } + set { ((IProtocolMessage)this).Incoming = value; } + } + + /// <summary> /// Gets the preferred method of transport for the message. /// </summary> protected HttpDeliveryMethods HttpMethods { diff --git a/src/DotNetOpenAuth/OpenId/ChannelElements/KeyValueFormEncoding.cs b/src/DotNetOpenAuth/OpenId/ChannelElements/KeyValueFormEncoding.cs index c6f5508..5d9dadb 100644 --- a/src/DotNetOpenAuth/OpenId/ChannelElements/KeyValueFormEncoding.cs +++ b/src/DotNetOpenAuth/OpenId/ChannelElements/KeyValueFormEncoding.cs @@ -98,7 +98,7 @@ namespace DotNetOpenAuth.OpenId.ChannelElements { /// If ordering of the key=value pairs is important, a deterministic enumerator must /// be used. /// </remarks> - public byte[] GetBytes(IEnumerable<KeyValuePair<string, string>> keysAndValues) { + public static byte[] GetBytes(IEnumerable<KeyValuePair<string, string>> keysAndValues) { ErrorUtilities.VerifyArgumentNotNull(keysAndValues, "keysAndValues"); MemoryStream ms = new MemoryStream(); diff --git a/src/DotNetOpenAuth/OpenId/ChannelElements/OpenIdChannel.cs b/src/DotNetOpenAuth/OpenId/ChannelElements/OpenIdChannel.cs index c514baf..7850e75 100644 --- a/src/DotNetOpenAuth/OpenId/ChannelElements/OpenIdChannel.cs +++ b/src/DotNetOpenAuth/OpenId/ChannelElements/OpenIdChannel.cs @@ -92,7 +92,7 @@ namespace DotNetOpenAuth.OpenId.ChannelElements { var serializer = MessageSerializer.Get(response.GetType()); var fields = serializer.Serialize(response); - byte[] keyValueEncoding = this.keyValueForm.GetBytes(fields); + byte[] keyValueEncoding = KeyValueFormEncoding.GetBytes(fields); Response preparedResponse = new Response(); preparedResponse.Headers.Add(HttpResponseHeader.ContentType, KeyValueFormContentType); diff --git a/src/DotNetOpenAuth/OpenId/ChannelElements/SigningBindingElement.cs b/src/DotNetOpenAuth/OpenId/ChannelElements/SigningBindingElement.cs index 624b157..4a5129c 100644 --- a/src/DotNetOpenAuth/OpenId/ChannelElements/SigningBindingElement.cs +++ b/src/DotNetOpenAuth/OpenId/ChannelElements/SigningBindingElement.cs @@ -64,8 +64,8 @@ namespace DotNetOpenAuth.OpenId.ChannelElements { // TODO: code here ////signedMessage.AssociationHandle = } - signedMessage.SignedParameterOrder = this.GetSignedParameterOrder(signedMessage); - signedMessage.Signature = this.GetSignature(signedMessage); + signedMessage.SignedParameterOrder = GetSignedParameterOrder(signedMessage); + signedMessage.Signature = GetSignature(signedMessage); return true; } @@ -90,7 +90,7 @@ namespace DotNetOpenAuth.OpenId.ChannelElements { if (signedMessage != null) { Logger.DebugFormat("Verifying incoming {0} message signature of: {1}", message.GetType().Name, signedMessage.Signature); - string signature = this.GetSignature(signedMessage); + string signature = GetSignature(signedMessage); if (!string.Equals(signedMessage.Signature, signature, StringComparison.Ordinal)) { Logger.Error("Signature verification failed."); throw new InvalidSignatureException(message); @@ -105,6 +105,27 @@ namespace DotNetOpenAuth.OpenId.ChannelElements { #endregion /// <summary> + /// Calculates the signature for a given message. + /// </summary> + /// <param name="signedMessage">The message to sign.</param> + /// <returns>The calculated signature of the method.</returns> + private static string GetSignature(ITamperResistantOpenIdMessage signedMessage) { + ErrorUtilities.VerifyArgumentNotNull(signedMessage, "signedMessage"); + ErrorUtilities.VerifyNonZeroLength(signedMessage.SignedParameterOrder, "signedMessage.SignedParameterOrder"); + + MessageDictionary dictionary = new MessageDictionary(signedMessage); + var parametersToSign = from name in signedMessage.SignedParameterOrder.Split(',') + let prefixedName = Protocol.V20.openid.Prefix + name + select new KeyValuePair<string, string>(prefixedName, dictionary[prefixedName]); + + byte[] dataToSign = KeyValueFormEncoding.GetBytes(parametersToSign); + + Association association = null; // TODO: fetch the association to use + string signature = Convert.ToBase64String(association.Sign(dataToSign)); + return signature; + } + + /// <summary> /// Gets the value to use for the openid.signed parameter. /// </summary> /// <param name="signedMessage">The signable message.</param> @@ -112,7 +133,7 @@ namespace DotNetOpenAuth.OpenId.ChannelElements { /// A comma-delimited list of parameter names, omitting the 'openid.' prefix, that determines /// the inclusion and order of message parts that will be signed. /// </returns> - private string GetSignedParameterOrder(ITamperResistantOpenIdMessage signedMessage) { + private static string GetSignedParameterOrder(ITamperResistantOpenIdMessage signedMessage) { ErrorUtilities.VerifyArgumentNotNull(signedMessage, "signedMessage"); MessageDescription description = MessageDescription.Get(signedMessage.GetType()); @@ -125,27 +146,5 @@ namespace DotNetOpenAuth.OpenId.ChannelElements { string signedFields = string.Join(",", signedParts.Select(name => name.Substring(skipLength)).ToArray()); return signedFields; } - - /// <summary> - /// Calculates the signature for a given message. - /// </summary> - /// <param name="signedMessage">The message to sign.</param> - /// <returns>The calculated signature of the method.</returns> - private string GetSignature(ITamperResistantOpenIdMessage signedMessage) { - ErrorUtilities.VerifyArgumentNotNull(signedMessage, "signedMessage"); - ErrorUtilities.VerifyNonZeroLength(signedMessage.SignedParameterOrder, "signedMessage.SignedParameterOrder"); - - MessageDictionary dictionary = new MessageDictionary(signedMessage); - var parametersToSign = from name in signedMessage.SignedParameterOrder.Split(',') - let prefixedName = Protocol.V20.openid.Prefix + name - select new KeyValuePair<string, string>(prefixedName, dictionary[prefixedName]); - - KeyValueFormEncoding keyValueForm = new KeyValueFormEncoding(); - byte[] dataToSign = keyValueForm.GetBytes(parametersToSign); - - Association association = null; // TODO: fetch the association to use - string signature = Convert.ToBase64String(association.Sign(dataToSign)); - return signature; - } } } diff --git a/src/DotNetOpenAuth/OpenId/Messages/AssociateDiffieHellmanResponse.cs b/src/DotNetOpenAuth/OpenId/Messages/AssociateDiffieHellmanResponse.cs index 0f3d729..432595b 100644 --- a/src/DotNetOpenAuth/OpenId/Messages/AssociateDiffieHellmanResponse.cs +++ b/src/DotNetOpenAuth/OpenId/Messages/AssociateDiffieHellmanResponse.cs @@ -42,8 +42,8 @@ namespace DotNetOpenAuth.OpenId.Messages { /// </remarks> protected override Association CreateAssociationAtRelyingParty(AssociateRequest request) { ErrorUtilities.VerifyArgumentNotNull(request, "request"); - ErrorUtilities.VerifyArgument(request is AssociateDiffieHellmanRequest, "request"); - var diffieHellmanRequest = (AssociateDiffieHellmanRequest)request; + var diffieHellmanRequest = request as AssociateDiffieHellmanRequest; + ErrorUtilities.VerifyArgument(diffieHellmanRequest != null, "request"); HashAlgorithm hasher = DiffieHellmanUtilities.Lookup(Protocol, this.SessionType); byte[] associationSecret = DiffieHellmanUtilities.SHAHashXorSecret(hasher, diffieHellmanRequest.Algorithm, this.DiffieHellmanServerPublic, this.EncodedMacKey); @@ -63,8 +63,8 @@ namespace DotNetOpenAuth.OpenId.Messages { /// </remarks> protected override Association CreateAssociationAtProvider(AssociateRequest request) { ErrorUtilities.VerifyArgumentNotNull(request, "request"); - ErrorUtilities.VerifyArgument(request is AssociateDiffieHellmanRequest, "request"); - var diffieHellmanRequest = (AssociateDiffieHellmanRequest)request; + var diffieHellmanRequest = request as AssociateDiffieHellmanRequest; + ErrorUtilities.VerifyArgument(diffieHellmanRequest != null, "request"); this.SessionType = this.SessionType ?? request.SessionType; diff --git a/src/DotNetOpenAuth/OpenId/Messages/AssociateUnsuccessfulResponse.cs b/src/DotNetOpenAuth/OpenId/Messages/AssociateUnsuccessfulResponse.cs index e2b4325..ad79a87 100644 --- a/src/DotNetOpenAuth/OpenId/Messages/AssociateUnsuccessfulResponse.cs +++ b/src/DotNetOpenAuth/OpenId/Messages/AssociateUnsuccessfulResponse.cs @@ -6,6 +6,7 @@ namespace DotNetOpenAuth.OpenId.Messages { using System.Diagnostics; + using System.Diagnostics.CodeAnalysis; using DotNetOpenAuth.Messaging; /// <summary> @@ -20,6 +21,7 @@ namespace DotNetOpenAuth.OpenId.Messages { /// A hard-coded string indicating an error occurred. /// </summary> /// <value>"unsupported-type" </value> + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields", Justification = "Read by reflection")] [MessagePart("error_code", IsRequired = true, AllowEmpty = false)] #pragma warning disable 0414 // read by reflection private readonly string Error = "unsupported-type"; diff --git a/src/DotNetOpenAuth/OpenId/Messages/DirectResponseBase.cs b/src/DotNetOpenAuth/OpenId/Messages/DirectResponseBase.cs index a1dc3ee..38ec16a 100644 --- a/src/DotNetOpenAuth/OpenId/Messages/DirectResponseBase.cs +++ b/src/DotNetOpenAuth/OpenId/Messages/DirectResponseBase.cs @@ -8,6 +8,7 @@ namespace DotNetOpenAuth.OpenId.Messages { using System; using System.Collections.Generic; using System.Diagnostics; + using System.Diagnostics.CodeAnalysis; using DotNetOpenAuth.Messaging; /// <summary> @@ -25,6 +26,7 @@ namespace DotNetOpenAuth.OpenId.Messages { /// Future versions of the specification may define different values in order to allow message /// recipients to properly interpret the request. /// </remarks> + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields", Justification = "Read by reflection.")] [MessagePart("ns", IsRequired = true, AllowEmpty = false)] #pragma warning disable 0414 // read by reflection private readonly string OpenIdNamespace = Protocol.OpenId2Namespace; diff --git a/src/DotNetOpenAuth/OpenId/Messages/RequestBase.cs b/src/DotNetOpenAuth/OpenId/Messages/RequestBase.cs index 101e4e3..f2c3fc4 100644 --- a/src/DotNetOpenAuth/OpenId/Messages/RequestBase.cs +++ b/src/DotNetOpenAuth/OpenId/Messages/RequestBase.cs @@ -8,6 +8,7 @@ namespace DotNetOpenAuth.OpenId.Messages { using System; using System.Collections.Generic; using System.Diagnostics; + using System.Diagnostics.CodeAnalysis; using DotNetOpenAuth.Messaging; /// <summary> @@ -22,6 +23,7 @@ namespace DotNetOpenAuth.OpenId.Messages { /// <remarks> /// This particular value MUST be present for the request to be a valid OpenID Authentication 2.0 request. Future versions of the specification may define different values in order to allow message recipients to properly interpret the request. /// </remarks> + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields", Justification = "Read by reflection.")] [MessagePart("openid.ns", IsRequired = true, AllowEmpty = false)] #pragma warning disable 0414 // read by reflection private readonly string OpenIdNamespace = Protocol.OpenId2Namespace; diff --git a/src/DotNetOpenAuth/OpenId/OpenIdProvider.cs b/src/DotNetOpenAuth/OpenId/OpenIdProvider.cs index 8ae1559..d1c48e7 100644 --- a/src/DotNetOpenAuth/OpenId/OpenIdProvider.cs +++ b/src/DotNetOpenAuth/OpenId/OpenIdProvider.cs @@ -49,9 +49,6 @@ namespace DotNetOpenAuth.OpenId { var associateRequest = request as AssociateRequest; if (associateRequest != null) { - var associateDiffieHellmanRequest = request as AssociateDiffieHellmanRequest; - var associateUnencryptedRequest = request as AssociateUnencryptedRequest; - IProtocolMessage response = associateRequest.CreateResponse(this.AssociationStore); this.Channel.Send(response); } else { diff --git a/src/DotNetOpenAuth/OpenId/Protocol.cs b/src/DotNetOpenAuth/OpenId/Protocol.cs index 4106ec6..1268925 100644 --- a/src/DotNetOpenAuth/OpenId/Protocol.cs +++ b/src/DotNetOpenAuth/OpenId/Protocol.cs @@ -326,9 +326,9 @@ namespace DotNetOpenAuth.OpenId { public string[] All { get { return new[] { DH_SHA512, DH_SHA384, DH_SHA256, DH_SHA1, NoEncryption }; } } public string[] AllDiffieHellman { get { return new[] { DH_SHA512, DH_SHA384, DH_SHA256, DH_SHA1 }; } } public string DH_SHA1 = "DH-SHA1"; - public string DH_SHA256 = null; - public string DH_SHA384 = null; - public string DH_SHA512 = null; + public string DH_SHA256; + public string DH_SHA384; + public string DH_SHA512; public string NoEncryption = string.Empty; public string Best { get { @@ -347,9 +347,9 @@ namespace DotNetOpenAuth.OpenId { /// </summary> public string[] All { get { return new[] { HMAC_SHA512, HMAC_SHA384, HMAC_SHA256, HMAC_SHA1 }; } } public string HMAC_SHA1 = "HMAC-SHA1"; - public string HMAC_SHA256 = null; - public string HMAC_SHA384 = null; - public string HMAC_SHA512 = null; + public string HMAC_SHA256; + public string HMAC_SHA384; + public string HMAC_SHA512; public string Best { get { foreach (string algorithmName in All) { @@ -369,7 +369,7 @@ namespace DotNetOpenAuth.OpenId { public string checkid_setup = "checkid_setup"; public string check_authentication = "check_authentication"; public string associate = "associate"; - public string setup_needed = null; + public string setup_needed; } internal class IsValidValues { public string True = "true"; |