Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
UniversalCryptoEncryptor.cs
Go to the documentation of this file.
1using System;
3
5
6internal sealed class UniversalCryptoEncryptor : Internal.Cryptography.UniversalCryptoTransform
7{
9 : base(paddingMode, basicSymmetricCipher)
10 {
11 }
12
13 protected override int UncheckedTransformBlock(ReadOnlySpan<byte> inputBuffer, Span<byte> outputBuffer)
14 {
15 return base.BasicSymmetricCipher.Transform(inputBuffer, outputBuffer);
16 }
17
18 protected override int UncheckedTransformFinalBlock(ReadOnlySpan<byte> inputBuffer, Span<byte> outputBuffer)
19 {
20 int length = PadBlock(inputBuffer, outputBuffer);
21 return base.BasicSymmetricCipher.TransformFinal(outputBuffer.Slice(0, length), outputBuffer);
22 }
23
24 protected override byte[] UncheckedTransformFinalBlock(byte[] inputBuffer, int inputOffset, int inputCount)
25 {
26 byte[] array = GC.AllocateUninitializedArray<byte>(GetCiphertextLength(inputCount));
27 int num = UncheckedTransformFinalBlock(inputBuffer.AsSpan(inputOffset, inputCount), array);
28 return array;
29 }
30
31 private int GetCiphertextLength(int plaintextLength)
32 {
33 int result;
34 int num = Math.DivRem(plaintextLength, base.PaddingSizeBytes, out result) * base.PaddingSizeBytes;
35 switch (base.PaddingMode)
36 {
37 case PaddingMode.None:
38 if (result != 0)
39 {
41 }
42 goto IL_004c;
43 case PaddingMode.Zeros:
44 if (result == 0)
45 {
46 goto IL_004c;
47 }
48 goto case PaddingMode.PKCS7;
49 case PaddingMode.PKCS7:
50 case PaddingMode.ANSIX923:
51 case PaddingMode.ISO10126:
52 return checked(num + base.PaddingSizeBytes);
53 default:
54 {
56 }
57 IL_004c:
58 return plaintextLength;
59 }
60 }
61
63 {
64 int length = block.Length;
65 int num = length % base.PaddingSizeBytes;
66 int num2 = base.PaddingSizeBytes - num;
67 switch (base.PaddingMode)
68 {
69 case PaddingMode.None:
70 if (num != 0)
71 {
73 }
74 if (destination.Length < length)
75 {
77 }
78 block.CopyTo(destination);
79 return length;
80 case PaddingMode.ANSIX923:
81 {
82 int num4 = length + num2;
83 if (destination.Length < num4)
84 {
86 }
87 block.CopyTo(destination);
88 destination.Slice(length, num2 - 1).Clear();
89 destination[length + num2 - 1] = (byte)num2;
90 return num4;
91 }
92 case PaddingMode.ISO10126:
93 {
94 int num6 = length + num2;
95 if (destination.Length < num6)
96 {
98 }
99 block.CopyTo(destination);
101 destination[length + num2 - 1] = (byte)num2;
102 return num6;
103 }
104 case PaddingMode.PKCS7:
105 {
106 int num5 = length + num2;
107 if (destination.Length < num5)
108 {
110 }
111 block.CopyTo(destination);
112 destination.Slice(length, num2).Fill((byte)num2);
113 return num5;
114 }
115 case PaddingMode.Zeros:
116 {
117 if (num2 == base.PaddingSizeBytes)
118 {
119 num2 = 0;
120 }
121 int num3 = length + num2;
122 if (destination.Length < num3)
123 {
125 }
126 block.CopyTo(destination);
127 destination.Slice(length, num2).Clear();
128 return num3;
129 }
130 default:
132 }
133 }
134}
override byte[] UncheckedTransformFinalBlock(byte[] inputBuffer, int inputOffset, int inputCount)
override int UncheckedTransformBlock(ReadOnlySpan< byte > inputBuffer, Span< byte > outputBuffer)
int PadBlock(ReadOnlySpan< byte > block, Span< byte > destination)
override int UncheckedTransformFinalBlock(ReadOnlySpan< byte > inputBuffer, Span< byte > outputBuffer)
UniversalCryptoEncryptor(PaddingMode paddingMode, Internal.Cryptography.BasicSymmetricCipher basicSymmetricCipher)
Definition GC.cs:8
static int DivRem(int a, int b, out int result)
Definition Math.cs:329
static string Argument_DestinationTooShort
Definition SR.cs:14
static string Cryptography_UnknownPaddingMode
Definition SR.cs:154
static string Cryptography_PartialBlock
Definition SR.cs:124
Definition SR.cs:7
void CopyTo(Span< T > destination)
Span< T > Slice(int start)
Definition Span.cs:271