Permalink
Browse files

Fixed FxCop messages in DNOA.Core #68

  • Loading branch information...
1 parent b6a394f commit cd00f47e375106db6b04a32dff669e5b87c5affb @AArnott AArnott committed Feb 9, 2012
@@ -8,7 +8,9 @@ namespace DotNetOpenAuth {
using System;
using System.Collections.Generic;
using System.Diagnostics;
+ using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
+ using System.Globalization;
using System.Linq;
using System.Text;
@@ -37,7 +39,7 @@ internal static class Assumes {
[Pure, DebuggerStepThrough]
internal static void True(bool condition, string unformattedMessage, params object[] args) {
if (!condition) {
- Fail(String.Format(unformattedMessage, args));
+ Fail(String.Format(CultureInfo.CurrentCulture, unformattedMessage, args));
}
}
@@ -57,6 +59,7 @@ internal static class Assumes {
/// <summary>
/// An internal error exception that should never be caught.
/// </summary>
+ [SuppressMessage("Microsoft.Design", "CA1064:ExceptionsShouldBePublic", Justification = "This exception should never be caught.")]
[Serializable]
private class InternalErrorException : Exception {
/// <summary>
@@ -69,15 +72,8 @@ private class InternalErrorException : Exception {
/// Initializes a new instance of the <see cref="InternalErrorException"/> class.
/// </summary>
/// <param name="message">The message.</param>
- internal InternalErrorException(string message) : base(message) {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="InternalErrorException"/> class.
- /// </summary>
- /// <param name="message">The message.</param>
- /// <param name="inner">The inner exception.</param>
- internal InternalErrorException(string message, Exception inner) : base(message, inner) {
+ internal InternalErrorException(string message)
+ : base(message) {
}
/// <summary>
@@ -7,6 +7,7 @@
namespace DotNetOpenAuth.Configuration {
using System;
using System.Configuration;
+ using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
using System.IO;
using System.Reflection;
@@ -92,6 +93,7 @@ internal class TypeConfigurationElement<T> : ConfigurationElement
/// <param name="defaultValue">The value to return if no type is given in the .config file.</param>
/// <param name="allowInternals">if set to <c>true</c> then internal types may be instantiated.</param>
/// <returns>The newly instantiated type.</returns>
+ [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "No apparent problem. False positive?")]
public T CreateInstance(T defaultValue, bool allowInternals) {
Contract.Ensures(Contract.Result<T>() != null || Contract.Result<T>() == defaultValue);
@@ -121,7 +121,6 @@
<Compile Include="Configuration\HostNameOrRegexCollection.cs" />
<Compile Include="Configuration\HostNameElement.cs" />
<Compile Include="IEmbeddedResourceRetrieval.cs" />
- <Compile Include="GlobalSuppressions.cs" />
<Compile Include="Logger.cs" />
<Compile Include="Loggers\ILog.cs" />
<Compile Include="Loggers\Log4NetLogger.cs" />
@@ -140,7 +139,6 @@
</ItemGroup>
<ItemGroup>
<None Include="Configuration\DotNetOpenAuth.xsd" />
- <None Include="Migrated rules for DotNetOpenAuth.ruleset" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Strings.resx">
@@ -7,6 +7,7 @@
namespace DotNetOpenAuth.Messaging {
using System;
using System.Collections.Generic;
+ using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
using System.IO;
using System.Linq;
@@ -52,6 +53,7 @@ protected internal BinaryDataBagFormatter(ICryptoKeyStore cryptoKeyStore = null,
/// </summary>
/// <param name="message">The message.</param>
/// <returns>The buffer containing the serialized data.</returns>
+ [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "No apparent problem. False positive?")]
protected override byte[] SerializeCore(T message) {
using (var stream = new MemoryStream()) {
message.Serialize(stream);
@@ -64,6 +66,7 @@ protected internal BinaryDataBagFormatter(ICryptoKeyStore cryptoKeyStore = null,
/// </summary>
/// <param name="message">The message instance to initialize with data from the buffer.</param>
/// <param name="data">The data buffer.</param>
+ [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "No apparent problem. False positive?")]
protected override void DeserializeCore(T message, byte[] data) {
using (var stream = new MemoryStream(data)) {
message.Deserialize(stream);
@@ -154,6 +154,7 @@ internal CachedCryptoKey(CryptoKey encrypted, CryptoKey decrypted)
/// Invariant conditions.
/// </summary>
[ContractInvariantMethod]
+ [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Code contracts")]
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "Required for code contracts.")]
private void ObjectInvariant() {
Contract.Invariant(this.EncryptedKey != null);
@@ -817,7 +817,7 @@ public TResponse Request<TResponse>(IDirectedProtocolMessage requestMessage)
if (tooLargeForGet) {
ErrorUtilities.VerifyProtocol(
(message.HttpMethods & HttpDeliveryMethods.PostRequest) == HttpDeliveryMethods.PostRequest,
- "Message too large for a HTTP GET, and HTTP POST is not allowed for this message type.");
+ MessagingStrings.MessageExceedsGetSizePostNotAllowed);
}
// If GET didn't work out, for whatever reason...
@@ -873,6 +873,7 @@ public TResponse Request<TResponse>(IDirectedProtocolMessage requestMessage)
/// <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>
+ [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "No apparent problem. False positive?")]
protected virtual OutgoingWebResponse CreateFormPostResponse(IDirectedProtocolMessage message, IDictionary<string, string> fields) {
Requires.NotNull(message, "message");
Requires.True(message.Recipient != null, "message", MessagingStrings.DirectedMessageMissingRecipient);
@@ -946,6 +947,7 @@ public TResponse Request<TResponse>(IDirectedProtocolMessage requestMessage)
/// <param name="message">The message to serialize.</param>
/// <returns>A JSON string.</returns>
[SuppressMessage("Microsoft.Usage", "CA2202:Do not dispose objects multiple times", Justification = "This Dispose is safe.")]
+ [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "No apparent problem. False positive?")]
protected virtual string SerializeAsJson(IMessage message) {
Requires.NotNull(message, "message");
@@ -966,6 +968,7 @@ public TResponse Request<TResponse>(IDirectedProtocolMessage requestMessage)
/// </summary>
/// <param name="json">A JSON string.</param>
/// <returns>The simple "key":"value" pairs from a JSON-encoded object.</returns>
+ [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "No apparent problem. False positive?")]
protected virtual IDictionary<string, string> DeserializeFromJson(string json) {
Requires.NotNullOrEmpty(json, "json");
@@ -7,6 +7,7 @@
namespace DotNetOpenAuth.Messaging {
using System;
using System.Collections.Generic;
+ using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
using System.IO;
using System.Linq;
@@ -143,6 +144,7 @@ protected DataBagFormatterBase(ICryptoKeyStore cryptoKeyStore = null, string buc
/// </summary>
/// <param name="message">The message to serialize. Must not be null.</param>
/// <returns>A non-null, non-empty value.</returns>
+ [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "No apparent problem. False positive?")]
public string Serialize(T message) {
message.UtcCreationDate = DateTime.UtcNow;
@@ -191,6 +193,7 @@ protected DataBagFormatterBase(ICryptoKeyStore cryptoKeyStore = null, string buc
/// <param name="containingMessage">The message that contains the <see cref="DataBag"/> serialized value. Must not be nulll.</param>
/// <param name="value">The serialized form of the <see cref="DataBag"/> to deserialize. Must not be null or empty.</param>
/// <returns>The deserialized value. Never null.</returns>
+ [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "No apparent problem. False positive?")]
public T Deserialize(IProtocolMessage containingMessage, string value) {
string symmetricSecretHandle = null;
if (this.encrypted && this.cryptoKeyStore != null) {
@@ -271,6 +274,7 @@ protected DataBagFormatterBase(ICryptoKeyStore cryptoKeyStore = null, string buc
/// <returns>
/// <c>true</c> if the signature is valid; otherwise, <c>false</c>.
/// </returns>
+ [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "No apparent problem. False positive?")]
private bool IsSignatureValid(byte[] signedData, byte[] signature, string symmetricSecretHandle) {
Requires.NotNull(signedData, "signedData");
Requires.NotNull(signature, "signature");
@@ -292,6 +296,7 @@ protected DataBagFormatterBase(ICryptoKeyStore cryptoKeyStore = null, string buc
/// <returns>
/// The calculated signature.
/// </returns>
+ [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "No apparent problem. False positive?")]
private byte[] CalculateSignature(byte[] bytesToSign, string symmetricSecretHandle) {
Requires.NotNull(bytesToSign, "bytesToSign");
Requires.ValidState(this.asymmetricSigning != null || this.cryptoKeyStore != null);
@@ -303,7 +308,7 @@ protected DataBagFormatterBase(ICryptoKeyStore cryptoKeyStore = null, string buc
}
} else {
var key = this.cryptoKeyStore.GetKey(this.cryptoKeyBucket, symmetricSecretHandle);
- ErrorUtilities.VerifyProtocol(key != null, "Missing decryption key.");
+ ErrorUtilities.VerifyProtocol(key != null, MessagingStrings.MissingDecryptionKeyForHandle, this.cryptoKeyBucket, symmetricSecretHandle);
using (var symmetricHasher = new HMACSHA256(key.Key)) {
return symmetricHasher.ComputeHash(bytesToSign);
}
@@ -346,7 +351,7 @@ protected DataBagFormatterBase(ICryptoKeyStore cryptoKeyStore = null, string buc
return this.asymmetricEncrypting.DecryptWithRandomSymmetricKey(value);
} else {
var key = this.cryptoKeyStore.GetKey(this.cryptoKeyBucket, symmetricSecretHandle);
- ErrorUtilities.VerifyProtocol(key != null, "Missing decryption key.");
+ ErrorUtilities.VerifyProtocol(key != null, MessagingStrings.MissingDecryptionKeyForHandle, this.cryptoKeyBucket, symmetricSecretHandle);
return MessagingUtilities.Decrypt(value, key.Key);
}
}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -324,4 +324,13 @@
<data name="ExpectedParameterWasMissing" xml:space="preserve">
<value>The message part {0} was expected in the {1} message but was not found.</value>
</data>
+ <data name="MessageExceedsGetSizePostNotAllowed" xml:space="preserve">
+ <value>Message too large for a HTTP GET, and HTTP POST is not allowed for this message type.</value>
+ </data>
+ <data name="MissingDecryptionKeyForHandle" xml:space="preserve">
+ <value>Missing decryption key for bucket "{0}" handle "{1}"</value>
+ </data>
+ <data name="UnexpectedBufferLength" xml:space="preserve">
+ <value>Unexpected buffer length.</value>
+ </data>
</root>
@@ -585,6 +585,7 @@ public static class MessagingUtilities {
/// <param name="buffer">The buffer to encrypt.</param>
/// <param name="key">The symmetric secret to use to encrypt the buffer. Allowed values are 128, 192, or 256 bytes in length.</param>
/// <returns>The encrypted buffer</returns>
+ [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "No apparent problem. False positive?")]
internal static byte[] Encrypt(byte[] buffer, byte[] key) {
using (SymmetricAlgorithm crypto = CreateSymmetricAlgorithm(key)) {
using (var ms = new MemoryStream()) {
@@ -609,6 +610,7 @@ public static class MessagingUtilities {
/// <param name="key">The symmetric secret to use to decrypt the buffer. Allowed values are 128, 192, and 256.</param>
/// <returns>The encrypted buffer</returns>
[SuppressMessage("Microsoft.Usage", "CA2202:Do not dispose objects multiple times", Justification = "This Dispose is safe.")]
+ [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "No apparent problem. False positive?")]
internal static byte[] Decrypt(byte[] buffer, byte[] key) {
using (SymmetricAlgorithm crypto = CreateSymmetricAlgorithm(key)) {
using (var ms = new MemoryStream(buffer)) {
@@ -664,6 +666,7 @@ public static class MessagingUtilities {
/// <param name="crypto">The asymmetric encryption provider to use for encryption.</param>
/// <param name="buffer">The buffer to encrypt.</param>
/// <returns>The encrypted data.</returns>
+ [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "No apparent problem. False positive?")]
internal static byte[] EncryptWithRandomSymmetricKey(this RSACryptoServiceProvider crypto, byte[] buffer) {
Requires.NotNull(crypto, "crypto");
Requires.NotNull(buffer, "buffer");
@@ -699,6 +702,7 @@ public static class MessagingUtilities {
/// <param name="buffer">The buffer to decrypt.</param>
/// <returns>The decrypted data.</returns>
[SuppressMessage("Microsoft.Usage", "CA2202:Do not dispose objects multiple times", Justification = "This Dispose is safe.")]
+ [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "No apparent problem. False positive?")]
internal static byte[] DecryptWithRandomSymmetricKey(this RSACryptoServiceProvider crypto, byte[] buffer) {
Requires.NotNull(crypto, "crypto");
Requires.NotNull(buffer, "buffer");
@@ -781,6 +785,7 @@ public static class MessagingUtilities {
/// <param name="buffer">The buffer to compress.</param>
/// <returns>The compressed data.</returns>
[SuppressMessage("Microsoft.Usage", "CA2202:Do not dispose objects multiple times", Justification = "This Dispose is safe.")]
+ [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "No apparent problem. False positive?")]
internal static byte[] Compress(byte[] buffer) {
Requires.NotNull(buffer, "buffer");
Contract.Ensures(Contract.Result<byte[]>() != null);
@@ -799,6 +804,8 @@ public static class MessagingUtilities {
/// </summary>
/// <param name="buffer">The buffer to decompress.</param>
/// <returns>The decompressed data.</returns>
+ [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "No apparent problem. False positive?")]
+ [SuppressMessage("Microsoft.Usage", "CA2202:Do not dispose objects multiple times", Justification = "This Dispose is safe.")]
internal static byte[] Decompress(byte[] buffer) {
Requires.NotNull(buffer, "buffer");
Contract.Ensures(Contract.Result<byte[]>() != null);
@@ -1543,7 +1550,7 @@ public static class MessagingUtilities {
Requires.NotNull(reader, "reader");
int length = reader.ReadInt32();
byte[] buffer = new byte[length];
- ErrorUtilities.VerifyProtocol(reader.Read(buffer, 0, length) == length, "Unexpected buffer length.");
+ ErrorUtilities.VerifyProtocol(reader.Read(buffer, 0, length) == length, MessagingStrings.UnexpectedBufferLength);
return buffer;
}
@@ -1654,6 +1661,7 @@ public static class MessagingUtilities {
/// </summary>
/// <param name="key">The symmetric key to use for encryption/decryption.</param>
/// <returns>A symmetric algorithm.</returns>
+ [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "No apparent problem. False positive?")]
private static SymmetricAlgorithm CreateSymmetricAlgorithm(byte[] key) {
SymmetricAlgorithm result = null;
try {
@@ -28,6 +28,7 @@ namespace DotNetOpenAuth {
/// The statistical reporting mechanism used so this library's project authors
/// know what versions and features are in use.
/// </summary>
+ [SuppressMessage("Microsoft.Design", "CA1053:StaticHolderTypesShouldNotHaveConstructors", Justification = "This class is derived from, so it can't be static.")]
public class Reporting {
/// <summary>
/// A UTF8 encoder that doesn't emit the preamble. Used for mid-stream writers.
@@ -118,6 +119,12 @@ public class Reporting {
Enabled = DotNetOpenAuthSection.Reporting.Enabled;
}
+ /// <summary>
+ /// Initializes a new instance of the <see cref="Reporting"/> class.
+ /// </summary>
+ protected Reporting() {
+ }
+
/// <summary>
/// Gets or sets a value indicating whether this reporting is enabled.
/// </summary>
@@ -367,6 +374,7 @@ public class Reporting {
/// Assembles a report for submission.
/// </summary>
/// <returns>A stream that contains the report.</returns>
+ [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "If we dispose of the StreamWriter, it disposes of the underlying stream.")]
private static Stream GetReport() {
var stream = new MemoryStream();
try {
@@ -553,6 +561,7 @@ public class Reporting {
/// The identifier is made persistent by storing the identifier in isolated storage.
/// If an existing identifier is not found, a new one is created, persisted, and returned.
/// </remarks>
+ [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "No apparent problem. False positive?")]
private static Guid GetOrCreateOriginIdentity() {
Requires.ValidState(file != null);
Contract.Ensures(Contract.Result<Guid>() != Guid.Empty);
Oops, something went wrong.

0 comments on commit cd00f47

Please sign in to comment.