-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
Minimal.cs
79 lines (67 loc) · 3.2 KB
/
Minimal.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Xunit;
namespace System.Security.Cryptography.Tests.Symmetric
{
public class MinimalTests
{
[Fact]
public static void TestMinimalProperties()
{
using (Minimal s = new Minimal())
{
Assert.Equal(0, s.KeySize);
Assert.Equal(0, s.BlockSize);
object ignored;
Assert.Throws<GenerateKeyNotImplementedException>(() => ignored = s.Key);
Assert.Throws<GenerateIvNotImplementedException>(() => ignored = s.IV);
Assert.Equal(CipherMode.CBC, s.Mode);
Assert.Equal(PaddingMode.PKCS7, s.Padding);
// .NET Framework compat: LegalBlockSizes and LegalKeySizes have to be overridden for these
// properties (and the class as a whole) to be of any use.
Assert.Throws<NullReferenceException>(() => ignored = s.LegalBlockSizes);
Assert.Throws<NullReferenceException>(() => ignored = s.LegalKeySizes);
Assert.Throws<NullReferenceException>(() => ignored = s.KeySize = 5);
Assert.Throws<NullReferenceException>(() => s.Key = new byte[5]);
s.Mode = CipherMode.CBC;
Assert.Equal(CipherMode.CBC, s.Mode);
s.Mode = CipherMode.ECB;
Assert.Equal(CipherMode.ECB, s.Mode);
Assert.Throws<CryptographicException>(() => s.Mode = CipherMode.CTS);
Assert.Throws<CryptographicException>(() => s.Mode = (CipherMode)12345);
Assert.Equal(CipherMode.ECB, s.Mode);
s.Padding = PaddingMode.None;
Assert.Equal(PaddingMode.None, s.Padding);
s.Padding = PaddingMode.Zeros;
Assert.Equal(PaddingMode.Zeros, s.Padding);
s.Padding = PaddingMode.PKCS7;
Assert.Equal(PaddingMode.PKCS7, s.Padding);
Assert.Throws<CryptographicException>(() => s.Padding = (PaddingMode)12345);
Assert.Equal(PaddingMode.PKCS7, s.Padding);
}
}
private class Minimal : SymmetricAlgorithm
{
public override ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[] rgbIV)
{
throw new CreateDecryptorNotImplementedException();
}
public override ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[] rgbIV)
{
throw new CreateEncryptorNotImplementedException();
}
public override void GenerateIV()
{
throw new GenerateIvNotImplementedException();
}
public override void GenerateKey()
{
throw new GenerateKeyNotImplementedException();
}
}
private class GenerateIvNotImplementedException : Exception { }
private class GenerateKeyNotImplementedException : Exception { }
private class CreateDecryptorNotImplementedException : Exception { }
private class CreateEncryptorNotImplementedException : Exception { }
}
}