Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Helpers.cs
Go to the documentation of this file.
1using System;
5
7
8internal static class Helpers
9{
11 public static bool IsRC2Supported => !OperatingSystem.IsAndroid();
12
13 public static bool UsesIv(this CipherMode cipherMode)
14 {
15 return cipherMode != CipherMode.ECB;
16 }
17
18 public static byte[] GetCipherIv(this CipherMode cipherMode, byte[] iv)
19 {
20 if (cipherMode.UsesIv())
21 {
22 if (iv == null)
23 {
25 }
26 return iv;
27 }
28 return null;
29 }
30
31 public static byte[] FixupKeyParity(this byte[] key)
32 {
33 byte[] array = new byte[key.Length];
34 for (int i = 0; i < key.Length; i++)
35 {
36 array[i] = (byte)(key[i] & 0xFEu);
37 byte b = (byte)((array[i] & 0xFu) ^ (uint)(array[i] >> 4));
38 byte b2 = (byte)((b & 3u) ^ (uint)(b >> 2));
39 if ((byte)((b2 & 1) ^ (b2 >> 1)) == 0)
40 {
41 array[i] |= 1;
42 }
43 }
44 return array;
45 }
46
47 [return: NotNullIfNotNull("src")]
48 public static byte[] CloneByteArray(this byte[] src)
49 {
50 if (src == null)
51 {
52 return null;
53 }
54 return (byte[])src.Clone();
55 }
56
58 {
59 return ((mode == CipherMode.CFB) ? feedbackSizeInBits : algorithm.BlockSize) / 8;
60 }
61
63 {
64 if (source.TryCopyTo(destination))
65 {
66 bytesWritten = source.Length;
67 return true;
68 }
69 bytesWritten = 0;
70 return false;
71 }
72}
static byte[] GetCipherIv(this CipherMode cipherMode, byte[] iv)
Definition Helpers.cs:18
static bool TryCopyToDestination(this ReadOnlySpan< byte > source, Span< byte > destination, out int bytesWritten)
Definition Helpers.cs:62
static int GetPaddingSize(this SymmetricAlgorithm algorithm, CipherMode mode, int feedbackSizeInBits)
Definition Helpers.cs:57
static byte[] CloneByteArray(this byte[] src)
Definition Helpers.cs:48
static bool UsesIv(this CipherMode cipherMode)
Definition Helpers.cs:13
static byte[] FixupKeyParity(this byte[] key)
Definition Helpers.cs:31
static string Cryptography_MissingIV
Definition SR.cs:112
Definition SR.cs:7