Skip to content

Commit

Permalink
The ciphers support only .NET v4.6
Browse files Browse the repository at this point in the history
  • Loading branch information
vmelamed committed Dec 10, 2015
1 parent e66b2f9 commit 6a0959b
Show file tree
Hide file tree
Showing 63 changed files with 218 additions and 714 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
[assembly: AssemblyTitle("vm.Aspects.Linq.Expressions.Serialization")]
[assembly: AssemblyDescription("Serializes and deserializes LINQ expression trees to and from XML documents.")]

[assembly: AssemblyVersion("1.0.5")]
[assembly: AssemblyFileVersion("1.0.5")]
[assembly: AssemblyInformationalVersion("1.0.5")]
[assembly: AssemblyVersion("1.0.6")]
[assembly: AssemblyFileVersion("1.0.6")]
[assembly: AssemblyInformationalVersion("1.0.6")]

[assembly: InternalsVisibleTo(
"vm.Aspects.Linq.Expressions.Serialization.Test, " +
Expand Down
6 changes: 3 additions & 3 deletions Aspects/Model/EncryptedParts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ void Verify()
.All(mi =>
{
var pi = mi as PropertyInfo;
var pType = pi != null ? pi.PropertyType : ((FieldInfo)mi).FieldType;

return ICipherExtensions.DecryptTypedData.ContainsKey(pi != null
? pi.PropertyType
: ((FieldInfo)mi).FieldType);
return pType.IsSerializable &&
ICipherExtensions.DecryptTypedData.ContainsKey(pType);
}))
throw new InvalidOperationException("The properties marked with DecryptedAttribute must be encryptable: must be of any of the following types: "+
"bool, char, byte, sbyte, short, ushort, int, uint, long, ulong, decimal, float, double, DateTime, Guid, "+
Expand Down
6 changes: 3 additions & 3 deletions Aspects/Model/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
[assembly: AssemblyTitle("vm.Aspect.Model")]
[assembly: AssemblyDescription("Defines the IRepository and related base classes and utilities - a framework of building domain object model.")]

[assembly: AssemblyVersion("1.0.5")]
[assembly: AssemblyFileVersion("1.0.5")]
[assembly: AssemblyInformationalVersion("1.0.5")]
[assembly: AssemblyVersion("1.0.6")]
[assembly: AssemblyFileVersion("1.0.6")]
[assembly: AssemblyInformationalVersion("1.0.6")]

[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(
"vm.Aspects.Model.Tests, " +
Expand Down
2 changes: 1 addition & 1 deletion Aspects/NuGet/vm.Aspects.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>vm.Aspects</id>
<version>1.0.5-beta</version>
<version>1.0.6-beta</version>
<authors>Val Melamed</authors>
<owners>Val Melamed</owners>
<summary>
Expand Down
6 changes: 3 additions & 3 deletions Aspects/Parsers/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
[assembly: AssemblyTitle("vm.Aspects.Parser")]
[assembly: AssemblyDescription("Text parsing readers, e.g. CSV/TSV reader.")]

[assembly: AssemblyVersion("1.0.5")]
[assembly: AssemblyFileVersion("1.0.5")]
[assembly: AssemblyInformationalVersion("1.0.5")]
[assembly: AssemblyVersion("1.0.6")]
[assembly: AssemblyFileVersion("1.0.6")]
[assembly: AssemblyInformationalVersion("1.0.6")]

[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(
"vm.Aspects.Parsers.Tests, " +
Expand Down
6 changes: 3 additions & 3 deletions Aspects/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

[assembly: AssemblyTitle("vm.Aspects")]
[assembly: AssemblyDescription("A set of classes addressing various common cross-cutting concerns.")]
[assembly: AssemblyVersion("1.0.5")]
[assembly: AssemblyFileVersion("1.0.5")]
[assembly: AssemblyInformationalVersion("1.0.5")]
[assembly: AssemblyVersion("1.0.6")]
[assembly: AssemblyFileVersion("1.0.6")]
[assembly: AssemblyInformationalVersion("1.0.6")]


[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(
Expand Down
40 changes: 18 additions & 22 deletions Aspects/Security/Cryptography/Ciphers/DpapiCipher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Security.Cryptography;
#if NET45
using System.Threading.Tasks;
#endif

namespace vm.Aspects.Security.Cryptography.Ciphers
{
Expand All @@ -18,7 +16,7 @@ namespace vm.Aspects.Security.Cryptography.Ciphers
/// <item><description>The bytes of the encrypted text.</description></item>
/// </list>
/// </remarks>
[SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly", Justification="Nothing to dispose")]
[SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly", Justification = "Nothing to dispose")]
public sealed class DpapiCipher : ICipherAsync
{
const int BlockLength = 4096;
Expand Down Expand Up @@ -49,7 +47,7 @@ public DpapiCipher(
/// <summary>
/// Gets or sets the entropy which makes the encryption stronger.
/// </summary>
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification="It is an opaque value.")]
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "It is an opaque value.")]
public byte[] Entropy { get; set; }

/// <summary>
Expand Down Expand Up @@ -88,9 +86,9 @@ public DpapiCipher(
/// <exception cref="T:System.IO.IOException">
/// An I/O error occurred.
/// </exception>
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification="The CryptoStream will do it.")]
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId="1")]
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId="0")]
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "The CryptoStream will do it.")]
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "1")]
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0")]
public void Encrypt(
Stream dataStream,
Stream encryptedStream)
Expand Down Expand Up @@ -156,9 +154,9 @@ public void Encrypt(
/// <exception cref="T:System.IO.IOException">
/// An I/O error occurred.
/// </exception>
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification="The CryptoStream will do it.")]
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId="1")]
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId="0")]
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "The CryptoStream will do it.")]
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "1")]
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0")]
public void Decrypt(
Stream encryptedStream,
Stream dataStream)
Expand Down Expand Up @@ -193,7 +191,7 @@ public void Decrypt(
buffer = new byte[bufferLen];
else
if (buffer.Length != bufferLen)
Array.Resize(ref buffer, bufferLen);
Array.Resize(ref buffer, bufferLen);

read = inputStream.Read(buffer, 0, bufferLen);

Expand Down Expand Up @@ -261,7 +259,6 @@ public byte[] Decrypt(
}
#endregion

#if NET45
#region ICipherAsync Members
/// <summary>
/// Asynchronously reads the clear text from the <paramref name="dataStream"/>, encrypts it and writes the result into the
Expand Down Expand Up @@ -290,8 +287,8 @@ public byte[] Decrypt(
/// <exception cref="T:System.IO.IOException">
/// An I/O error occurred.
/// </exception>
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId="1")]
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId="0")]
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "1")]
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0")]
public async Task EncryptAsync(
Stream dataStream,
Stream encryptedStream)
Expand All @@ -308,7 +305,7 @@ public async Task EncryptAsync(
first = false;
else
if (read == 0)
return;
return;

if (read < buffer.Length)
Array.Resize(ref buffer, read);
Expand Down Expand Up @@ -348,8 +345,8 @@ public async Task EncryptAsync(
/// <exception cref="T:System.IO.IOException">
/// An I/O error occurred.
/// </exception>
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId="1")]
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId="0")]
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "1")]
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0")]
public async Task DecryptAsync(
Stream encryptedStream,
Stream dataStream)
Expand All @@ -369,7 +366,7 @@ public async Task DecryptAsync(
first = false;
else
if (read == 0)
return;
return;

if (read != bufferLenBytes.Length)
throw new ArgumentException("The input stream does not seem to be produced with compatible cipher.", "encryptedStream");
Expand All @@ -380,7 +377,7 @@ public async Task DecryptAsync(
buffer = new byte[bufferLen];
else
if (buffer.Length != bufferLen)
Array.Resize(ref buffer, bufferLen);
Array.Resize(ref buffer, bufferLen);

read = await encryptedStream.ReadAsync(buffer, 0, bufferLen);

Expand All @@ -393,14 +390,13 @@ public async Task DecryptAsync(
while (decrypted.Length == BlockLength);
}
#endregion
#endif

#region IDisposable Members
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources, here it does nothing.
/// </summary>
[SuppressMessage("Microsoft.Usage", "CA1816:CallGCSuppressFinalizeCorrectly", Justification="Nothing to dispose")]
[SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly", Justification="Nothing to dispose")]
[SuppressMessage("Microsoft.Usage", "CA1816:CallGCSuppressFinalizeCorrectly", Justification = "Nothing to dispose")]
[SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly", Justification = "Nothing to dispose")]
public void Dispose()
{
GC.SuppressFinalize(this);
Expand Down
18 changes: 6 additions & 12 deletions Aspects/Security/Cryptography/Ciphers/EncryptedNewKeyCipher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Security.Cryptography.X509Certificates;
#if NET45
using System.Threading.Tasks;
#endif

namespace vm.Aspects.Security.Cryptography.Ciphers
{
Expand Down Expand Up @@ -91,7 +89,7 @@ public override string KeyLocation
/// </summary>
/// <param name="key">The key.</param>
/// <exception cref="NotImplementedException">Always thrown.</exception>
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId="0")]
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0")]
public override void ImportSymmetricKey(
byte[] key)
{
Expand All @@ -107,13 +105,12 @@ public override byte[] ExportSymmetricKey()
throw new NotImplementedException();
}

#if NET45
/// <summary>
/// Asynchronously imports the symmetric key as a clear text.
/// </summary>
/// <param name="key">The key.</param>
/// <exception cref="NotImplementedException">Always thrown.</exception>
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId="0")]
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0")]
public override Task ImportSymmetricKeyAsync(
byte[] key)
{
Expand All @@ -128,7 +125,6 @@ public override Task<byte[]> ExportSymmetricKeyAsync()
{
throw new NotImplementedException();
}
#endif
#endregion

#region Initialization of the symmetric key overrides
Expand All @@ -154,7 +150,7 @@ protected override void InitializeSymmetricKey()
/// <exception cref="System.ArgumentNullException">Thrown when <paramref name="encryptedStream" /> is <see langword="null" />.</exception>
/// <exception cref="System.ArgumentException">Thrown when <paramref name="encryptedStream" /> cannot be written to.</exception>
/// <remarks>The method is called by the GoF template-methods.</remarks>
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId="0")]
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0")]
protected override void BeforeWriteEncrypted(
Stream encryptedStream)
{
Expand All @@ -181,7 +177,7 @@ protected override void BeforeWriteEncrypted(
/// </list>
/// </exception>
/// <remarks>The method is called by the GoF template-methods.</remarks>
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId="0")]
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0")]
protected override void BeforeReadDecrypted(Stream encryptedStream)
{
// read the length of the key and allocate an array for it
Expand All @@ -204,7 +200,6 @@ protected override void BeforeReadDecrypted(Stream encryptedStream)
}
#endregion

#if NET45
/// <summary>
/// Initializes asynchronously the symmetric key by either reading it from the storage with the specified key location name or by
/// generating a new key and saving it in it.
Expand All @@ -229,7 +224,7 @@ protected override Task InitializeSymmetricKeyAsync()
/// <exception cref="System.ArgumentNullException">Thrown when <paramref name="encryptedStream" /> is <see langword="null" />.</exception>
/// <exception cref="System.ArgumentException">Thrown when <paramref name="encryptedStream" /> cannot be written to.</exception>
/// <remarks>The method is called by the GoF template-methods.</remarks>
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId="0")]
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0")]
protected override async Task BeforeWriteEncryptedAsync(
Stream encryptedStream)
{
Expand All @@ -256,7 +251,7 @@ protected override async Task BeforeWriteEncryptedAsync(
/// </list>
/// </exception>
/// <remarks>The method is called by the GoF template-methods.</remarks>
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId="0")]
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0")]
protected override async Task BeforeReadDecryptedAsync(
Stream encryptedStream)
{
Expand All @@ -279,6 +274,5 @@ protected override async Task BeforeReadDecryptedAsync(
await base.BeforeReadDecryptedAsync(encryptedStream);
}
#endregion
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
using System.Linq;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
#if NET45
using System.Threading.Tasks;
#endif

namespace vm.Aspects.Security.Cryptography.Ciphers
{
Expand Down Expand Up @@ -491,7 +489,6 @@ protected byte[] FinalizeHashAfterRead(
}
#endregion

#if NET45
/// <summary>
/// Asynchronously reads the clear text from the <paramref name="dataStream" />, encrypts it and writes the result into the
/// <paramref name="encryptedStream" /> stream. This is the reverse method of <see cref="M:DecryptAsync(System.Stream, System.Stream)" />.
Expand Down Expand Up @@ -610,7 +607,6 @@ protected virtual async Task LoadHashToValidateAsync(
: storedHash;
}
#endregion
#endif

#region IDisposable Members

Expand Down
Loading

0 comments on commit 6a0959b

Please sign in to comment.