Skip to content

Commit c97712b

Browse files
committed
🧑‍💻 Reduce what's used from xecrets-net #72
1 parent 1a4fd7e commit c97712b

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

src/Xecrets.Cli/Program.cs

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,17 @@
2323

2424
#endregion Coypright and GPL License
2525

26-
using System.Reflection;
2726
using System.Runtime.CompilerServices;
2827
using System.Text;
2928

3029
using AxCrypt.Abstractions;
3130
using AxCrypt.Abstractions.Algorithm;
32-
using AxCrypt.Api;
3331
using AxCrypt.Core;
3432
using AxCrypt.Core.Crypto;
35-
using AxCrypt.Core.Extensions;
33+
using AxCrypt.Core.Crypto.Asymmetric;
3634
using AxCrypt.Core.IO;
35+
using AxCrypt.Core.Portable;
3736
using AxCrypt.Core.Runtime;
38-
using AxCrypt.Core.Service;
3937
using AxCrypt.Core.UI;
4038
using AxCrypt.Mono;
4139
using AxCrypt.Mono.Portable;
@@ -49,6 +47,8 @@
4947
using Xecrets.Cli.Run;
5048
using Xecrets.Licensing.Abstractions;
5149
using Xecrets.Licensing.Implementation;
50+
using Xecrets.Net.Api.Implementation;
51+
using Xecrets.Net.Core;
5252

5353
using static AxCrypt.Abstractions.TypeResolve;
5454

@@ -58,32 +58,46 @@
5858

5959
var options = new OptionsParser(Environment.CommandLine);
6060

61-
RuntimeEnvironment.RegisterTypeFactories();
61+
TypeMap.Register.Singleton<IRuntimeEnvironment>(() => new RuntimeEnvironment(".axx"));
62+
TypeMap.Register.Singleton<IPortableFactory>(() => new PortableFactory());
63+
TypeMap.Register.Singleton<ILogging>(() => new Logging());
64+
TypeMap.Register.Singleton<IPlatform>(() => new MonoPlatform());
65+
TypeMap.Register.Singleton<IPath>(() => new PortablePath());
66+
67+
TypeMap.Register.New<string, IDataStore>((path) => new DataStore(path));
68+
TypeMap.Register.New<string, IDataContainer>((path) => new DataContainer(path));
69+
TypeMap.Register.New<string, IDataItem>((path) => DataItem.Create(path));
6270

6371
string workFolderPath = Path.Combine(Path.GetTempPath(), "Axantum/XecretsCli".Replace('/', Path.DirectorySeparatorChar));
64-
Directory.CreateDirectory(workFolderPath);
65-
Resolve.RegisterTypeFactories(workFolderPath, []);
72+
Directory.CreateDirectory(workFolderPath);
73+
74+
TypeMap.Register.Singleton(() => new UserSettingsVersion());
75+
TypeMap.Register.Singleton(() => new UserSettings(New<ISettingsStore>(), New<IterationCalculator>()));
76+
TypeMap.Register.Singleton<IRandomGenerator>(() => new RandomGenerator());
77+
TypeMap.Register.Singleton<IAsymmetricFactory>(() => new BouncyCastleAsymmetricFactory());
78+
TypeMap.Register.Singleton(() => new CryptoFactory([]));
79+
80+
TypeMap.Register.New(() => new AxCryptFactory());
81+
TypeMap.Register.New(() => new AxCryptFile());
82+
TypeMap.Register.New<int, Salt>((size) => new Salt(size));
83+
TypeMap.Register.New(() => new IterationCalculator());
84+
TypeMap.Register.Singleton<IStringSerializer>(() => new SystemTextJsonStringSerializer(JsonSourceGenerationContext.CreateJsonSerializerContext()));
85+
86+
TypeMap.Register.Singleton(() => new WorkFolder(workFolderPath), () => { });
6687

6788
TypeMap.Register.Singleton(() => new FileLocker());
68-
TypeMap.Register.Singleton<IProtectedData>(() => new ProtectedDataImplementation("Xecrets.Cli"));
69-
TypeMap.Register.New<ILauncher>(() => new Launcher());
7089
TypeMap.Register.New(() => PortableFactory.AxCryptHMACSHA1());
7190
TypeMap.Register.New<HMACSHA512>(() => new AxCrypt.Mono.Cryptography.HMACSHA512Wrapper(new AxCrypt.Desktop.Cryptography.HMACSHA512CryptoServiceProvider()));
7291
TypeMap.Register.New<Aes>(() => new AxCrypt.Mono.Cryptography.AesWrapper(System.Security.Cryptography.Aes.Create()));
7392
TypeMap.Register.New<Sha1>(() => PortableFactory.SHA1Managed());
7493
TypeMap.Register.New<Sha256>(() => PortableFactory.SHA256Managed());
7594
TypeMap.Register.New<CryptoStreamBase>(() => PortableFactory.CryptoStream());
7695
TypeMap.Register.New(() => PortableFactory.RandomNumberGenerator());
77-
TypeMap.Register.New<LogOnIdentity, IAccountService>((LogOnIdentity identity) => new CachingAccountService(new DeviceAccountService(new LocalAccountService(identity, Resolve.WorkFolder.FileInfo), new ApiAccountService(new AxCryptApiClient(identity.ToRestIdentity(), Resolve.UserSettings.RestApiBaseUrl, Resolve.UserSettings.ApiTimeout)))));
78-
TypeMap.Register.New(() => new GlobalApiClient(Resolve.UserSettings.RestApiBaseUrl, Resolve.UserSettings.ApiTimeout));
79-
TypeMap.Register.New(() => new AxCryptApiClient(Resolve.KnownIdentities.DefaultEncryptionIdentity.ToRestIdentity(), Resolve.UserSettings.RestApiBaseUrl, Resolve.UserSettings.ApiTimeout));
8096
TypeMap.Register.New<ISystemCryptoPolicy>(() => new ProCryptoPolicy());
81-
TypeMap.Register.New<ICryptoPolicy>(() => New<LicensePolicy>().Capabilities.CryptoPolicy);
8297

8398
TypeMap.Register.Singleton<IReport>(() => new Report(Resolve.WorkFolder.FileInfo.FullName, 1000000));
8499
TypeMap.Register.Singleton(() => TimeProvider.System);
85100
TypeMap.Register.Singleton<INow>(() => new TimeProviderNow());
86-
TypeMap.Register.New<string, IFileWatcher>((path) => new FileWatcher());
87101

88102
// Avoid JSON deserialization errors when the user settings file is empty.
89103
IDataStore settings = Resolve.WorkFolder.FileInfo.FileItemInfo("UserSettings.txt");
@@ -93,7 +107,6 @@
93107
}
94108
TypeMap.Register.Singleton<ISettingsStore>(() => new SettingsStore(settings));
95109

96-
TypeMap.Register.Singleton<IUIThread>(() => new UIThread());
97110
TypeMap.Register.Singleton(() => new ConsoleOut(Console.Error));
98111
TypeMap.Register.Singleton<IEmailParser>(() => new EmailParser());
99112
TypeMap.Register.Singleton(() => new Splash(Resource.splash));

src/Xecrets.Cli/TestCli/win-x64/Examples.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ echo === adaptions are needed.
55

66
echo === Assume set PATH=%%PATH%%;[Path-to-executable]
77
echo === For example:
8-
echo === set PATH=%%PATH%%;"C:\Users\%UserName%\Documents\Visual Studio 2022\Projects\xecrets\xecrets-file-cli\src\Xecrets.Cli\bin\Debug\net8.0\"
8+
echo === set PATH=%%PATH%%;"C:\Users\%UserName%\Documents\Visual Studio 2022\Projects\xecrets\xecrets-cli\src\Xecrets.Cli\bin\Debug\net8.0\"
99
echo.
1010
echo === Ensure there is a file thfg.mp4 and a folder Photos with files 1.jpg ... 5.jpg
1111
echo === in the current folder, named win-x64.

0 commit comments

Comments
 (0)