chore(deps): update docker/build-push-action action to v6.11.0
[ArchiSteamFarm.git] / ArchiSteamFarm.Tests / ArchiCryptoHelper.cs
blob493e40502249b21e14a6addf492b9f3c2dd0976c
1 // ----------------------------------------------------------------------------------------------
2 // _ _ _ ____ _ _____
3 // / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
4 // / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
5 // / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
6 // /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
7 // ----------------------------------------------------------------------------------------------
8 // |
9 // Copyright 2015-2025 Ɓukasz "JustArchi" Domeradzki
10 // Contact: JustArchi@JustArchi.net
11 // |
12 // Licensed under the Apache License, Version 2.0 (the "License");
13 // you may not use this file except in compliance with the License.
14 // You may obtain a copy of the License at
15 // |
16 // http://www.apache.org/licenses/LICENSE-2.0
17 // |
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the License is distributed on an "AS IS" BASIS,
20 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 // See the License for the specific language governing permissions and
22 // limitations under the License.
24 using System;
25 using System.ComponentModel;
26 using System.Threading.Tasks;
27 using Microsoft.VisualStudio.TestTools.UnitTesting;
28 using static ArchiSteamFarm.Helpers.ArchiCryptoHelper;
30 namespace ArchiSteamFarm.Tests;
32 #pragma warning disable CA1812 // False positive, the class is used during MSTest
33 [TestClass]
34 internal sealed class ArchiCryptoHelper {
35 private const string TestPassword = "a2o41PuPdZNDLw9AT6dZt5pLVC23MN9O7NfKI4a0MWJgWWIAVGt3naYiIA0BhPel";
37 [DataRow(ECryptoMethod.PlainText)]
38 [DataRow(ECryptoMethod.AES)]
39 [DataTestMethod]
40 internal async Task CanEncryptDecrypt(ECryptoMethod cryptoMethod) {
41 if (!Enum.IsDefined(cryptoMethod)) {
42 throw new InvalidEnumArgumentException(nameof(cryptoMethod), (int) cryptoMethod, typeof(ECryptoMethod));
45 string? encrypted = Encrypt(cryptoMethod, TestPassword);
47 Assert.IsNotNull(encrypted);
49 string? decrypted = await Decrypt(cryptoMethod, encrypted).ConfigureAwait(false);
51 Assert.IsNotNull(decrypted);
52 Assert.AreEqual(TestPassword, decrypted);
55 [TestMethod]
56 internal async Task CanEncryptDecryptProtectedDataForCurrentUser() {
57 if (!OperatingSystem.IsWindows()) {
58 // Not supported on other platforms than Windows
59 return;
62 await CanEncryptDecrypt(ECryptoMethod.ProtectedDataForCurrentUser).ConfigureAwait(false);
65 #pragma warning restore CA1812 // False positive, the class is used during MSTest