Skip to content

Commit 224ed2a

Browse files
committed
Add .editorconfig; change tabs back to spaces; add braces for single-line statements.
1 parent e4ff6ae commit 224ed2a

25 files changed

+1890
-1690
lines changed

.editorconfig

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
[*.cs]
2+
indent_style = space
3+
indent_size = 4
4+
5+
csharp_new_line_before_else = true
6+
csharp_new_line_before_finally = true
7+
csharp_new_line_before_members_in_object_initializers = true
8+
csharp_new_line_before_open_brace = methods, object_collection_array_initializers, control_blocks, types
9+
dotnet_sort_system_directives_first = true
10+
11+
csharp_space_after_cast = false
12+
csharp_space_after_colon_in_inheritance_clause = true
13+
csharp_space_after_keywords_in_control_flow_statements = true
14+
csharp_space_before_colon_in_inheritance_clause = true
15+
csharp_space_between_method_call_empty_parameter_list_parentheses = false
16+
csharp_space_between_method_call_name_and_opening_parenthesis = false
17+
csharp_space_between_method_call_parameter_list_parentheses = false
18+
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
19+
csharp_space_between_method_declaration_parameter_list_parentheses = false
20+
21+
csharp_preserve_single_line_blocks = true
22+
csharp_preserve_single_line_statements = false
23+
csharp_prefer_braces = true:warning
24+
25+
csharp_style_var_when_type_is_apparent = true:suggestion
26+
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
27+
28+
dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion
29+
csharp_preferred_modifier_order = public,private,internal,protected,static,readonly,sealed,async,override,abstract:suggestion
30+
31+
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
32+
dotnet_style_predefined_type_for_member_access = true:suggestion
33+
dotnet_style_object_initializer = true:suggestion
34+
dotnet_style_prefer_inferred_tuple_names = true:suggestion
35+
csharp_prefer_simple_default_expression = true:suggestion
36+
37+
dotnet_style_qualification_for_field = false:suggestion
38+
dotnet_style_qualification_for_method = false:suggestion
39+
dotnet_style_qualification_for_property = false:suggestion

EntityFrameworkCore.DataEncryption.sln

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "pipelines", "pipelines", "{
2828
ProjectSection(SolutionItems) = preProject
2929
.azure\pipelines\azure-pipelines.yml = .azure\pipelines\azure-pipelines.yml
3030
EndProjectSection
31+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5EE4E8BE-6B15-49DB-A4A8-D2CD63D5E90C}"
32+
ProjectSection(SolutionItems) = preProject
33+
.editorconfig = .editorconfig
34+
EndProjectSection
3135
EndProject
3236
Global
3337
GlobalSection(SolutionConfigurationPlatforms) = preSolution

samples/AesSample/Program.cs

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,51 +6,51 @@
66

77
namespace AesSample
88
{
9-
static class Program
10-
{
11-
static void Main()
12-
{
13-
var options = new DbContextOptionsBuilder<DatabaseContext>()
14-
.UseInMemoryDatabase(databaseName: "MyInMemoryDatabase")
15-
.Options;
16-
17-
// AES key randomly generated at each run.
18-
byte[] encryptionKey = AesProvider.GenerateKey(AesKeySize.AES256Bits).Key;
19-
var encryptionProvider = new AesProvider(encryptionKey);
20-
21-
using var context = new DatabaseContext(options, encryptionProvider);
22-
23-
var user = new UserEntity
24-
{
25-
FirstName = "John",
26-
LastName = "Doe",
27-
Email = "john@doe.com",
28-
Password = BuildPassword(),
29-
};
30-
31-
context.Users.Add(user);
32-
context.SaveChanges();
33-
34-
Console.WriteLine($"Users count: {context.Users.Count()}");
35-
36-
user = context.Users.First();
37-
38-
Console.WriteLine($"User: {user.FirstName} {user.LastName} - {user.Email} ({user.Password.Length})");
39-
}
40-
41-
static SecureString BuildPassword()
42-
{
43-
SecureString result = new();
44-
result.AppendChar('L');
45-
result.AppendChar('e');
46-
result.AppendChar('t');
47-
result.AppendChar('M');
48-
result.AppendChar('e');
49-
result.AppendChar('I');
50-
result.AppendChar('n');
51-
result.AppendChar('!');
52-
result.MakeReadOnly();
53-
return result;
54-
}
55-
}
9+
static class Program
10+
{
11+
static void Main()
12+
{
13+
var options = new DbContextOptionsBuilder<DatabaseContext>()
14+
.UseInMemoryDatabase(databaseName: "MyInMemoryDatabase")
15+
.Options;
16+
17+
// AES key randomly generated at each run.
18+
byte[] encryptionKey = AesProvider.GenerateKey(AesKeySize.AES256Bits).Key;
19+
var encryptionProvider = new AesProvider(encryptionKey);
20+
21+
using var context = new DatabaseContext(options, encryptionProvider);
22+
23+
var user = new UserEntity
24+
{
25+
FirstName = "John",
26+
LastName = "Doe",
27+
Email = "john@doe.com",
28+
Password = BuildPassword(),
29+
};
30+
31+
context.Users.Add(user);
32+
context.SaveChanges();
33+
34+
Console.WriteLine($"Users count: {context.Users.Count()}");
35+
36+
user = context.Users.First();
37+
38+
Console.WriteLine($"User: {user.FirstName} {user.LastName} - {user.Email} ({user.Password.Length})");
39+
}
40+
41+
static SecureString BuildPassword()
42+
{
43+
SecureString result = new();
44+
result.AppendChar('L');
45+
result.AppendChar('e');
46+
result.AppendChar('t');
47+
result.AppendChar('M');
48+
result.AppendChar('e');
49+
result.AppendChar('I');
50+
result.AppendChar('n');
51+
result.AppendChar('!');
52+
result.MakeReadOnly();
53+
return result;
54+
}
55+
}
5656
}
Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
namespace System.ComponentModel.DataAnnotations
22
{
3-
/// <summary>
4-
/// Specifies that the data field value should be encrypted.
5-
/// </summary>
6-
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
7-
public sealed class EncryptedAttribute : Attribute
8-
{
9-
/// <summary>
10-
/// Initializes a new instance of the <see cref="EncryptedAttribute"/> class.
11-
/// </summary>
12-
/// <param name="format">
13-
/// The storage format.
14-
/// </param>
15-
public EncryptedAttribute(StorageFormat format)
16-
{
17-
Format = format;
18-
}
3+
/// <summary>
4+
/// Specifies that the data field value should be encrypted.
5+
/// </summary>
6+
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
7+
public sealed class EncryptedAttribute : Attribute
8+
{
9+
/// <summary>
10+
/// Initializes a new instance of the <see cref="EncryptedAttribute"/> class.
11+
/// </summary>
12+
/// <param name="format">
13+
/// The storage format.
14+
/// </param>
15+
public EncryptedAttribute(StorageFormat format)
16+
{
17+
Format = format;
18+
}
1919

20-
/// <summary>
21-
/// Initializes a new instance of the <see cref="EncryptedAttribute"/> class.
22-
/// </summary>
23-
public EncryptedAttribute() : this(StorageFormat.Default)
24-
{
25-
}
20+
/// <summary>
21+
/// Initializes a new instance of the <see cref="EncryptedAttribute"/> class.
22+
/// </summary>
23+
public EncryptedAttribute() : this(StorageFormat.Default)
24+
{
25+
}
2626

27-
/// <summary>
28-
/// Returns the storage format for the database value.
29-
/// </summary>
30-
public StorageFormat Format { get; }
31-
}
27+
/// <summary>
28+
/// Returns the storage format for the database value.
29+
/// </summary>
30+
public StorageFormat Format { get; }
31+
}
3232
}
Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
namespace System.ComponentModel.DataAnnotations
22
{
3-
/// <summary>
4-
/// Represents the storage format for an encrypted value.
5-
/// </summary>
6-
public enum StorageFormat
7-
{
8-
/// <summary>
9-
/// The format is determined by the model data type.
10-
/// </summary>
11-
Default,
12-
/// <summary>
13-
/// The value is stored in binary.
14-
/// </summary>
15-
Binary,
16-
/// <summary>
17-
/// The value is stored in a Base64-encoded string.
18-
/// </summary>
19-
/// <remarks>
20-
/// <b>NB:</b> If the source property is a <see cref="string"/>,
21-
/// and no encryption provider is configured,
22-
/// the string will not be modified.
23-
/// </remarks>
24-
Base64,
25-
}
3+
/// <summary>
4+
/// Represents the storage format for an encrypted value.
5+
/// </summary>
6+
public enum StorageFormat
7+
{
8+
/// <summary>
9+
/// The format is determined by the model data type.
10+
/// </summary>
11+
Default,
12+
/// <summary>
13+
/// The value is stored in binary.
14+
/// </summary>
15+
Binary,
16+
/// <summary>
17+
/// The value is stored in a Base64-encoded string.
18+
/// </summary>
19+
/// <remarks>
20+
/// <b>NB:</b> If the source property is a <see cref="string"/>,
21+
/// and no encryption provider is configured,
22+
/// the string will not be modified.
23+
/// </remarks>
24+
Base64,
25+
}
2626
}

src/EntityFrameworkCore.DataEncryption/IEncryptionProvider.cs

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -3,65 +3,65 @@
33

44
namespace Microsoft.EntityFrameworkCore.DataEncryption
55
{
6-
/// <summary>
7-
/// Provides a mechanism for implementing a custom encryption provider.
8-
/// </summary>
9-
public interface IEncryptionProvider
10-
{
11-
/// <summary>
12-
/// Encrypts a value.
13-
/// </summary>
14-
/// <typeparam name="TStore">
15-
/// The type of data stored in the database.
16-
/// </typeparam>
17-
/// <typeparam name="TModel">
18-
/// The type of value stored in the model.
19-
/// </typeparam>
20-
/// <param name="dataToEncrypt">
21-
/// Input data to encrypt.
22-
/// </param>
23-
/// <param name="converter">
24-
/// Function which converts the model value to a byte array.
25-
/// </param>
26-
/// <param name="encoder">
27-
/// Function which encodes the value for storing the the database.
28-
/// </param>
29-
/// <returns>
30-
/// Encrypted data.
31-
/// </returns>
32-
/// <exception cref="ArgumentNullException">
33-
/// <para><paramref name="converter"/> is <see langword="null"/>.</para>
34-
/// <para>-or-</para>
35-
/// <para><paramref name="encoder"/> is <see langword="null"/>.</para>
36-
/// </exception>
37-
TStore Encrypt<TStore, TModel>(TModel dataToEncrypt, Func<TModel, byte[]> converter, Func<Stream, TStore> encoder);
6+
/// <summary>
7+
/// Provides a mechanism for implementing a custom encryption provider.
8+
/// </summary>
9+
public interface IEncryptionProvider
10+
{
11+
/// <summary>
12+
/// Encrypts a value.
13+
/// </summary>
14+
/// <typeparam name="TStore">
15+
/// The type of data stored in the database.
16+
/// </typeparam>
17+
/// <typeparam name="TModel">
18+
/// The type of value stored in the model.
19+
/// </typeparam>
20+
/// <param name="dataToEncrypt">
21+
/// Input data to encrypt.
22+
/// </param>
23+
/// <param name="converter">
24+
/// Function which converts the model value to a byte array.
25+
/// </param>
26+
/// <param name="encoder">
27+
/// Function which encodes the value for storing the the database.
28+
/// </param>
29+
/// <returns>
30+
/// Encrypted data.
31+
/// </returns>
32+
/// <exception cref="ArgumentNullException">
33+
/// <para><paramref name="converter"/> is <see langword="null"/>.</para>
34+
/// <para>-or-</para>
35+
/// <para><paramref name="encoder"/> is <see langword="null"/>.</para>
36+
/// </exception>
37+
TStore Encrypt<TStore, TModel>(TModel dataToEncrypt, Func<TModel, byte[]> converter, Func<Stream, TStore> encoder);
3838

39-
/// <summary>
40-
/// Decrypts a value.
41-
/// </summary>
42-
/// <typeparam name="TStore">
43-
/// The type of data stored in the database.
44-
/// </typeparam>
45-
/// <typeparam name="TModel">
46-
/// The type of value stored in the model.
47-
/// </typeparam>
48-
/// <param name="dataToDecrypt">
49-
/// Encrypted data to decrypt.
50-
/// </param>
51-
/// <param name="decoder">
52-
/// Function which converts the stored data to a byte array.
53-
/// </param>
54-
/// <param name="converter">
55-
/// Function which converts the decrypted <see cref="Stream"/> to the return value.
56-
/// </param>
57-
/// <returns>
58-
/// Decrypted data.
59-
/// </returns>
60-
/// <exception cref="ArgumentNullException">
61-
/// <para><paramref name="decoder"/> is <see langword="null"/>.</para>
62-
/// <para>-or-</para>
63-
/// <para><paramref name="converter"/> is <see langword="null"/>.</para>
64-
/// </exception>
65-
TModel Decrypt<TStore, TModel>(TStore dataToDecrypt, Func<TStore, byte[]> decoder, Func<Stream, TModel> converter);
66-
}
39+
/// <summary>
40+
/// Decrypts a value.
41+
/// </summary>
42+
/// <typeparam name="TStore">
43+
/// The type of data stored in the database.
44+
/// </typeparam>
45+
/// <typeparam name="TModel">
46+
/// The type of value stored in the model.
47+
/// </typeparam>
48+
/// <param name="dataToDecrypt">
49+
/// Encrypted data to decrypt.
50+
/// </param>
51+
/// <param name="decoder">
52+
/// Function which converts the stored data to a byte array.
53+
/// </param>
54+
/// <param name="converter">
55+
/// Function which converts the decrypted <see cref="Stream"/> to the return value.
56+
/// </param>
57+
/// <returns>
58+
/// Decrypted data.
59+
/// </returns>
60+
/// <exception cref="ArgumentNullException">
61+
/// <para><paramref name="decoder"/> is <see langword="null"/>.</para>
62+
/// <para>-or-</para>
63+
/// <para><paramref name="converter"/> is <see langword="null"/>.</para>
64+
/// </exception>
65+
TModel Decrypt<TStore, TModel>(TStore dataToDecrypt, Func<TStore, byte[]> decoder, Func<Stream, TModel> converter);
66+
}
6767
}

0 commit comments

Comments
 (0)