summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Core/Messaging/Bindings
diff options
context:
space:
mode:
Diffstat (limited to 'src/DotNetOpenAuth.Core/Messaging/Bindings')
-rw-r--r--src/DotNetOpenAuth.Core/Messaging/Bindings/AsymmetricCryptoKeyStoreWrapper.cs20
-rw-r--r--src/DotNetOpenAuth.Core/Messaging/Bindings/CryptoKey.cs6
-rw-r--r--src/DotNetOpenAuth.Core/Messaging/Bindings/ExpiredMessageException.cs4
-rw-r--r--src/DotNetOpenAuth.Core/Messaging/Bindings/ICryptoKeyStore.cs61
-rw-r--r--src/DotNetOpenAuth.Core/Messaging/Bindings/StandardReplayProtectionBindingElement.cs2
5 files changed, 11 insertions, 82 deletions
diff --git a/src/DotNetOpenAuth.Core/Messaging/Bindings/AsymmetricCryptoKeyStoreWrapper.cs b/src/DotNetOpenAuth.Core/Messaging/Bindings/AsymmetricCryptoKeyStoreWrapper.cs
index 4cb5337..0439908 100644
--- a/src/DotNetOpenAuth.Core/Messaging/Bindings/AsymmetricCryptoKeyStoreWrapper.cs
+++ b/src/DotNetOpenAuth.Core/Messaging/Bindings/AsymmetricCryptoKeyStoreWrapper.cs
@@ -8,11 +8,11 @@ namespace DotNetOpenAuth.Messaging.Bindings {
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
- using System.Diagnostics.Contracts;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using DotNetOpenAuth.Messaging;
+ using Validation;
/// <summary>
/// Provides RSA encryption of symmetric keys to protect them from a theft of
@@ -42,7 +42,7 @@ namespace DotNetOpenAuth.Messaging.Bindings {
public AsymmetricCryptoKeyStoreWrapper(ICryptoKeyStore dataStore, RSACryptoServiceProvider asymmetricCrypto) {
Requires.NotNull(dataStore, "dataStore");
Requires.NotNull(asymmetricCrypto, "asymmetricCrypto");
- Requires.True(!asymmetricCrypto.PublicOnly, "asymmetricCrypto");
+ Requires.That(!asymmetricCrypto.PublicOnly, "asymmetricCrypto", "Private key required.");
this.dataStore = dataStore;
this.asymmetricCrypto = asymmetricCrypto;
}
@@ -138,9 +138,9 @@ namespace DotNetOpenAuth.Messaging.Bindings {
/// <param name="decrypted">The decrypted key.</param>
internal CachedCryptoKey(CryptoKey encrypted, CryptoKey decrypted)
: base(decrypted.Key, decrypted.ExpiresUtc) {
- Contract.Requires(encrypted != null);
- Contract.Requires(decrypted != null);
- Contract.Requires(encrypted.ExpiresUtc == decrypted.ExpiresUtc);
+ Requires.NotNull(encrypted, "encrypted");
+ Requires.NotNull(decrypted, "decrypted");
+ Requires.That(encrypted.ExpiresUtc == decrypted.ExpiresUtc, "encrypted", "encrypted and decrypted expirations must equal.");
this.EncryptedKey = encrypted.Key;
}
@@ -149,16 +149,6 @@ namespace DotNetOpenAuth.Messaging.Bindings {
/// Gets the encrypted key.
/// </summary>
internal byte[] EncryptedKey { get; private set; }
-
- /// <summary>
- /// 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);
- }
}
}
}
diff --git a/src/DotNetOpenAuth.Core/Messaging/Bindings/CryptoKey.cs b/src/DotNetOpenAuth.Core/Messaging/Bindings/CryptoKey.cs
index 3fa50d4..d6fef62 100644
--- a/src/DotNetOpenAuth.Core/Messaging/Bindings/CryptoKey.cs
+++ b/src/DotNetOpenAuth.Core/Messaging/Bindings/CryptoKey.cs
@@ -8,10 +8,10 @@ namespace DotNetOpenAuth.Messaging.Bindings {
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
- using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;
using DotNetOpenAuth.Messaging;
+ using Validation;
/// <summary>
/// A cryptographic key and metadata concerning it.
@@ -34,7 +34,7 @@ namespace DotNetOpenAuth.Messaging.Bindings {
/// <param name="expiresUtc">The expires UTC.</param>
public CryptoKey(byte[] key, DateTime expiresUtc) {
Requires.NotNull(key, "key");
- Requires.True(expiresUtc.Kind == DateTimeKind.Utc, "expiresUtc");
+ Requires.That(expiresUtc.Kind == DateTimeKind.Utc, "expiresUtc", "Time must be expressed in UTC.");
this.key = key;
this.expiresUtc = expiresUtc;
}
@@ -45,7 +45,6 @@ namespace DotNetOpenAuth.Messaging.Bindings {
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "It's a buffer")]
public byte[] Key {
get {
- Contract.Ensures(Contract.Result<byte[]>() != null);
return this.key;
}
}
@@ -55,7 +54,6 @@ namespace DotNetOpenAuth.Messaging.Bindings {
/// </summary>
public DateTime ExpiresUtc {
get {
- Contract.Ensures(Contract.Result<DateTime>().Kind == DateTimeKind.Utc);
return this.expiresUtc;
}
}
diff --git a/src/DotNetOpenAuth.Core/Messaging/Bindings/ExpiredMessageException.cs b/src/DotNetOpenAuth.Core/Messaging/Bindings/ExpiredMessageException.cs
index 88b8fed..8c5db3c 100644
--- a/src/DotNetOpenAuth.Core/Messaging/Bindings/ExpiredMessageException.cs
+++ b/src/DotNetOpenAuth.Core/Messaging/Bindings/ExpiredMessageException.cs
@@ -6,8 +6,8 @@
namespace DotNetOpenAuth.Messaging.Bindings {
using System;
- using System.Diagnostics.Contracts;
using System.Globalization;
+ using Validation;
/// <summary>
/// An exception thrown when a message is received that exceeds the maximum message age limit.
@@ -21,7 +21,7 @@ namespace DotNetOpenAuth.Messaging.Bindings {
/// <param name="faultedMessage">The expired message.</param>
public ExpiredMessageException(DateTime utcExpirationDate, IProtocolMessage faultedMessage)
: base(string.Format(CultureInfo.CurrentCulture, MessagingStrings.ExpiredMessage, utcExpirationDate.ToLocalTime(), DateTime.Now), faultedMessage) {
- Requires.True(utcExpirationDate.Kind == DateTimeKind.Utc, "utcExpirationDate");
+ Requires.Argument(utcExpirationDate.Kind == DateTimeKind.Utc, "utcExpirationDate", "Time must be expressed as UTC.");
}
/// <summary>
diff --git a/src/DotNetOpenAuth.Core/Messaging/Bindings/ICryptoKeyStore.cs b/src/DotNetOpenAuth.Core/Messaging/Bindings/ICryptoKeyStore.cs
index 2e43bba..ce7bf42 100644
--- a/src/DotNetOpenAuth.Core/Messaging/Bindings/ICryptoKeyStore.cs
+++ b/src/DotNetOpenAuth.Core/Messaging/Bindings/ICryptoKeyStore.cs
@@ -8,10 +8,10 @@ namespace DotNetOpenAuth.Messaging.Bindings {
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
- using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;
using DotNetOpenAuth.Messaging;
+ using Validation;
/// <summary>
/// A persistent store for rotating symmetric cryptographic keys.
@@ -23,7 +23,6 @@ namespace DotNetOpenAuth.Messaging.Bindings {
/// of the confidentiality of the keys. One possible mitigation is to asymmetrically encrypt
/// each key using a certificate installed in the server's certificate store.
/// </remarks>
- [ContractClass(typeof(ICryptoKeyStoreContract))]
public interface ICryptoKeyStore {
/// <summary>
/// Gets the key in a given bucket and handle.
@@ -57,62 +56,4 @@ namespace DotNetOpenAuth.Messaging.Bindings {
/// <param name="handle">The key handle. Case sensitive.</param>
void RemoveKey(string bucket, string handle);
}
-
- /// <summary>
- /// Code contract for the <see cref="ICryptoKeyStore"/> interface.
- /// </summary>
- [ContractClassFor(typeof(ICryptoKeyStore))]
- internal abstract class ICryptoKeyStoreContract : ICryptoKeyStore {
- /// <summary>
- /// Gets the key in a given bucket and handle.
- /// </summary>
- /// <param name="bucket">The bucket name. Case sensitive.</param>
- /// <param name="handle">The key handle. Case sensitive.</param>
- /// <returns>
- /// The cryptographic key, or <c>null</c> if no matching key was found.
- /// </returns>
- CryptoKey ICryptoKeyStore.GetKey(string bucket, string handle) {
- Requires.NotNullOrEmpty(bucket, "bucket");
- Requires.NotNullOrEmpty(handle, "handle");
- throw new NotImplementedException();
- }
-
- /// <summary>
- /// Gets a sequence of existing keys within a given bucket.
- /// </summary>
- /// <param name="bucket">The bucket name. Case sensitive.</param>
- /// <returns>
- /// A sequence of handles and keys, ordered by descending <see cref="CryptoKey.ExpiresUtc"/>.
- /// </returns>
- IEnumerable<KeyValuePair<string, CryptoKey>> ICryptoKeyStore.GetKeys(string bucket) {
- Requires.NotNullOrEmpty(bucket, "bucket");
- Contract.Ensures(Contract.Result<IEnumerable<KeyValuePair<string, CryptoKey>>>() != null);
- throw new NotImplementedException();
- }
-
- /// <summary>
- /// Stores a cryptographic key.
- /// </summary>
- /// <param name="bucket">The name of the bucket to store the key in. Case sensitive.</param>
- /// <param name="handle">The handle to the key, unique within the bucket. Case sensitive.</param>
- /// <param name="key">The key to store.</param>
- /// <exception cref="CryptoKeyCollisionException">Thrown in the event of a conflict with an existing key in the same bucket and with the same handle.</exception>
- void ICryptoKeyStore.StoreKey(string bucket, string handle, CryptoKey key) {
- Requires.NotNullOrEmpty(bucket, "bucket");
- Requires.NotNullOrEmpty(handle, "handle");
- Requires.NotNull(key, "key");
- throw new NotImplementedException();
- }
-
- /// <summary>
- /// Removes the key.
- /// </summary>
- /// <param name="bucket">The bucket name. Case sensitive.</param>
- /// <param name="handle">The key handle. Case sensitive.</param>
- void ICryptoKeyStore.RemoveKey(string bucket, string handle) {
- Requires.NotNullOrEmpty(bucket, "bucket");
- Requires.NotNullOrEmpty(handle, "handle");
- throw new NotImplementedException();
- }
- }
}
diff --git a/src/DotNetOpenAuth.Core/Messaging/Bindings/StandardReplayProtectionBindingElement.cs b/src/DotNetOpenAuth.Core/Messaging/Bindings/StandardReplayProtectionBindingElement.cs
index 7e39536..45bccdf 100644
--- a/src/DotNetOpenAuth.Core/Messaging/Bindings/StandardReplayProtectionBindingElement.cs
+++ b/src/DotNetOpenAuth.Core/Messaging/Bindings/StandardReplayProtectionBindingElement.cs
@@ -7,7 +7,7 @@
namespace DotNetOpenAuth.Messaging.Bindings {
using System;
using System.Diagnostics;
- using System.Diagnostics.Contracts;
+ using Validation;
/// <summary>
/// A binding element that checks/verifies a nonce message part.