11 using System.Security.Cryptography;
16 public partial class JsonDatabaseConnector: DatabaseConnector {
19 public List<Domain>
DomainList {
get;
set; } =
new List<Domain>();
27 if (jsonFile is
null) {
28 throw new ArgumentNullException(nameof(jsonFile));
30 if (key is
null || key.Length == 0) {
31 throw new ArgumentNullException(nameof(key));
33 if (initVector is
null || initVector.Length == 0) {
34 throw new ArgumentNullException(nameof(initVector));
65 var fContents = File.ReadAllBytes(
JsonFile.FullName);
66 if (fContents is
null) {
72 if (decryptedString is
null) {
81 var fContents = await File.ReadAllBytesAsync(
JsonFile.FullName);
82 if (fContents is
null) {
88 if (decryptedString is
null) {
97 using var fStream =
JsonFile.Create();
98 using var sWriter =
new StreamWriter(fStream);
103 using var fStream =
JsonFile.Create();
104 using var sWriter =
new StreamWriter(fStream);
109 public override Task<List<Domain>>
GetDomainsAsync(
bool includeUsers =
true, params
string[] tlds) {
110 if (tlds.Length == 0) {
111 return Task.FromResult(
120 return Task.FromResult(
123 new List<Domain>(filteredDomains.Select(x =>
new Domain(x)))
131 return Task.CompletedTask;
160 var domainUsers = domainToPurge.DomainUsers.Count;
161 domainToPurge.DomainUsers =
new List<DomainUser>();
170 domainToEdit.DomainUsers.Remove(user);
183 if (tld is
null || domain is
null) {
186 }
else if (tld is
null || domain is
null) {
187 throw new Exception(
"An unknown exception has occurred!");
198 throw new NotImplementedException();
Represents a single domain.
string DomainName
The name of the domain.
string Tld
The top-level domain.
static bool IsValidDomain(string fqdn, out int? tldLevels, out string? tld, out string? domain)
Gets a value indicating whether or not a given domain is valid.
static async Task< bool > DownloadCurrentValidTldListFromIanaAsync()
Asynchronously downloads the latest list of TLDs from the IANA.
This class represents a single user (email account) in a domain.
Exception class that is thrown when an invalid domain name is encountered.
List< Domain > DomainList
override async Task InitialiseDatabaseAsync()
Asynchronously initialises the database.An awaitable Task
async Task< byte[]> EncryptStringAsync(string plaintext)
Asynchronously encrypts a given string.
JsonDatabaseConnector(FileInfo jsonFile, byte[] key, byte[] initVector)
async Task DumpJsonAsync()
async Task ReadFileAsync()
async Task< string > DecryptStringAsync(byte[] bytes)
Asynchronously decrypts a cipher text to a string.
override async Task< Domain > AddDomainAsync(string domainName)
Adds a single domain to the database.An awaitable Task<Domain> containing the newly generated domain.
byte[] EncryptString(string plaintext)
Encrypts a string.
override async Task< int > PurgeDatabasesAsync()
override Task GetUsersForDomainAsync(Domain domain)
Asynchronously gets all the users for a given domain.An awaitable Task
override void Connect()
Connect to the database.
override async Task< int > PurgeUsersFromDomainAsync(Domain domain)
DomainContainer m_jsonObj
override async Task< bool > RemoveUserFromDomainAsync(Domain domain, DomainUser user)
Asynchronously removes a single user from a given domain.An awaitable Task<Boolean> indicating whethe...
string DecryptString(byte[] bytes)
Decrypts a cipher text to a string.
override Task< bool > RemoveDomainAsync(Domain domain)
Removes a single domain from the database.
override async Task ConnectAsync()
Asynchronously connect to the database.An awaitable Task
override Task< bool > IsInitialisedAsync()
Asynchronously gets a value indicating whether or not the database is initialised....
override Task< List< Domain > > GetDomainsAsync(bool includeUsers=true, params string[] tlds)
Asynchronously gets a list of all known domains.An awaitable Task<List<Domain>> containing the search...