diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 3cd9a8e..1ef8d0e 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,5 +1,5 @@ -# This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET). -# Copyright (c) 2021 SocialVoid.NET Authors. +# This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). +# Copyright (c) 2021 Socialvoid.NET Authors. # # This library is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -17,7 +17,7 @@ version: 2 updates: - package-ecosystem: nuget - directory: "/SocialVoid" + directory: "/Socialvoid" schedule: interval: daily time: "15:00" diff --git a/.github/stale.yml b/.github/stale.yml index 97b7657..d0fe6d5 100644 --- a/.github/stale.yml +++ b/.github/stale.yml @@ -1,5 +1,5 @@ -# This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET). -# Copyright (c) 2021 SocialVoid.NET Authors. +# This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). +# Copyright (c) 2021 Socialvoid.NET Authors. # # This library is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/.github/workflows/dotnet-linux.yml b/.github/workflows/dotnet-linux.yml index 15867a1..46ca488 100644 --- a/.github/workflows/dotnet-linux.yml +++ b/.github/workflows/dotnet-linux.yml @@ -1,5 +1,5 @@ -# This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET). -# Copyright (c) 2021 SocialVoid.NET Authors. +# This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). +# Copyright (c) 2021 Socialvoid.NET Authors. # # This library is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/.github/workflows/dotnet-windows.yml b/.github/workflows/dotnet-windows.yml index a7572aa..48ff396 100644 --- a/.github/workflows/dotnet-windows.yml +++ b/.github/workflows/dotnet-windows.yml @@ -1,5 +1,5 @@ -# This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET). -# Copyright (c) 2021 SocialVoid.NET Authors. +# This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). +# Copyright (c) 2021 Socialvoid.NET Authors. # # This library is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/.gitignore b/.gitignore index 0ea5202..405d83d 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ woto_files/ woto_docs/ woto_tests/ woto_objects/ +/.vs/ diff --git a/CODESTYLE.md b/CODESTYLE.md index a9f88c1..de947e9 100755 --- a/CODESTYLE.md +++ b/CODESTYLE.md @@ -1,6 +1,6 @@ -> #### NOTE: This code style standard for SocialVoid.NET is a work in progress and much of the code does not currently conform to these rules. This is something that will be addressed by the core team. +> #### NOTE: This code style standard for Socialvoid.NET is a work in progress and much of the code does not currently conform to these rules. This is something that will be addressed by the core team. # Introduction -As the SocialVoid.NET project gains more traction and becomes more widely used, we aim to provide a more professional and consistent look to the large amount of source now in the project. It was a broadly supported decision by the core development team to follow the Microsoft coding guidelines (the default provided in Visual Studio's C# editor). These coding guidelines listed below are based on a [MSDN blog post](http://blogs.msdn.com/b/brada/archive/2005/01/26/361363.aspx) from 2005 by Brad Abrams describing the internal coding guidelines at Microsoft, with some changes to suit our project. +As the Socialvoid.NET project gains more traction and becomes more widely used, we aim to provide a more professional and consistent look to the large amount of source now in the project. It was a broadly supported decision by the core development team to follow the Microsoft coding guidelines (the default provided in Visual Studio's C# editor). These coding guidelines listed below are based on a [MSDN blog post](http://blogs.msdn.com/b/brada/archive/2005/01/26/361363.aspx) from 2005 by Brad Abrams describing the internal coding guidelines at Microsoft, with some changes to suit our project. # Coding Guidelines ## Tabs & Indenting @@ -117,8 +117,8 @@ Comments must provide added value or explanation to the code. Simply describing Each file **should** start with a copyright notice. This is a short statement declaring the project name and copyright notice, and directing the reader to the license document elsewhere in the project. To avoid errors in doc comment builds, avoid using triple-slash doc comments. ```csharp /* - * This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET). - * Copyright (c) 2021 SocialVoid.NET Authors. + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. * * This library is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -254,7 +254,7 @@ In addition, the goal is to have clean, readable source. Code legibility should ## File Organization * Source files should contain only one public type, although multiple internal types are permitted if required. * Source files should be given the name of the public type in the file. -* Directory names should follow the namespace for the class after `SocialVoid`. For example, one would expect to find the public class `SocialVoid.Constants.WotoTools` in **SocialVoid\Constants\WotoTools.cs**. +* Directory names should follow the namespace for the class after `Socialvoid`. For example, one would expect to find the public class `Socialvoid.Constants.WotoTools` in **Socialvoid\Constants\WotoTools.cs**. * Class members should be grouped logically, and encapsulated into regions: ```csharp diff --git a/README.md b/README.md index 15fca83..51a9495 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -# SocialVoid.NET \ No newline at end of file +# Socialvoid.NET \ No newline at end of file diff --git a/SocialVoid.png b/Socialvoid.png similarity index 100% rename from SocialVoid.png rename to Socialvoid.png diff --git a/SocialVoid.sln b/Socialvoid.sln similarity index 89% rename from SocialVoid.sln rename to Socialvoid.sln index 11814ff..dd41f31 100644 --- a/SocialVoid.sln +++ b/Socialvoid.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SocialVoid", "SocialVoid\SocialVoid.csproj", "{6CB5C21A-EB16-48D6-B98A-F18D7CE46785}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Socialvoid", "Socialvoid\Socialvoid.csproj", "{6CB5C21A-EB16-48D6-B98A-F18D7CE46785}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBD}") = "Tests", "Tests\Tests.csproj", "{2EFF7FAB-7794-4BFA-AB48-998ADADC45A9}" EndProject diff --git a/Socialvoid/Client/SocialvoidClient.cs b/Socialvoid/Client/SocialvoidClient.cs new file mode 100644 index 0000000..c41694b --- /dev/null +++ b/Socialvoid/Client/SocialvoidClient.cs @@ -0,0 +1,603 @@ +/* + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this source code of library. + * If not, see . + */ + +using System; +using System.Text; +using System.Net.Http; +using System.IO; +using Socialvoid.Security; +using Socialvoid.Security.Otp; +using Socialvoid.JObjects; +using Socialvoid.Errors.ServerErrors; +using Socialvoid.Errors.AuthenticationErrors; +using Socialvoid.Errors.ValidationErrors; +using MType = System.Net.Http.Headers.MediaTypeHeaderValue; + +namespace Socialvoid.Client +{ + /// + /// Socialvoid client. + /// since: v0.0.0 + /// + public abstract class SocialvoidClient + { + //------------------------------------------------- + #region Constant's Region + /// + /// the content type of all of our http requests. + /// since: v0.0.0 + /// + protected internal const string ContentType = "application/json-rpc"; + /// + /// the username key in jsonrpc request params. + /// since: v0.0.0 + /// + protected const string UsernameKey = "username"; + /// + /// the password key in jsonrpc request params. + /// since: v0.0.0 + /// + protected const string PasswordKey = "password"; + /// + /// the otp key in jsonrpc request params. + /// since: v0.0.0 + /// + protected const string OtpKey = "otp"; + /// + /// the public hash key in jsonrpc request params. + /// since: v0.0.0 + /// + protected const string PublicHashKey = "public_hash"; + /// + /// the private hash key in jsonrpc request params. + /// since: v0.0.0 + /// + protected const string PrivateHashKey = "private_hash"; + /// + /// the platform key in jsonrpc request params. + /// since: v0.0.0 + /// + protected const string PlatformKey = "platform"; + /// + /// the name key in jsonrpc request params. + /// since: v0.0.0 + /// + protected const string NameKey = "name"; + /// + /// the version key in jsonrpc request params. + /// since: v0.0.0 + /// + protected const string VersionKey = "version"; + /// + /// authenticate_user method value. + /// since: v0.0.0 + /// + protected const string AuthenticateUserMethod = "session.authenticate_user"; + /// + /// authenticate_user method value. + /// since: v0.0.0 + /// + protected const string CreateSessionMethod = "session.create"; + /// + /// authenticate_user method value. + /// since: v0.0.0 + /// + protected const string SessionIDKey = "session_identification"; + #endregion + //------------------------------------------------- + #region static Properties Region + // some members here + #endregion + //------------------------------------------------- + #region Properties Region + /// + /// The public hash of the client. + /// since: v0.0.0 + /// + public string PublicHash { get; protected set; } + /// + /// The private hash of the client. + /// since: v0.0.0 + /// + public string PrivateHash { get; protected set; } + /// + /// The platform of the client. + /// since: v0.0.0 + /// + public string Platform { get; protected set; } + /// + /// The name of the client. + /// since: v0.0.0 + /// + public string ClientName { get; protected set; } + /// + /// The version of the client. + /// since: v0.0.0 + /// + public string Version { get; protected set; } + /// + /// + /// since: v0.0.0 + /// + public HttpClient HttpClient { get; protected set; } + #endregion + //------------------------------------------------- + #region static field's Region + // some members here + #endregion + //------------------------------------------------- + #region field's Region + /// + /// the endpoint url of socialvoid servers. + /// since: v0.0.0 + /// + protected internal string _endpoint = "http://socialvoid.qlg1.com:5601/"; + /// + /// Session object of this client. + /// since: v0.0.0 + /// + protected internal SessionEstablished _session; + /// + /// if the client should send an otp answer in the next request, + /// this field should be set to true. + /// since: v0.0.0 + /// + protected bool _should_otp; + /// + /// the last otp value of the client which should be sent in the + /// next jsonrpc request. + /// since: v0.0.0 + /// + protected string _otp; + /// + /// since: v0.0.0 + /// + protected readonly MType _contentTypeValue = MType.Parse(ContentType); + #endregion + //------------------------------------------------- + #region static event field's Region + // some members here + #endregion + //------------------------------------------------- + #region event field's Region + // some members here + #endregion + //------------------------------------------------- + #region Constructor's Region + /// + /// Creates a new instance of the class. + /// since: v0.0.0 + /// + /// + /// the public hash of the client. + /// + /// + /// the private hash of the client. + /// + /// + /// the platform of the client. + /// + /// + /// the client name. + /// + /// + /// the version of the client. + /// + protected SocialvoidClient(string publicHash, string privateHash, + string platform, string name, string version) + { + PublicHash = publicHash; + PrivateHash = privateHash; + Platform = platform; + ClientName = name; + Version = version; + HttpClient = new(); + } + + + #endregion + //------------------------------------------------- + #region Destructor's Region + // some members here + #endregion + //------------------------------------------------- + #region Initialize Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region Graphical Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region event Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region overrided Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region ordinary Method's Region + + /// + /// CreateSession method (session.create), establishes a new session + /// to the network. + /// Please do notice that new and unauthenticated sessions + /// expires after 10 minutes of inactivity, authenticating to the session + /// will increase the expiration time to 72 hours of inactivity. This timer + /// is reset whenever the session is used in one way or another. + /// since: v0.0.0 + /// + /// + /// Thrown if the server encounters an internal error. + /// + /// + /// Thrown if the parameter passed as client name is not valid. + /// + /// + /// Thrown if the parameter passed as public hash is not valid. + /// + /// + /// Thrown if the parameter passed as private hash is not valid. + /// + /// + /// Thrown if the parameter passed as platform is not valid. + /// + /// + /// Thrown if the parameter passed as version is not valid. + /// + public virtual SessionEstablished CreateSession() + { + JArgs args = new(){ + {PublicHashKey, PublicHash}, + {PrivateHashKey, PrivateHash}, + {PlatformKey, Platform}, + {NameKey, ClientName}, + {VersionKey, Version}, + }; + + + var request = GetRpcRequest(CreateSessionMethod, args); + + var message = new HttpRequestMessage(HttpMethod.Post, _endpoint); + message.Content = SerializeContent(request); + message.Content.Headers.ContentType = _contentTypeValue; + var jresp = ParseContent(message); + + if (!string.IsNullOrEmpty(jresp.Result.ChallengeSecret)) + { + _should_otp = true; + _otp = GetChallengeAnswer(jresp.Result.ChallengeSecret); + // set challenege secret to null to avoid sending it again. + // this will avoid future conflicts in using old challenge secret. + jresp.Result.ChallengeSecret = null; + } + _session = jresp.Result; + + return _session; + } + /// + /// AuthenticateUser method (session.authenticate_user), + /// Authenticates a user via a Username and Password combination. + /// Optionally two-factor authentication if the account has enabled it. + /// Once authenticated, the session will be able to access methods that + /// requires authentication and preform operations as the authenticated + /// user. + /// since: v0.0.0 + /// + /// + /// The Session Identification object. + /// + /// + /// The username of the user to authenticate to. + /// + /// + /// The password used to authenticate to this account. + /// + /// + /// The optional one-time password used to authenticate to this account. + /// It will be ignored by server if empty or larger than 64 characters. + /// + /// + /// Thrown if the server encounters an internal error. + /// + /// + /// Thrown if the authentication fails. + /// + /// + /// Thrown if the user is already authenticated. + /// + /// + /// Thrown if the user is not able to authenticate. + /// + /// + /// Thrown if the session challenge answer is invalid. + /// + /// + /// Thrown if the username or password is incorrect. + /// + /// + /// Thrown if the two-factor authentication code is incorrect. + /// + /// + /// Thrown if the user is not authenticated and the private access token is required. + /// + /// + /// Thrown if the session has expired. + /// + /// + /// Thrown if two-factor authentication is required. + /// + public virtual void AuthenticateUser(string username, string password, + string otp = null, SessionIdentification sessionID = null) + { + if (sessionID == null && _session != null) + { + sessionID = new() + { + SessionID = _session.SessionID, + ClientPublicHash = PublicHash + }; + } + + JArgs args = new(){ + {UsernameKey, username}, + {PasswordKey, password}, + {SessionIDKey, sessionID}, + }; + + // check if the passed-by otp argument is valid or not. + // if yes, ignore _otp field and use user's specified otp value. + // otherwise check for _should_otp and see if we should send an + // otp answer or not. + if (IsOtpValid(otp)) + { + args.Add(OtpKey, otp); + sessionID.ChallengeAnswer = otp; + } + else if (_should_otp && IsOtpValid(_otp)) + { + // after adding otp answer to args, don't forget to set + // _should_otp to false (and _otp to null). + args.Add(OtpKey, _otp); + sessionID.ChallengeAnswer = _otp; + _should_otp = false; + _otp = null; + } + + var request = GetRpcRequest(AuthenticateUserMethod, args); + + var message = new HttpRequestMessage(HttpMethod.Post, _endpoint); + message.Content = SerializeContent(request); + message.Content.Headers.ContentType = _contentTypeValue; + var resp = HttpClient.Send(message); + var contentStr = ReadFromContent(resp.Content); + + Console.WriteLine(contentStr); + } + + /// + /// returns a challenge's answer using the session's challenge secret. + /// since: v0.0.0 + /// + protected internal virtual string GetChallengeAnswer(string secret) + { + var otp = new Totp(Encoding.UTF8.GetBytes(secret)); + return KeyGeneration.GetSha1(otp.ComputeTotp() + PrivateHash);; + } + + #endregion + //------------------------------------------------- + #region Get Method's Region + /// + /// Gets the session of this if and only + /// if you have already established a session (or has loaded it from a file); + /// oterwise it will just return a null object instead of throwing an exception. + /// since: v0.0.0 + /// + public virtual SessionEstablished GetSession() + { + return _session; + } + /// + /// since: v0.0.0 + /// + /// + /// the method. + /// + /// + /// the arguments. + /// + /// + /// the request ID. + /// + /// + /// set it to `true` if you want this request to have requestID parameter + /// set. (if the passed-by id paramater is null, this method will generate + /// a new id itself.) + /// + protected internal JRequest GetRpcRequest(string method, + JArgs args = null, + Nullable id = null, + bool useID = true) + { + if (string.IsNullOrWhiteSpace(method)) + { + throw new ArgumentException( + "method name in a rpc request cannot be null or empty", + nameof(method)); + } + if (useID && (id == null)) + { + id = DateTime.Now.Ticks; + } + + return useID && id != null && id.HasValue ? + new() + { + Method = method, + Arguments = args, + ID = id.Value, + } : + new() + { + Method = method, + Arguments = args, + }; + } + + /// + /// since: v0.0.0 + /// + protected StringContent SerializeContent(JRequest request) + { + return new(request.Serialize()); + } + /// + /// Parses the content of a as a + /// . + /// + /// + /// + protected internal JResponse ParseContent( + HttpRequestMessage message, + bool ex = true) + where VType : class + { + if (HttpClient == null) + { + throw new InvalidOperationException("HttpClient wasn't initialized"); + } + var resp = HttpClient.Send(message); + if (resp == null) + { + throw new InvalidOperationException("HttpClient.Send returned null"); + } + + return ParseContent(resp.Content, ex); + } + #endregion + //------------------------------------------------- + #region Set Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region static Method's Region + /// + /// Creates a new instance of the class. + /// since: v0.0.0 + /// + /// + /// the public hash of the client. + /// + /// + /// the private hash of the client. + /// + /// + /// the platform of the client. + /// + /// + /// the client name. + /// + /// + /// the version of the client. + /// + public static SocialvoidClient GetClient(string publicHash, string privateHash, + string platform, string name, string version) + { + if (string.IsNullOrWhiteSpace(publicHash) || publicHash.Length != 64) + { + throw new ArgumentException( + "publicHash parameter is invalid", + nameof(publicHash)); + } + if (string.IsNullOrWhiteSpace(privateHash) || privateHash.Length != 64) + { + throw new ArgumentException( + "privateHash parameter is invalid", + nameof(privateHash)); + } + if (string.IsNullOrWhiteSpace(platform)) + { + throw new ArgumentException( + "platform cannot be null or empty", + nameof(platform)); + } + if (string.IsNullOrWhiteSpace(version)) + { + throw new ArgumentException( + "version cannot be null or empty", + nameof(version)); + } + return new SvClient(publicHash, privateHash, platform, name, version); + } + + /// + /// Checks if a string can be sent as a TOTOP answer or not. + /// since: v0.0.0 + /// + /// + /// the otp string to check. + /// + /// + /// true if the otp string is valid; otherwise false. + /// + protected internal static bool IsOtpValid(string otp) + { + return !(string.IsNullOrWhiteSpace(otp) || otp.Length > 64); + } + /// + /// reads the content of a as a string. + /// returns null if the stream cannot be read. + /// + /// + /// + protected internal static string ReadFromContent(HttpContent content) + { + var stream = content.ReadAsStream(); + if (stream == null || !stream.CanRead) + { + return null; + } + + return new StreamReader(stream).ReadToEnd(); + } + /// + /// Parses the content of a as a + /// . + /// + /// + /// + protected internal static JResponse ParseContent( + HttpContent content, + bool ex = true) + where VType : class + { + var jresp = JResponse.Deserialize(ReadFromContent(content)); + if (ex && jresp.HasError()) + { + throw jresp.GetException(); + } + + return jresp; + } + + #endregion + //------------------------------------------------- + } +} diff --git a/Socialvoid/Client/SvClient.cs b/Socialvoid/Client/SvClient.cs new file mode 100644 index 0000000..1dbcc6d --- /dev/null +++ b/Socialvoid/Client/SvClient.cs @@ -0,0 +1,100 @@ +/* + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this source code of library. + * If not, see . + */ + +namespace Socialvoid.Client +{ + internal sealed class SvClient : SocialvoidClient + { + //------------------------------------------------- + #region Constant's Region + // some members here + #endregion + //------------------------------------------------- + #region static Properties Region + // some members here + #endregion + //------------------------------------------------- + #region Properties Region + // some members here + #endregion + //------------------------------------------------- + #region static field's Region + // some members here + #endregion + //------------------------------------------------- + #region field's Region + // some members here + #endregion + //------------------------------------------------- + #region static event field's Region + // some members here + #endregion + //------------------------------------------------- + #region event field's Region + // some members here + #endregion + //------------------------------------------------- + #region Constructor's Region + public SvClient(string publicHash, string privateHash, + string platform, string name, string version) : + base(publicHash, privateHash, platform, name, version) + { + ; + } + + + #endregion + //------------------------------------------------- + #region Destructor's Region + // some members here + #endregion + //------------------------------------------------- + #region Initialize Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region Graphical Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region event Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region overrided Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region ordinary Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region Get Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region Set Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region static Method's Region + // some methods here + #endregion + //------------------------------------------------- + } +} \ No newline at end of file diff --git a/SocialVoid/Errors/AuthenticationErrors/AlreadyAuthenticatedException.cs b/Socialvoid/Errors/AuthenticationErrors/AlreadyAuthenticatedException.cs similarity index 93% rename from SocialVoid/Errors/AuthenticationErrors/AlreadyAuthenticatedException.cs rename to Socialvoid/Errors/AuthenticationErrors/AlreadyAuthenticatedException.cs index 772d7c5..1295340 100644 --- a/SocialVoid/Errors/AuthenticationErrors/AlreadyAuthenticatedException.cs +++ b/Socialvoid/Errors/AuthenticationErrors/AlreadyAuthenticatedException.cs @@ -1,6 +1,6 @@ /* - * This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET). - * Copyright (c) 2021 SocialVoid.NET Authors. + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. * * This library is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,7 @@ * If not, see . */ -namespace SocialVoid.Errors.NetworkErrors +namespace Socialvoid.Errors.AuthenticationErrors { /// /// This exception will be raised when the client is attempting diff --git a/SocialVoid/Errors/AuthenticationErrors/AuthenticationFailureException.cs b/Socialvoid/Errors/AuthenticationErrors/AuthenticationFailureException.cs similarity index 93% rename from SocialVoid/Errors/AuthenticationErrors/AuthenticationFailureException.cs rename to Socialvoid/Errors/AuthenticationErrors/AuthenticationFailureException.cs index d53832c..8344b02 100644 --- a/SocialVoid/Errors/AuthenticationErrors/AuthenticationFailureException.cs +++ b/Socialvoid/Errors/AuthenticationErrors/AuthenticationFailureException.cs @@ -1,6 +1,6 @@ /* - * This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET). - * Copyright (c) 2021 SocialVoid.NET Authors. + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. * * This library is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,7 @@ * If not, see . */ -namespace SocialVoid.Errors.NetworkErrors +namespace Socialvoid.Errors.AuthenticationErrors { /// /// This exception will be raised when the authentication process failed diff --git a/SocialVoid/Errors/AuthenticationErrors/AuthenticationNotApplicableException.cs b/Socialvoid/Errors/AuthenticationErrors/AuthenticationNotApplicableException.cs similarity index 93% rename from SocialVoid/Errors/AuthenticationErrors/AuthenticationNotApplicableException.cs rename to Socialvoid/Errors/AuthenticationErrors/AuthenticationNotApplicableException.cs index d1f2b7d..5d72633 100644 --- a/SocialVoid/Errors/AuthenticationErrors/AuthenticationNotApplicableException.cs +++ b/Socialvoid/Errors/AuthenticationErrors/AuthenticationNotApplicableException.cs @@ -1,6 +1,6 @@ /* - * This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET). - * Copyright (c) 2021 SocialVoid.NET Authors. + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. * * This library is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,7 @@ * If not, see . */ -namespace SocialVoid.Errors.NetworkErrors +namespace Socialvoid.Errors.AuthenticationErrors { /// /// This exception will be raised when the user does not support diff --git a/SocialVoid/Errors/AuthenticationErrors/BadSessionChallengeAnswerException.cs b/Socialvoid/Errors/AuthenticationErrors/BadSessionChallengeAnswerException.cs similarity index 93% rename from SocialVoid/Errors/AuthenticationErrors/BadSessionChallengeAnswerException.cs rename to Socialvoid/Errors/AuthenticationErrors/BadSessionChallengeAnswerException.cs index 1913d33..d446888 100644 --- a/SocialVoid/Errors/AuthenticationErrors/BadSessionChallengeAnswerException.cs +++ b/Socialvoid/Errors/AuthenticationErrors/BadSessionChallengeAnswerException.cs @@ -1,6 +1,6 @@ /* - * This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET). - * Copyright (c) 2021 SocialVoid.NET Authors. + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. * * This library is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,7 @@ * If not, see . */ -namespace SocialVoid.Errors.NetworkErrors +namespace Socialvoid.Errors.AuthenticationErrors { /// /// This exception will be raised when the given session challenge answer diff --git a/SocialVoid/Errors/AuthenticationErrors/IncorrectLoginCredentialsException.cs b/Socialvoid/Errors/AuthenticationErrors/IncorrectLoginCredentialsException.cs similarity index 92% rename from SocialVoid/Errors/AuthenticationErrors/IncorrectLoginCredentialsException.cs rename to Socialvoid/Errors/AuthenticationErrors/IncorrectLoginCredentialsException.cs index a5925b3..e9832dd 100644 --- a/SocialVoid/Errors/AuthenticationErrors/IncorrectLoginCredentialsException.cs +++ b/Socialvoid/Errors/AuthenticationErrors/IncorrectLoginCredentialsException.cs @@ -1,6 +1,6 @@ /* - * This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET). - * Copyright (c) 2021 SocialVoid.NET Authors. + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. * * This library is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,7 @@ * If not, see . */ -namespace SocialVoid.Errors.NetworkErrors +namespace Socialvoid.Errors.AuthenticationErrors { /// /// This exception will be raised when the given login credentials diff --git a/SocialVoid/Errors/AuthenticationErrors/IncorrectTwoFactorAuthenticationCodeException.cs b/Socialvoid/Errors/AuthenticationErrors/IncorrectTwoFactorAuthenticationCodeException.cs similarity index 93% rename from SocialVoid/Errors/AuthenticationErrors/IncorrectTwoFactorAuthenticationCodeException.cs rename to Socialvoid/Errors/AuthenticationErrors/IncorrectTwoFactorAuthenticationCodeException.cs index d2db0eb..dd028ac 100644 --- a/SocialVoid/Errors/AuthenticationErrors/IncorrectTwoFactorAuthenticationCodeException.cs +++ b/Socialvoid/Errors/AuthenticationErrors/IncorrectTwoFactorAuthenticationCodeException.cs @@ -1,6 +1,6 @@ /* - * This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET). - * Copyright (c) 2021 SocialVoid.NET Authors. + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. * * This library is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,7 @@ * If not, see . */ -namespace SocialVoid.Errors.NetworkErrors +namespace Socialvoid.Errors.AuthenticationErrors { /// /// This exception will be raised when the given two-factor diff --git a/SocialVoid/Errors/AuthenticationErrors/NotAuthenticatedException.cs b/Socialvoid/Errors/AuthenticationErrors/NotAuthenticatedException.cs similarity index 92% rename from SocialVoid/Errors/AuthenticationErrors/NotAuthenticatedException.cs rename to Socialvoid/Errors/AuthenticationErrors/NotAuthenticatedException.cs index 37b4768..46d4ba9 100644 --- a/SocialVoid/Errors/AuthenticationErrors/NotAuthenticatedException.cs +++ b/Socialvoid/Errors/AuthenticationErrors/NotAuthenticatedException.cs @@ -1,6 +1,6 @@ /* - * This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET). - * Copyright (c) 2021 SocialVoid.NET Authors. + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. * * This library is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,7 @@ * If not, see . */ -namespace SocialVoid.Errors.NetworkErrors +namespace Socialvoid.Errors.AuthenticationErrors { /// /// This exception will be raised when the client attempts to diff --git a/SocialVoid/Errors/AuthenticationErrors/PrivateAccessTokenRequiredException.cs b/Socialvoid/Errors/AuthenticationErrors/PrivateAccessTokenRequiredException.cs similarity index 93% rename from SocialVoid/Errors/AuthenticationErrors/PrivateAccessTokenRequiredException.cs rename to Socialvoid/Errors/AuthenticationErrors/PrivateAccessTokenRequiredException.cs index 1608807..b15675d 100644 --- a/SocialVoid/Errors/AuthenticationErrors/PrivateAccessTokenRequiredException.cs +++ b/Socialvoid/Errors/AuthenticationErrors/PrivateAccessTokenRequiredException.cs @@ -1,6 +1,6 @@ /* - * This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET). - * Copyright (c) 2021 SocialVoid.NET Authors. + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. * * This library is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,7 @@ * If not, see . */ -namespace SocialVoid.Errors.NetworkErrors +namespace Socialvoid.Errors.AuthenticationErrors { /// /// This exception will be raised when the user/entity uses a diff --git a/SocialVoid/Errors/AuthenticationErrors/README.md b/Socialvoid/Errors/AuthenticationErrors/README.md similarity index 100% rename from SocialVoid/Errors/AuthenticationErrors/README.md rename to Socialvoid/Errors/AuthenticationErrors/README.md diff --git a/SocialVoid/Errors/AuthenticationErrors/SessionExpiredException.cs b/Socialvoid/Errors/AuthenticationErrors/SessionExpiredException.cs similarity index 92% rename from SocialVoid/Errors/AuthenticationErrors/SessionExpiredException.cs rename to Socialvoid/Errors/AuthenticationErrors/SessionExpiredException.cs index 78707bd..422518f 100644 --- a/SocialVoid/Errors/AuthenticationErrors/SessionExpiredException.cs +++ b/Socialvoid/Errors/AuthenticationErrors/SessionExpiredException.cs @@ -1,6 +1,6 @@ /* - * This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET). - * Copyright (c) 2021 SocialVoid.NET Authors. + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. * * This library is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,7 @@ * If not, see . */ -namespace SocialVoid.Errors.NetworkErrors +namespace Socialvoid.Errors.AuthenticationErrors { /// /// This exception will be raised when the client tried to use a session diff --git a/SocialVoid/Errors/AuthenticationErrors/SessionNotFoundException.cs b/Socialvoid/Errors/AuthenticationErrors/SessionNotFoundException.cs similarity index 92% rename from SocialVoid/Errors/AuthenticationErrors/SessionNotFoundException.cs rename to Socialvoid/Errors/AuthenticationErrors/SessionNotFoundException.cs index bd1e34a..855c9e2 100644 --- a/SocialVoid/Errors/AuthenticationErrors/SessionNotFoundException.cs +++ b/Socialvoid/Errors/AuthenticationErrors/SessionNotFoundException.cs @@ -1,6 +1,6 @@ /* - * This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET). - * Copyright (c) 2021 SocialVoid.NET Authors. + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. * * This library is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,7 @@ * If not, see . */ -namespace SocialVoid.Errors.NetworkErrors +namespace Socialvoid.Errors.AuthenticationErrors { /// /// This exception will be raised when the requested session can diff --git a/SocialVoid/Errors/AuthenticationErrors/TwoFactorAuthenticationRequiredException.cs b/Socialvoid/Errors/AuthenticationErrors/TwoFactorAuthenticationRequiredException.cs similarity index 93% rename from SocialVoid/Errors/AuthenticationErrors/TwoFactorAuthenticationRequiredException.cs rename to Socialvoid/Errors/AuthenticationErrors/TwoFactorAuthenticationRequiredException.cs index 8f46171..e6252d5 100644 --- a/SocialVoid/Errors/AuthenticationErrors/TwoFactorAuthenticationRequiredException.cs +++ b/Socialvoid/Errors/AuthenticationErrors/TwoFactorAuthenticationRequiredException.cs @@ -1,6 +1,6 @@ /* - * This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET). - * Copyright (c) 2021 SocialVoid.NET Authors. + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. * * This library is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,7 @@ * If not, see . */ -namespace SocialVoid.Errors.NetworkErrors +namespace Socialvoid.Errors.AuthenticationErrors { /// /// This exception will be raised when the Two-Factor Authentication diff --git a/SocialVoid/Errors/ErrorCodes.cs b/Socialvoid/Errors/ErrorCodes.cs similarity index 82% rename from SocialVoid/Errors/ErrorCodes.cs rename to Socialvoid/Errors/ErrorCodes.cs index 6a959d3..99374d9 100644 --- a/SocialVoid/Errors/ErrorCodes.cs +++ b/Socialvoid/Errors/ErrorCodes.cs @@ -1,6 +1,6 @@ /* - * This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET). - * Copyright (c) 2021 SocialVoid.NET Authors. + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. * * This library is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,10 +16,10 @@ * If not, see . */ -namespace SocialVoid.Errors +namespace Socialvoid.Errors { /// - /// All error codes received from the SocialVoid servers. + /// All error codes received from the Socialvoid servers. /// Since: v0.0.0 /// public enum ErrorCodes @@ -268,6 +268,61 @@ namespace SocialVoid.Errors InternalServerError = 16384, #endregion //------------------------------------------------- + #region RPC Errors + /// + /// Execution of the server method was aborted due to a cancellation request from + /// the client. + /// Since: v0.0.0 + /// + RequestCanceled = -32800, + /// + /// Invalid JSON was received by the server. An error occurred on the server while + /// parsing the JSON text. + /// Since: v0.0.0 + /// + ParseError = -32700, + /// + /// Internal JSON-RPC error. + /// Since: v0.0.0 + /// + InternalError = -32603, + /// + /// Invalid method parameter(s). + /// Since: v0.0.0 + /// + InvalidParams = -32602, + /// + /// The method does not exist / is not available. + /// Since: v0.0.0 + /// + MethodNotFound = -32601, + /// + /// The JSON object sent is not a valid Request object. + /// Since: v0.0.0 + /// + InvalidRequest = -32600, + /// + /// Indicates the RPC call was made but the target threw an exception. + /// Since: v0.0.0 + /// + InvocationErrorWithException = -32004, + /// + /// Indicates a response could not be serialized as the application intended. + /// Since: v0.0.0 + /// + ResponseSerializationFailure = -32003, + /// + /// Indicates a request was made to a remotely marshaled object that never existed + /// or has already been disposed of. + /// Since: v0.0.0 + /// + NoMarshaledObjectFound = -32001, + /// + /// Indicates the RPC call was made but the target threw an exception. + /// Since: v0.0.0 + /// + InvocationError = -32000 + #endregion } } diff --git a/SocialVoid/Errors/GeneralException.cs b/Socialvoid/Errors/GeneralException.cs similarity index 86% rename from SocialVoid/Errors/GeneralException.cs rename to Socialvoid/Errors/GeneralException.cs index a185fbd..ab76174 100644 --- a/SocialVoid/Errors/GeneralException.cs +++ b/Socialvoid/Errors/GeneralException.cs @@ -1,14 +1,17 @@ using System; -using SocialVoid.Errors.ServerErrors; -using SocialVoid.Errors.NetworkErrors; -using SocialVoid.Errors.ValidationErrors; +using Socialvoid.Errors.RPCErrors; +using Socialvoid.Errors.ServerErrors; +using Socialvoid.Errors.NetworkErrors; +using Socialvoid.Errors.ValidationErrors; +using Socialvoid.Errors.AuthenticationErrors; -namespace SocialVoid.Errors +namespace Socialvoid.Errors { /// /// /// Since: v0.0.0 /// + [Serializable] public class GeneralException : Exception { //------------------------------------------------- @@ -192,6 +195,27 @@ namespace SocialVoid.Errors // Server Errors ErrorCodes.InternalServerError => new InternalServerErrorException(m), + // RPC Errors + ErrorCodes.RequestCanceled => + new RequestCanceledException(m), + ErrorCodes.ParseError => + new ParseErrorException(m), + ErrorCodes.InternalError => + new InternalErrorException(m), + ErrorCodes.InvalidParams => + new InvalidParamsException(m), + ErrorCodes.MethodNotFound => + new MethodNotFoundException(m), + ErrorCodes.InvalidRequest => + new InvalidRequestException(m), + ErrorCodes.InvocationErrorWithException => + new InvocationErrorWithExException(m), + ErrorCodes.ResponseSerializationFailure => + new ResponseSerializationFailureException(m), + ErrorCodes.NoMarshaledObjectFound => + new NoMarshaledObjectFound(m), + ErrorCodes.InvocationError => + new InvocationErrorException(m), // an unknown error code? _ => new(m, err) diff --git a/SocialVoid/Errors/MediaErrors/README.md b/Socialvoid/Errors/MediaErrors/README.md similarity index 100% rename from SocialVoid/Errors/MediaErrors/README.md rename to Socialvoid/Errors/MediaErrors/README.md diff --git a/SocialVoid/Errors/NetworkErrors/AlreadyRepostedException.cs b/Socialvoid/Errors/NetworkErrors/AlreadyRepostedException.cs similarity index 93% rename from SocialVoid/Errors/NetworkErrors/AlreadyRepostedException.cs rename to Socialvoid/Errors/NetworkErrors/AlreadyRepostedException.cs index 353b2b2..c2ee1dd 100644 --- a/SocialVoid/Errors/NetworkErrors/AlreadyRepostedException.cs +++ b/Socialvoid/Errors/NetworkErrors/AlreadyRepostedException.cs @@ -1,6 +1,6 @@ /* - * This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET). - * Copyright (c) 2021 SocialVoid.NET Authors. + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. * * This library is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,7 @@ * If not, see . */ -namespace SocialVoid.Errors.NetworkErrors +namespace Socialvoid.Errors.NetworkErrors { /// /// This exception will be raised when the client attempts to repost a diff --git a/SocialVoid/Errors/NetworkErrors/FileUploadErrorException.cs b/Socialvoid/Errors/NetworkErrors/FileUploadErrorException.cs similarity index 93% rename from SocialVoid/Errors/NetworkErrors/FileUploadErrorException.cs rename to Socialvoid/Errors/NetworkErrors/FileUploadErrorException.cs index bd6a631..6d5297d 100644 --- a/SocialVoid/Errors/NetworkErrors/FileUploadErrorException.cs +++ b/Socialvoid/Errors/NetworkErrors/FileUploadErrorException.cs @@ -1,6 +1,6 @@ /* - * This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET). - * Copyright (c) 2021 SocialVoid.NET Authors. + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. * * This library is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,7 @@ * If not, see . */ -namespace SocialVoid.Errors.NetworkErrors +namespace Socialvoid.Errors.NetworkErrors { /// /// This exception will be raised when there was an error while trying to diff --git a/SocialVoid/Errors/NetworkErrors/PeerNotFoundException.cs b/Socialvoid/Errors/NetworkErrors/PeerNotFoundException.cs similarity index 93% rename from SocialVoid/Errors/NetworkErrors/PeerNotFoundException.cs rename to Socialvoid/Errors/NetworkErrors/PeerNotFoundException.cs index e8f7528..4c86ded 100644 --- a/SocialVoid/Errors/NetworkErrors/PeerNotFoundException.cs +++ b/Socialvoid/Errors/NetworkErrors/PeerNotFoundException.cs @@ -1,6 +1,6 @@ /* - * This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET). - * Copyright (c) 2021 SocialVoid.NET Authors. + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. * * This library is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,7 @@ * If not, see . */ -namespace SocialVoid.Errors.NetworkErrors +namespace Socialvoid.Errors.NetworkErrors { /// /// This exception will be raised when the requested user entity diff --git a/SocialVoid/Errors/NetworkErrors/PostDeletedException.cs b/Socialvoid/Errors/NetworkErrors/PostDeletedException.cs similarity index 92% rename from SocialVoid/Errors/NetworkErrors/PostDeletedException.cs rename to Socialvoid/Errors/NetworkErrors/PostDeletedException.cs index b038146..54b0984 100644 --- a/SocialVoid/Errors/NetworkErrors/PostDeletedException.cs +++ b/Socialvoid/Errors/NetworkErrors/PostDeletedException.cs @@ -1,6 +1,6 @@ /* - * This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET). - * Copyright (c) 2021 SocialVoid.NET Authors. + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. * * This library is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,7 @@ * If not, see . */ -namespace SocialVoid.Errors.NetworkErrors +namespace Socialvoid.Errors.NetworkErrors { /// /// This exception will be raised when the client requests a post that diff --git a/SocialVoid/Errors/NetworkErrors/PostNotFoundException.cs b/Socialvoid/Errors/NetworkErrors/PostNotFoundException.cs similarity index 93% rename from SocialVoid/Errors/NetworkErrors/PostNotFoundException.cs rename to Socialvoid/Errors/NetworkErrors/PostNotFoundException.cs index fb7d627..6399f74 100644 --- a/SocialVoid/Errors/NetworkErrors/PostNotFoundException.cs +++ b/Socialvoid/Errors/NetworkErrors/PostNotFoundException.cs @@ -1,6 +1,6 @@ /* - * This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET). - * Copyright (c) 2021 SocialVoid.NET Authors. + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. * * This library is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,7 @@ * If not, see . */ -namespace SocialVoid.Errors.NetworkErrors +namespace Socialvoid.Errors.NetworkErrors { /// /// This exception will be raised when the client requests a post that diff --git a/SocialVoid/Errors/NetworkErrors/README.md b/Socialvoid/Errors/NetworkErrors/README.md similarity index 100% rename from SocialVoid/Errors/NetworkErrors/README.md rename to Socialvoid/Errors/NetworkErrors/README.md diff --git a/SocialVoid/Errors/README.md b/Socialvoid/Errors/README.md similarity index 100% rename from SocialVoid/Errors/README.md rename to Socialvoid/Errors/README.md diff --git a/Socialvoid/Errors/RPCErrors/InternalErrorException.cs b/Socialvoid/Errors/RPCErrors/InternalErrorException.cs new file mode 100644 index 0000000..352490f --- /dev/null +++ b/Socialvoid/Errors/RPCErrors/InternalErrorException.cs @@ -0,0 +1,84 @@ +/* + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this source code of library. + * If not, see . + */ + +namespace Socialvoid.Errors.RPCErrors +{ + /// + /// This exception will be raised when an internal JSON-RPC error + /// happens at the server-side. + /// Since: v0.0.0 + /// + public sealed class InternalErrorException : GeneralException + { + //------------------------------------------------- + #region Constant's Region + // some members here + #endregion + //------------------------------------------------- + #region static Properties Region + // some members here + #endregion + //------------------------------------------------- + #region Properties Region + /// + /// The error code + /// will be returned because of an internal JSON-RPC error. + /// Since: v0.0.0 + /// + public override ErrorCodes ErrorCode + { + get + { + return ErrorCodes.InternalError; + } + } + #endregion + //------------------------------------------------- + #region static field's Region + // some members here + #endregion + //------------------------------------------------- + #region field's Region + // some members here + #endregion + //------------------------------------------------- + #region static event field's Region + // some members here + #endregion + //------------------------------------------------- + #region event field's Region + // some members here + #endregion + //------------------------------------------------- + #region Constructor's Region + /// + /// Creates a new instance of . + /// Since: v0.0.0 + /// + internal InternalErrorException(string message) : base(message) + { + ; + } + #endregion + //------------------------------------------------- + #region Destructor's Region + // some members here + #endregion + //------------------------------------------------- + } +} \ No newline at end of file diff --git a/Socialvoid/Errors/RPCErrors/InvalidParamsException.cs b/Socialvoid/Errors/RPCErrors/InvalidParamsException.cs new file mode 100644 index 0000000..168379e --- /dev/null +++ b/Socialvoid/Errors/RPCErrors/InvalidParamsException.cs @@ -0,0 +1,85 @@ +/* + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this source code of library. + * If not, see . + */ + +namespace Socialvoid.Errors.RPCErrors +{ + /// + /// This exception will be raised when invalid method parameter(s) is + /// received by socialvoid's servers. + /// Since: v0.0.0 + /// + public sealed class InvalidParamsException : GeneralException + { + //------------------------------------------------- + #region Constant's Region + // some members here + #endregion + //------------------------------------------------- + #region static Properties Region + // some members here + #endregion + //------------------------------------------------- + #region Properties Region + /// + /// The error code + /// will be returned because invalid method parameter(s) is + /// received by socialvoid's servers. + /// Since: v0.0.0 + /// + public override ErrorCodes ErrorCode + { + get + { + return ErrorCodes.InvalidParams; + } + } + #endregion + //------------------------------------------------- + #region static field's Region + // some members here + #endregion + //------------------------------------------------- + #region field's Region + // some members here + #endregion + //------------------------------------------------- + #region static event field's Region + // some members here + #endregion + //------------------------------------------------- + #region event field's Region + // some members here + #endregion + //------------------------------------------------- + #region Constructor's Region + /// + /// Creates a new instance of . + /// Since: v0.0.0 + /// + internal InvalidParamsException(string message) : base(message) + { + ; + } + #endregion + //------------------------------------------------- + #region Destructor's Region + // some members here + #endregion + //------------------------------------------------- + } +} \ No newline at end of file diff --git a/Socialvoid/Errors/RPCErrors/InvalidRequestException.cs b/Socialvoid/Errors/RPCErrors/InvalidRequestException.cs new file mode 100644 index 0000000..b11474a --- /dev/null +++ b/Socialvoid/Errors/RPCErrors/InvalidRequestException.cs @@ -0,0 +1,85 @@ +/* + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this source code of library. + * If not, see . + */ + +namespace Socialvoid.Errors.RPCErrors +{ + /// + /// This exception will be raised when the JSON object sent to + /// the socialvoid's server is not a valid Request object. + /// Since: v0.0.0 + /// + public sealed class InvalidRequestException : GeneralException + { + //------------------------------------------------- + #region Constant's Region + // some members here + #endregion + //------------------------------------------------- + #region static Properties Region + // some members here + #endregion + //------------------------------------------------- + #region Properties Region + /// + /// The error code + /// will be returned because the JSON object sent is not a + /// valid Request object. + /// Since: v0.0.0 + /// + public override ErrorCodes ErrorCode + { + get + { + return ErrorCodes.InvalidRequest; + } + } + #endregion + //------------------------------------------------- + #region static field's Region + // some members here + #endregion + //------------------------------------------------- + #region field's Region + // some members here + #endregion + //------------------------------------------------- + #region static event field's Region + // some members here + #endregion + //------------------------------------------------- + #region event field's Region + // some members here + #endregion + //------------------------------------------------- + #region Constructor's Region + /// + /// Creates a new instance of . + /// Since: v0.0.0 + /// + internal InvalidRequestException(string message) : base(message) + { + ; + } + #endregion + //------------------------------------------------- + #region Destructor's Region + // some members here + #endregion + //------------------------------------------------- + } +} \ No newline at end of file diff --git a/Socialvoid/Errors/RPCErrors/InvocationErrorException.cs b/Socialvoid/Errors/RPCErrors/InvocationErrorException.cs new file mode 100644 index 0000000..5ff32b2 --- /dev/null +++ b/Socialvoid/Errors/RPCErrors/InvocationErrorException.cs @@ -0,0 +1,85 @@ +/* + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this source code of library. + * If not, see . + */ + +namespace Socialvoid.Errors.RPCErrors +{ + /// + /// This exception will be raised when the RPC call was made but the target + /// threw an exception. + /// Since: v0.0.0 + /// + public sealed class InvocationErrorException : GeneralException + { + //------------------------------------------------- + #region Constant's Region + // some members here + #endregion + //------------------------------------------------- + #region static Properties Region + // some members here + #endregion + //------------------------------------------------- + #region Properties Region + /// + /// The error code + /// will be returned because the RPC call was made but the target + /// threw an exception. + /// Since: v0.0.0 + /// + public override ErrorCodes ErrorCode + { + get + { + return ErrorCodes.InvocationError; + } + } + #endregion + //------------------------------------------------- + #region static field's Region + // some members here + #endregion + //------------------------------------------------- + #region field's Region + // some members here + #endregion + //------------------------------------------------- + #region static event field's Region + // some members here + #endregion + //------------------------------------------------- + #region event field's Region + // some members here + #endregion + //------------------------------------------------- + #region Constructor's Region + /// + /// Creates a new instance of . + /// Since: v0.0.0 + /// + internal InvocationErrorException(string message) : base(message) + { + ; + } + #endregion + //------------------------------------------------- + #region Destructor's Region + // some members here + #endregion + //------------------------------------------------- + } +} \ No newline at end of file diff --git a/Socialvoid/Errors/RPCErrors/InvocationErrorWithExException.cs b/Socialvoid/Errors/RPCErrors/InvocationErrorWithExException.cs new file mode 100644 index 0000000..f10a036 --- /dev/null +++ b/Socialvoid/Errors/RPCErrors/InvocationErrorWithExException.cs @@ -0,0 +1,85 @@ +/* + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this source code of library. + * If not, see . + */ + +namespace Socialvoid.Errors.RPCErrors +{ + /// + /// This exception will be raised when the RPC call was made but + /// the target threw an exception. + /// Since: v0.0.0 + /// + public sealed class InvocationErrorWithExException : GeneralException + { + //------------------------------------------------- + #region Constant's Region + // some members here + #endregion + //------------------------------------------------- + #region static Properties Region + // some members here + #endregion + //------------------------------------------------- + #region Properties Region + /// + /// The error code + /// will be returned because the RPC call was made but + /// the target threw an exception. + /// Since: v0.0.0 + /// + public override ErrorCodes ErrorCode + { + get + { + return ErrorCodes.InvocationErrorWithException; + } + } + #endregion + //------------------------------------------------- + #region static field's Region + // some members here + #endregion + //------------------------------------------------- + #region field's Region + // some members here + #endregion + //------------------------------------------------- + #region static event field's Region + // some members here + #endregion + //------------------------------------------------- + #region event field's Region + // some members here + #endregion + //------------------------------------------------- + #region Constructor's Region + /// + /// Creates a new instance of . + /// Since: v0.0.0 + /// + internal InvocationErrorWithExException(string message) : base(message) + { + ; + } + #endregion + //------------------------------------------------- + #region Destructor's Region + // some members here + #endregion + //------------------------------------------------- + } +} \ No newline at end of file diff --git a/Socialvoid/Errors/RPCErrors/MethodNotFoundException.cs b/Socialvoid/Errors/RPCErrors/MethodNotFoundException.cs new file mode 100644 index 0000000..ca5a07f --- /dev/null +++ b/Socialvoid/Errors/RPCErrors/MethodNotFoundException.cs @@ -0,0 +1,85 @@ +/* + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this source code of library. + * If not, see . + */ + +namespace Socialvoid.Errors.RPCErrors +{ + /// + /// This exception will be raised when the method does not exist / is + /// not available. + /// Since: v0.0.0 + /// + public sealed class MethodNotFoundException : GeneralException + { + //------------------------------------------------- + #region Constant's Region + // some members here + #endregion + //------------------------------------------------- + #region static Properties Region + // some members here + #endregion + //------------------------------------------------- + #region Properties Region + /// + /// The error code + /// will be returned because the method does not exist / is + /// not available. + /// Since: v0.0.0 + /// + public override ErrorCodes ErrorCode + { + get + { + return ErrorCodes.MethodNotFound; + } + } + #endregion + //------------------------------------------------- + #region static field's Region + // some members here + #endregion + //------------------------------------------------- + #region field's Region + // some members here + #endregion + //------------------------------------------------- + #region static event field's Region + // some members here + #endregion + //------------------------------------------------- + #region event field's Region + // some members here + #endregion + //------------------------------------------------- + #region Constructor's Region + /// + /// Creates a new instance of . + /// Since: v0.0.0 + /// + internal MethodNotFoundException(string message) : base(message) + { + ; + } + #endregion + //------------------------------------------------- + #region Destructor's Region + // some members here + #endregion + //------------------------------------------------- + } +} \ No newline at end of file diff --git a/Socialvoid/Errors/RPCErrors/NoMarshaledObjectFoundException.cs b/Socialvoid/Errors/RPCErrors/NoMarshaledObjectFoundException.cs new file mode 100644 index 0000000..26911b4 --- /dev/null +++ b/Socialvoid/Errors/RPCErrors/NoMarshaledObjectFoundException.cs @@ -0,0 +1,85 @@ +/* + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this source code of library. + * If not, see . + */ + +namespace Socialvoid.Errors.RPCErrors +{ + /// + /// This exception will be raised when a request is made to a remotely + /// marshaled object that never existed or has already been disposed of. + /// Since: v0.0.0 + /// + public sealed class NoMarshaledObjectFound : GeneralException + { + //------------------------------------------------- + #region Constant's Region + // some members here + #endregion + //------------------------------------------------- + #region static Properties Region + // some members here + #endregion + //------------------------------------------------- + #region Properties Region + /// + /// The error code + /// will be returned because a request was made to a remotely marshaled object + /// that never existed or has already been disposed of. + /// Since: v0.0.0 + /// + public override ErrorCodes ErrorCode + { + get + { + return ErrorCodes.NoMarshaledObjectFound; + } + } + #endregion + //------------------------------------------------- + #region static field's Region + // some members here + #endregion + //------------------------------------------------- + #region field's Region + // some members here + #endregion + //------------------------------------------------- + #region static event field's Region + // some members here + #endregion + //------------------------------------------------- + #region event field's Region + // some members here + #endregion + //------------------------------------------------- + #region Constructor's Region + /// + /// Creates a new instance of . + /// Since: v0.0.0 + /// + internal NoMarshaledObjectFound(string message) : base(message) + { + ; + } + #endregion + //------------------------------------------------- + #region Destructor's Region + // some members here + #endregion + //------------------------------------------------- + } +} \ No newline at end of file diff --git a/Socialvoid/Errors/RPCErrors/ParseErrorException.cs b/Socialvoid/Errors/RPCErrors/ParseErrorException.cs new file mode 100644 index 0000000..994a506 --- /dev/null +++ b/Socialvoid/Errors/RPCErrors/ParseErrorException.cs @@ -0,0 +1,85 @@ +/* + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this source code of library. + * If not, see . + */ + +namespace Socialvoid.Errors.RPCErrors +{ + /// + /// This exception will be raised when invalid JSON is received by the server. + /// An error occurred on the server while parsing the JSON text. + /// Since: v0.0.0 + /// + public sealed class ParseErrorException : GeneralException + { + //------------------------------------------------- + #region Constant's Region + // some members here + #endregion + //------------------------------------------------- + #region static Properties Region + // some members here + #endregion + //------------------------------------------------- + #region Properties Region + /// + /// The error code + /// will be returned because invalid JSON was received by the server. + /// An error occurred on the server while parsing the JSON text. + /// Since: v0.0.0 + /// + public override ErrorCodes ErrorCode + { + get + { + return ErrorCodes.ParseError; + } + } + #endregion + //------------------------------------------------- + #region static field's Region + // some members here + #endregion + //------------------------------------------------- + #region field's Region + // some members here + #endregion + //------------------------------------------------- + #region static event field's Region + // some members here + #endregion + //------------------------------------------------- + #region event field's Region + // some members here + #endregion + //------------------------------------------------- + #region Constructor's Region + /// + /// Creates a new instance of . + /// Since: v0.0.0 + /// + internal ParseErrorException(string message) : base(message) + { + ; + } + #endregion + //------------------------------------------------- + #region Destructor's Region + // some members here + #endregion + //------------------------------------------------- + } +} \ No newline at end of file diff --git a/Socialvoid/Errors/RPCErrors/RequestCanceledException.cs b/Socialvoid/Errors/RPCErrors/RequestCanceledException.cs new file mode 100644 index 0000000..27485e7 --- /dev/null +++ b/Socialvoid/Errors/RPCErrors/RequestCanceledException.cs @@ -0,0 +1,85 @@ +/* + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this source code of library. + * If not, see . + */ + +namespace Socialvoid.Errors.RPCErrors +{ + /// + /// This exception will be raised when execution of the server method is + /// aborted due to a cancellation request from the client. + /// Since: v0.0.0 + /// + public sealed class RequestCanceledException : GeneralException + { + //------------------------------------------------- + #region Constant's Region + // some members here + #endregion + //------------------------------------------------- + #region static Properties Region + // some members here + #endregion + //------------------------------------------------- + #region Properties Region + /// + /// The error code + /// will be returned because execution of the server method was aborted + /// due to a cancellation request from the client. + /// Since: v0.0.0 + /// + public override ErrorCodes ErrorCode + { + get + { + return ErrorCodes.RequestCanceled; + } + } + #endregion + //------------------------------------------------- + #region static field's Region + // some members here + #endregion + //------------------------------------------------- + #region field's Region + // some members here + #endregion + //------------------------------------------------- + #region static event field's Region + // some members here + #endregion + //------------------------------------------------- + #region event field's Region + // some members here + #endregion + //------------------------------------------------- + #region Constructor's Region + /// + /// Creates a new instance of . + /// Since: v0.0.0 + /// + internal RequestCanceledException(string message) : base(message) + { + ; + } + #endregion + //------------------------------------------------- + #region Destructor's Region + // some members here + #endregion + //------------------------------------------------- + } +} \ No newline at end of file diff --git a/Socialvoid/Errors/RPCErrors/ResponseSerializationFailureException.cs b/Socialvoid/Errors/RPCErrors/ResponseSerializationFailureException.cs new file mode 100644 index 0000000..7a7734b --- /dev/null +++ b/Socialvoid/Errors/RPCErrors/ResponseSerializationFailureException.cs @@ -0,0 +1,85 @@ +/* + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this source code of library. + * If not, see . + */ + +namespace Socialvoid.Errors.RPCErrors +{ + /// + /// This exception will be raised when a response cannot not be serialized + /// as the application intended. + /// Since: v0.0.0 + /// + public sealed class ResponseSerializationFailureException : GeneralException + { + //------------------------------------------------- + #region Constant's Region + // some members here + #endregion + //------------------------------------------------- + #region static Properties Region + // some members here + #endregion + //------------------------------------------------- + #region Properties Region + /// + /// The error code + /// will be returned because a response could not be serialized + /// as the application intended. + /// Since: v0.0.0 + /// + public override ErrorCodes ErrorCode + { + get + { + return ErrorCodes.ResponseSerializationFailure; + } + } + #endregion + //------------------------------------------------- + #region static field's Region + // some members here + #endregion + //------------------------------------------------- + #region field's Region + // some members here + #endregion + //------------------------------------------------- + #region static event field's Region + // some members here + #endregion + //------------------------------------------------- + #region event field's Region + // some members here + #endregion + //------------------------------------------------- + #region Constructor's Region + /// + /// Creates a new instance of . + /// Since: v0.0.0 + /// + internal ResponseSerializationFailureException(string message) : base(message) + { + ; + } + #endregion + //------------------------------------------------- + #region Destructor's Region + // some members here + #endregion + //------------------------------------------------- + } +} \ No newline at end of file diff --git a/SocialVoid/Errors/ServerErrors/InternalServerErrorException.cs b/Socialvoid/Errors/ServerErrors/InternalServerErrorException.cs similarity index 93% rename from SocialVoid/Errors/ServerErrors/InternalServerErrorException.cs rename to Socialvoid/Errors/ServerErrors/InternalServerErrorException.cs index d5fba05..40fdc61 100644 --- a/SocialVoid/Errors/ServerErrors/InternalServerErrorException.cs +++ b/Socialvoid/Errors/ServerErrors/InternalServerErrorException.cs @@ -1,6 +1,6 @@ /* - * This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET). - * Copyright (c) 2021 SocialVoid.NET Authors. + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. * * This library is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,7 @@ * If not, see . */ -namespace SocialVoid.Errors.ServerErrors +namespace Socialvoid.Errors.ServerErrors { /// /// This exception will be raised when there is an unexpected error diff --git a/SocialVoid/Errors/ServerErrors/ServerErrors.md b/Socialvoid/Errors/ServerErrors/README.md similarity index 100% rename from SocialVoid/Errors/ServerErrors/ServerErrors.md rename to Socialvoid/Errors/ServerErrors/README.md diff --git a/SocialVoid/Errors/ValidationErrors/InvalidBiographyException.cs b/Socialvoid/Errors/ValidationErrors/InvalidBiographyException.cs similarity index 93% rename from SocialVoid/Errors/ValidationErrors/InvalidBiographyException.cs rename to Socialvoid/Errors/ValidationErrors/InvalidBiographyException.cs index 8c0b973..b40d6e9 100644 --- a/SocialVoid/Errors/ValidationErrors/InvalidBiographyException.cs +++ b/Socialvoid/Errors/ValidationErrors/InvalidBiographyException.cs @@ -1,6 +1,6 @@ /* - * This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET). - * Copyright (c) 2021 SocialVoid.NET Authors. + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. * * This library is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,7 @@ * If not, see . */ -namespace SocialVoid.Errors.ValidationErrors +namespace Socialvoid.Errors.ValidationErrors { /// /// This exception will be raised when the Biography is too long diff --git a/SocialVoid/Errors/ValidationErrors/InvalidClientNameException.cs b/Socialvoid/Errors/ValidationErrors/InvalidClientNameException.cs similarity index 93% rename from SocialVoid/Errors/ValidationErrors/InvalidClientNameException.cs rename to Socialvoid/Errors/ValidationErrors/InvalidClientNameException.cs index e6e5e41..79e4ed6 100644 --- a/SocialVoid/Errors/ValidationErrors/InvalidClientNameException.cs +++ b/Socialvoid/Errors/ValidationErrors/InvalidClientNameException.cs @@ -1,6 +1,6 @@ /* - * This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET). - * Copyright (c) 2021 SocialVoid.NET Authors. + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. * * This library is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,7 @@ * If not, see . */ -namespace SocialVoid.Errors.ValidationErrors +namespace Socialvoid.Errors.ValidationErrors { /// /// This exception will be raised when the client name contains invalid diff --git a/SocialVoid/Errors/ValidationErrors/InvalidClientPrivateHashException.cs b/Socialvoid/Errors/ValidationErrors/InvalidClientPrivateHashException.cs similarity index 93% rename from SocialVoid/Errors/ValidationErrors/InvalidClientPrivateHashException.cs rename to Socialvoid/Errors/ValidationErrors/InvalidClientPrivateHashException.cs index 3381075..52e2d59 100644 --- a/SocialVoid/Errors/ValidationErrors/InvalidClientPrivateHashException.cs +++ b/Socialvoid/Errors/ValidationErrors/InvalidClientPrivateHashException.cs @@ -1,6 +1,6 @@ /* - * This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET). - * Copyright (c) 2021 SocialVoid.NET Authors. + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. * * This library is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,7 @@ * If not, see . */ -namespace SocialVoid.Errors.ValidationErrors +namespace Socialvoid.Errors.ValidationErrors { /// /// This exception will be raised when the client's private hash is invalid diff --git a/SocialVoid/Errors/ValidationErrors/InvalidClientPublicHashException.cs b/Socialvoid/Errors/ValidationErrors/InvalidClientPublicHashException.cs similarity index 93% rename from SocialVoid/Errors/ValidationErrors/InvalidClientPublicHashException.cs rename to Socialvoid/Errors/ValidationErrors/InvalidClientPublicHashException.cs index 5ec78d2..dd2326f 100644 --- a/SocialVoid/Errors/ValidationErrors/InvalidClientPublicHashException.cs +++ b/Socialvoid/Errors/ValidationErrors/InvalidClientPublicHashException.cs @@ -1,6 +1,6 @@ /* - * This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET). - * Copyright (c) 2021 SocialVoid.NET Authors. + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. * * This library is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,7 @@ * If not, see . */ -namespace SocialVoid.Errors.ValidationErrors +namespace Socialvoid.Errors.ValidationErrors { /// /// This exception will be raised when the client's public hash is invalid diff --git a/SocialVoid/Errors/ValidationErrors/InvalidFirstNameException.cs b/Socialvoid/Errors/ValidationErrors/InvalidFirstNameException.cs similarity index 93% rename from SocialVoid/Errors/ValidationErrors/InvalidFirstNameException.cs rename to Socialvoid/Errors/ValidationErrors/InvalidFirstNameException.cs index 083b519..833d054 100644 --- a/SocialVoid/Errors/ValidationErrors/InvalidFirstNameException.cs +++ b/Socialvoid/Errors/ValidationErrors/InvalidFirstNameException.cs @@ -1,6 +1,6 @@ /* - * This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET). - * Copyright (c) 2021 SocialVoid.NET Authors. + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. * * This library is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,7 @@ * If not, see . */ -namespace SocialVoid.Errors.ValidationErrors +namespace Socialvoid.Errors.ValidationErrors { /// /// This exception will be raised when the First Name provided contains diff --git a/SocialVoid/Errors/ValidationErrors/InvalidLastNameException.cs b/Socialvoid/Errors/ValidationErrors/InvalidLastNameException.cs similarity index 93% rename from SocialVoid/Errors/ValidationErrors/InvalidLastNameException.cs rename to Socialvoid/Errors/ValidationErrors/InvalidLastNameException.cs index 2004e47..4074998 100644 --- a/SocialVoid/Errors/ValidationErrors/InvalidLastNameException.cs +++ b/Socialvoid/Errors/ValidationErrors/InvalidLastNameException.cs @@ -1,6 +1,6 @@ /* - * This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET). - * Copyright (c) 2021 SocialVoid.NET Authors. + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. * * This library is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,7 @@ * If not, see . */ -namespace SocialVoid.Errors.ValidationErrors +namespace Socialvoid.Errors.ValidationErrors { /// /// This exception will be raised when the Last Name provided contains diff --git a/SocialVoid/Errors/ValidationErrors/InvalidPasswordException.cs b/Socialvoid/Errors/ValidationErrors/InvalidPasswordException.cs similarity index 93% rename from SocialVoid/Errors/ValidationErrors/InvalidPasswordException.cs rename to Socialvoid/Errors/ValidationErrors/InvalidPasswordException.cs index 02ef8b7..8228b08 100644 --- a/SocialVoid/Errors/ValidationErrors/InvalidPasswordException.cs +++ b/Socialvoid/Errors/ValidationErrors/InvalidPasswordException.cs @@ -1,6 +1,6 @@ /* - * This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET). - * Copyright (c) 2021 SocialVoid.NET Authors. + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. * * This library is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,7 @@ * If not, see . */ -namespace SocialVoid.Errors.ValidationErrors +namespace Socialvoid.Errors.ValidationErrors { /// /// This exception will be raised when the given password is invalid and/or diff --git a/SocialVoid/Errors/ValidationErrors/InvalidPeerInputException.cs b/Socialvoid/Errors/ValidationErrors/InvalidPeerInputException.cs similarity index 93% rename from SocialVoid/Errors/ValidationErrors/InvalidPeerInputException.cs rename to Socialvoid/Errors/ValidationErrors/InvalidPeerInputException.cs index 10a4948..9324f1d 100644 --- a/SocialVoid/Errors/ValidationErrors/InvalidPeerInputException.cs +++ b/Socialvoid/Errors/ValidationErrors/InvalidPeerInputException.cs @@ -1,6 +1,6 @@ /* - * This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET). - * Copyright (c) 2021 SocialVoid.NET Authors. + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. * * This library is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,7 @@ * If not, see . */ -namespace SocialVoid.Errors.ValidationErrors +namespace Socialvoid.Errors.ValidationErrors { /// /// This exception will be raised when the client provide an invalid diff --git a/SocialVoid/Errors/ValidationErrors/InvalidPlatformException.cs b/Socialvoid/Errors/ValidationErrors/InvalidPlatformException.cs similarity index 93% rename from SocialVoid/Errors/ValidationErrors/InvalidPlatformException.cs rename to Socialvoid/Errors/ValidationErrors/InvalidPlatformException.cs index 819851b..8332162 100644 --- a/SocialVoid/Errors/ValidationErrors/InvalidPlatformException.cs +++ b/Socialvoid/Errors/ValidationErrors/InvalidPlatformException.cs @@ -1,6 +1,6 @@ /* - * This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET). - * Copyright (c) 2021 SocialVoid.NET Authors. + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. * * This library is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,7 @@ * If not, see . */ -namespace SocialVoid.Errors.ValidationErrors +namespace Socialvoid.Errors.ValidationErrors { /// /// This exception will be raised when the platform name contains invalid diff --git a/SocialVoid/Errors/ValidationErrors/InvalidPostTextException.cs b/Socialvoid/Errors/ValidationErrors/InvalidPostTextException.cs similarity index 93% rename from SocialVoid/Errors/ValidationErrors/InvalidPostTextException.cs rename to Socialvoid/Errors/ValidationErrors/InvalidPostTextException.cs index 21656b8..9ddf005 100644 --- a/SocialVoid/Errors/ValidationErrors/InvalidPostTextException.cs +++ b/Socialvoid/Errors/ValidationErrors/InvalidPostTextException.cs @@ -1,6 +1,6 @@ /* - * This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET). - * Copyright (c) 2021 SocialVoid.NET Authors. + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. * * This library is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,7 @@ * If not, see . */ -namespace SocialVoid.Errors.ValidationErrors +namespace Socialvoid.Errors.ValidationErrors { /// /// This exception will be raised when the post contains invalid diff --git a/SocialVoid/Errors/ValidationErrors/InvalidSessionIdentificationException.cs b/Socialvoid/Errors/ValidationErrors/InvalidSessionIdentificationException.cs similarity index 93% rename from SocialVoid/Errors/ValidationErrors/InvalidSessionIdentificationException.cs rename to Socialvoid/Errors/ValidationErrors/InvalidSessionIdentificationException.cs index 3109edc..2c0f1ed 100644 --- a/SocialVoid/Errors/ValidationErrors/InvalidSessionIdentificationException.cs +++ b/Socialvoid/Errors/ValidationErrors/InvalidSessionIdentificationException.cs @@ -1,6 +1,6 @@ /* - * This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET). - * Copyright (c) 2021 SocialVoid.NET Authors. + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. * * This library is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,7 @@ * If not, see . */ -namespace SocialVoid.Errors.ValidationErrors +namespace Socialvoid.Errors.ValidationErrors { /// /// This exception will be raised when the session identification diff --git a/SocialVoid/Errors/ValidationErrors/InvalidUsernameException.cs b/Socialvoid/Errors/ValidationErrors/InvalidUsernameException.cs similarity index 93% rename from SocialVoid/Errors/ValidationErrors/InvalidUsernameException.cs rename to Socialvoid/Errors/ValidationErrors/InvalidUsernameException.cs index 054568c..ee8e928 100644 --- a/SocialVoid/Errors/ValidationErrors/InvalidUsernameException.cs +++ b/Socialvoid/Errors/ValidationErrors/InvalidUsernameException.cs @@ -1,6 +1,6 @@ /* - * This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET). - * Copyright (c) 2021 SocialVoid.NET Authors. + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. * * This library is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,7 @@ * If not, see . */ -namespace SocialVoid.Errors.ValidationErrors +namespace Socialvoid.Errors.ValidationErrors { /// /// This exception will be raised when the given username is invalid diff --git a/SocialVoid/Errors/ValidationErrors/InvalidVersionException.cs b/Socialvoid/Errors/ValidationErrors/InvalidVersionException.cs similarity index 93% rename from SocialVoid/Errors/ValidationErrors/InvalidVersionException.cs rename to Socialvoid/Errors/ValidationErrors/InvalidVersionException.cs index 53f80c2..d2480e2 100644 --- a/SocialVoid/Errors/ValidationErrors/InvalidVersionException.cs +++ b/Socialvoid/Errors/ValidationErrors/InvalidVersionException.cs @@ -1,6 +1,6 @@ /* - * This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET). - * Copyright (c) 2021 SocialVoid.NET Authors. + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. * * This library is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,7 @@ * If not, see . */ -namespace SocialVoid.Errors.ValidationErrors +namespace Socialvoid.Errors.ValidationErrors { /// /// This exception will be raised when the given username is invalid diff --git a/SocialVoid/Errors/ValidationErrors/README.md b/Socialvoid/Errors/ValidationErrors/README.md similarity index 100% rename from SocialVoid/Errors/ValidationErrors/README.md rename to Socialvoid/Errors/ValidationErrors/README.md diff --git a/SocialVoid/Errors/ValidationErrors/UsernameAlreadyExistsException.cs b/Socialvoid/Errors/ValidationErrors/UsernameAlreadyExistsException.cs similarity index 93% rename from SocialVoid/Errors/ValidationErrors/UsernameAlreadyExistsException.cs rename to Socialvoid/Errors/ValidationErrors/UsernameAlreadyExistsException.cs index faba28e..e635dc7 100644 --- a/SocialVoid/Errors/ValidationErrors/UsernameAlreadyExistsException.cs +++ b/Socialvoid/Errors/ValidationErrors/UsernameAlreadyExistsException.cs @@ -1,6 +1,6 @@ /* - * This file is part of SocialVoid.NET Project (https://github.com/Intellivoid/SocialVoid.NET). - * Copyright (c) 2021 SocialVoid.NET Authors. + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. * * This library is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,7 @@ * If not, see . */ -namespace SocialVoid.Errors.ValidationErrors +namespace Socialvoid.Errors.ValidationErrors { /// /// This exception will be raised when the given username is invalid diff --git a/SocialVoid/Icon.ico b/Socialvoid/Icon.ico similarity index 100% rename from SocialVoid/Icon.ico rename to Socialvoid/Icon.ico diff --git a/SocialVoid/Icon.png b/Socialvoid/Icon.png similarity index 100% rename from SocialVoid/Icon.png rename to Socialvoid/Icon.png diff --git a/Socialvoid/JObjects/JArgs.cs b/Socialvoid/JObjects/JArgs.cs new file mode 100644 index 0000000..a02e789 --- /dev/null +++ b/Socialvoid/JObjects/JArgs.cs @@ -0,0 +1,81 @@ +using System; +using System.Text.Json.Serialization; +using System.Collections.Generic; + +namespace Socialvoid.JObjects +{ + /// + /// A simple object. + /// since: v0.0.0 + /// + [Serializable] + public class JArgs: Dictionary + { + //------------------------------------------------- + #region Constant's Region + // some members here + #endregion + //------------------------------------------------- + #region static Properties Region + // some members here + #endregion + //------------------------------------------------- + #region Properties Region + #endregion + //------------------------------------------------- + #region static field's Region + // some members here + #endregion + //------------------------------------------------- + #region field's Region + // some members here + #endregion + //------------------------------------------------- + #region static event field's Region + // some members here + #endregion + //------------------------------------------------- + #region event field's Region + // some members here + #endregion + //------------------------------------------------- + #region Constructor's Region + #endregion + //------------------------------------------------- + #region Destructor's Region + // some members here + #endregion + //------------------------------------------------- + #region Initialize Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region Graphical Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region event Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region overrided Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region ordinary Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region Get Method's Region + + #endregion + //------------------------------------------------- + #region Set Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region static Method's Region + #endregion + //------------------------------------------------- + } +} \ No newline at end of file diff --git a/Socialvoid/JObjects/JError.cs b/Socialvoid/JObjects/JError.cs new file mode 100644 index 0000000..636490d --- /dev/null +++ b/Socialvoid/JObjects/JError.cs @@ -0,0 +1,94 @@ +using System; +using System.Text.Json.Serialization; + +namespace Socialvoid.JObjects +{ + /// + /// A object which contains basic information + /// about an error returned by the server. + /// since: v0.0.0 + /// + [Serializable] + public sealed class JError + { + //------------------------------------------------- + #region Constant's Region + // some members here + #endregion + //------------------------------------------------- + #region static Properties Region + // some members here + #endregion + //------------------------------------------------- + #region Properties Region + /// + /// The response error code. + /// since: v0.0.0 + /// + [JsonPropertyName("code")] + public int Code { get; set; } + /// + /// The error message. + /// since: v0.0.0 + /// + [JsonPropertyName("message")] + public string Message { get; set; } + + #endregion + //------------------------------------------------- + #region static field's Region + // some members here + #endregion + //------------------------------------------------- + #region field's Region + // some members here + #endregion + //------------------------------------------------- + #region static event field's Region + // some members here + #endregion + //------------------------------------------------- + #region event field's Region + // some members here + #endregion + //------------------------------------------------- + #region Constructor's Region + #endregion + //------------------------------------------------- + #region Destructor's Region + // some members here + #endregion + //------------------------------------------------- + #region Initialize Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region Graphical Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region event Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region overrided Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region ordinary Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region Get Method's Region + + #endregion + //------------------------------------------------- + #region Set Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region static Method's Region + #endregion + //------------------------------------------------- + } +} \ No newline at end of file diff --git a/Socialvoid/JObjects/JRequest.cs b/Socialvoid/JObjects/JRequest.cs new file mode 100644 index 0000000..105c58a --- /dev/null +++ b/Socialvoid/JObjects/JRequest.cs @@ -0,0 +1,122 @@ +using System; +using System.Text.Json.Serialization; +using System.Text.Json; + +namespace Socialvoid.JObjects +{ + /// + /// A object which contains basic information + /// about an error returned by the server. + /// since: v0.0.0 + /// + [Serializable] + public sealed class JRequest + { + //------------------------------------------------- + #region Constant's Region + // some members here + #endregion + //------------------------------------------------- + #region static Properties Region + // some members here + #endregion + //------------------------------------------------- + #region Properties Region + /// + /// The JSON-RPC version. Should be equal to "2.0". + /// since: v0.0.0 + /// + [JsonPropertyName("jsonrpc")] + public string JsonRPC { get; set; } = "2.0"; + /// + /// The error message. + /// since: v0.0.0 + /// + [JsonPropertyName("method")] + public string Method { get; set; } + /// + /// The error message. + /// since: v0.0.0 + /// + [JsonPropertyName("id")] + public long ID { get; set; } + /// + /// The error message. + /// since: v0.0.0 + /// + [JsonPropertyName("params")] + public JArgs Arguments { get; set; } + + + #endregion + //------------------------------------------------- + #region static field's Region + // some members here + #endregion + //------------------------------------------------- + #region field's Region + // some members here + #endregion + //------------------------------------------------- + #region static event field's Region + // some members here + #endregion + //------------------------------------------------- + #region event field's Region + // some members here + #endregion + //------------------------------------------------- + #region Constructor's Region + #endregion + //------------------------------------------------- + #region Destructor's Region + // some members here + #endregion + //------------------------------------------------- + #region Initialize Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region Graphical Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region event Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region overrided Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region ordinary Method's Region + /// + /// Changes the ID property of this value to DateTime.Now.Ticks. + /// since: v0.0.0 + /// + public void ChangeID() + { + ID = DateTime.Now.Ticks; + } + #endregion + //------------------------------------------------- + #region Get Method's Region + /// + /// Serializes this request as a string. + /// since: v0.0.0 + /// + public string Serialize() + { + return JsonSerializer.Serialize(this); + } + #endregion + //------------------------------------------------- + #region Set Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region static Method's Region + #endregion + //------------------------------------------------- + } +} \ No newline at end of file diff --git a/Socialvoid/JObjects/JResponse.cs b/Socialvoid/JObjects/JResponse.cs new file mode 100644 index 0000000..2a8d82f --- /dev/null +++ b/Socialvoid/JObjects/JResponse.cs @@ -0,0 +1,145 @@ +using System; +using System.Text.Json.Serialization; +using Socialvoid.Errors; +using System.Text.Json; + +namespace Socialvoid.JObjects +{ + /// + /// A with a specified result type. + /// since: v0.0.0 + /// + [Serializable] + public sealed class JResponse where T: class + { + //------------------------------------------------- + #region Constant's Region + // some members here + #endregion + //------------------------------------------------- + #region static Properties Region + // some members here + #endregion + //------------------------------------------------- + #region Properties Region + /// + /// The Json-rpc version. + /// since: v0.0.0 + /// + [JsonPropertyName("jsonrpc")] + public string RPCVersion { get; set; } + + /// + /// The Json-rpc request id. + /// since: v0.0.0 + /// + [JsonPropertyName("id")] + public long ID { get; set; } + /// + /// The results. + /// since: v0.0.0 + /// + [JsonPropertyName("result")] + public T Result { get; set; } + /// + /// The results. + /// since: v0.0.0 + /// + [JsonPropertyName("error")] + public JError Error { get; set; } + #endregion + //------------------------------------------------- + #region static field's Region + // some members here + #endregion + //------------------------------------------------- + #region field's Region + // some members here + #endregion + //------------------------------------------------- + #region static event field's Region + // some members here + #endregion + //------------------------------------------------- + #region event field's Region + // some members here + #endregion + //------------------------------------------------- + #region Constructor's Region + #endregion + //------------------------------------------------- + #region Destructor's Region + // some members here + #endregion + //------------------------------------------------- + #region Initialize Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region Graphical Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region event Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region overrided Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region ordinary Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region Get Method's Region + /// + /// Checks if the current response has error or not. + /// since: v0.0.0 + /// + public bool HasError() + { + return Error != null; + } + /// + /// Will convert the current property of this value + /// to a . + /// since: v0.0.0 + /// + /// + /// returns a if and only if the + /// property is not null; otherwise returns null. + /// + public GeneralException GetException() + { + if (!HasError()) + { + return null; + } + + + return GeneralException.GetException(Error.Message, + (ErrorCodes)Error.Code); + } + #endregion + //------------------------------------------------- + #region Set Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region static Method's Region + /// + /// Will convert a json string to a . + /// since: v0.0.0 + /// + /// + /// returns a value. + /// + public static JResponse Deserialize(string text) + { + return JsonSerializer.Deserialize>(text); + } + #endregion + //------------------------------------------------- + } +} \ No newline at end of file diff --git a/Socialvoid/Security/Otp/Base32Encoding.cs b/Socialvoid/Security/Otp/Base32Encoding.cs new file mode 100644 index 0000000..a807650 --- /dev/null +++ b/Socialvoid/Security/Otp/Base32Encoding.cs @@ -0,0 +1,184 @@ +/* + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this source code of library. + * If not, see . + */ + +/* + * Credits to Devin Martin and the original OtpSharp library: + * https://github.com/kspearrin/Otp.NET + */ +/* + * Credits to "Shane" from SO answer here: + * http://stackoverflow.com/a/7135008/1090359 + */ + +using System; + +namespace Socialvoid.Security.Otp +{ + /// + /// Base32 encoding/decoding helper class. + /// since: v0.0.0 + /// + public static class Base32Encoding + { + //------------------------------------------------- + #region static Method's Region + /// + /// Converts a string to a byte array using the specified encoding. + /// since: v0.0.0 + /// + /// + /// + public static byte[] ToBytes(string input) + { + if (string.IsNullOrEmpty(input)) + { + throw new ArgumentNullException("input"); + } + + input = input.TrimEnd('='); //remove padding characters + int byteCount = input.Length * 5 / 8; //this must be TRUNCATED + byte[] returnArray = new byte[byteCount]; + + byte curByte = 0, bitsRemaining = 8; + int mask = 0, arrayIndex = 0; + + foreach(char c in input) + { + int cValue = CharToValue(c); + + if (bitsRemaining > 5) + { + mask = cValue << (bitsRemaining - 5); + curByte = (byte)(curByte | mask); + bitsRemaining -= 5; + } + else + { + mask = cValue >> (5 - bitsRemaining); + curByte = (byte)(curByte | mask); + returnArray[arrayIndex++] = curByte; + curByte = (byte)(cValue << (3 + bitsRemaining)); + bitsRemaining += 3; + } + } + + // in the case we didn't end with a full byte + if (arrayIndex != byteCount) + { + returnArray[arrayIndex] = curByte; + } + + return returnArray; + } + /// + /// Converts an array of byte to a Base32-encoded string. + /// since: v0.0.0 + /// + /// + /// + public static string ToString(byte[] input) + { + if (input == null || input.Length == 0) + { + throw new ArgumentNullException("input"); + } + + int charCount = (int)Math.Ceiling(input.Length / 5d) * 8; + char[] returnArray = new char[charCount]; + + byte nextChar = 0, bitsRemaining = 5; + int arrayIndex = 0; + + foreach(byte b in input) + { + nextChar = (byte)(nextChar | (b >> (8 - bitsRemaining))); + returnArray[arrayIndex++] = ValueToChar(nextChar); + + if (bitsRemaining < 4) + { + nextChar = (byte)((b >> (3 - bitsRemaining)) & 31); + returnArray[arrayIndex++] = ValueToChar(nextChar); + bitsRemaining += 5; + } + + bitsRemaining -= 3; + nextChar = (byte)((b << bitsRemaining) & 31); + } + + // in the case we didn't end with a full char + if (arrayIndex != charCount) + { + returnArray[arrayIndex++] = ValueToChar(nextChar); + while(arrayIndex != charCount) returnArray[arrayIndex++] = '='; //padding + } + + return new string(returnArray); + } + /// + /// Converts a valid base32 character to it's corresponding value. + /// since: v0.0.0 + /// + /// + private static int CharToValue(char c) + { + // 65 - 90 == uppercase letters + if (c < 91 && c > 64) + { + return c - 65; + } + + // 50 - 55 == numbers 2-7 + if (c < 56 && c > 49) + { + return c - 24; + } + + // 97 - 122 == lowercase letters + if (c < 123 && c > 96) + { + return c - 97; + } + + // isn't in any of these chars range? + throw new ArgumentException( + "Character is not a valid Base32 character.", + nameof(c)); + } + /// + /// Converts a valid base32 byte value to its corresponding char. + /// since: v0.0.0 + /// + /// + private static char ValueToChar(byte b) + { + if (b < 26) + { + return (char)(b + 65); + } + + if (b < 32) + { + return (char)(b + 24); + } + + throw new ArgumentException("Byte is not a Base32 value", nameof(b)); + } + #endregion + //------------------------------------------------- + } +} diff --git a/Socialvoid/Security/Otp/Hotp.cs b/Socialvoid/Security/Otp/Hotp.cs new file mode 100644 index 0000000..31200ea --- /dev/null +++ b/Socialvoid/Security/Otp/Hotp.cs @@ -0,0 +1,153 @@ +/* + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this source code of library. + * If not, see . + */ + +/* + * Credits to Devin Martin and the original OtpSharp library: + * https://github.com/kspearrin/Otp.NET + */ + +using System; + +namespace Socialvoid.Security.Otp +{ + /// + /// Calculate HMAC-Based One-Time-Passwords (HOTP) from a secret key. + /// since: v0.0.0 + /// + /// + /// The specifications for the methods of this class can be found in RFC 4226: + /// http://tools.ietf.org/html/rfc4226 + /// + public sealed class Hotp : Otp + { + //------------------------------------------------- + #region field's Region + /// + /// The HOTP size. + /// since: v0.0.0 + /// + private readonly int _hotpSize; + #endregion + //------------------------------------------------- + #region Constructor's Region + /// + /// Creates an HOTP instance. + /// since: v0.0.0 + /// + /// + /// The secret key to use in HOTP calculations. + /// + /// + /// The hash mode to use. + /// + /// The number of digits that the returning HOTP should have. The default is 6. + public Hotp(byte[] secretKey, OtpHashMode mode = OtpHashMode.Sha1, int hotpSize = 6) + : base(secretKey, mode) + { + if (hotpSize < 6 || hotpSize > 8) + { + throw new ArgumentOutOfRangeException(nameof(hotpSize), + "The hotpSize must be between 6 and 8"); + } + + _hotpSize = hotpSize; + } + /// + /// Create a HOTP instance. + /// since: v0.0.0 + /// + /// + /// The key to use in HOTP calculations. + /// + /// + /// The hash mode to use. + /// + /// + /// The number of digits that the returning HOTP should have. + /// The default value is 6. + /// + public Hotp(IKeyProvider key, + OtpHashMode mode = OtpHashMode.Sha1, + int hotpSize = 6) + : base(key, mode) + { + + if (hotpSize < 6 || hotpSize > 8) + { + throw new ArgumentOutOfRangeException(nameof(hotpSize), + "The hotpSize must be between 6 and 8"); + } + + _hotpSize = hotpSize; + } + #endregion + //------------------------------------------------- + #region overrided Method's Region + /// + /// Takes a time step and computes a HOTP code. + /// since: v0.0.0 + /// + /// + /// the counter. This is the number of time steps that have passed. + /// + /// + /// The hash mode to use. + /// + /// + /// HOTP calculated code. + /// + protected override string Compute(long counter, OtpHashMode mode) + { + var data = KeyUtilities.GetBigEndianBytes(counter); + var otp = this.CalculateOtp(data, mode); + return Digits(otp, _hotpSize); + } + #endregion + //------------------------------------------------- + #region Get Method's Region + /// + /// Takes a counter and then computes a HOTP value. + /// since: v0.0.0 + /// + /// + /// The timestamp to use for the HOTP calculation. + /// + /// a HOTP value + public string ComputeHOTP(long counter) + { + return this.Compute(counter, _hashMode); + } + /// + /// Verify a value that has been provided with the calculated value. + /// since: v0.0.0 + /// + /// the trial HOTP value. + /// + /// + /// The counter value to verify + /// + /// + /// true if there is a match; otherwise false. + /// + public bool VerifyHotp(string hotp, long counter) => + hotp == ComputeHOTP(counter); + + #endregion + //------------------------------------------------- + } +} diff --git a/Socialvoid/Security/Otp/IKeyProvider.cs b/Socialvoid/Security/Otp/IKeyProvider.cs new file mode 100644 index 0000000..89c580c --- /dev/null +++ b/Socialvoid/Security/Otp/IKeyProvider.cs @@ -0,0 +1,57 @@ +/* + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this source code of library. + * If not, see . + */ + +/* + * Credits to Devin Martin and the original OtpSharp library: + * https://github.com/kspearrin/Otp.NET + */ + +namespace Socialvoid.Security.Otp +{ + /// + /// Interface used to interact with a key. + /// since: v0.0.0 + /// + public interface IKeyProvider + { + //------------------------------------------------- + #region Get Method's Region + /// + /// Uses the key to get an HMAC using the specified algorithm and data. + /// since: v0.0.0 + /// + /// + /// This is a much better API than the previous API which would briefly + /// expose the key for all derived types. + /// + /// Now a derived type could be bound to an HSM/smart card/etc if + /// required and a lot of the security limitations of in app/memory + /// exposure of the key can be eliminated. + /// + /// + /// The HMAC algorithm to use. + /// + /// + /// The data used to compute the HMAC. + /// + /// HMAC of the key and data + byte[] ComputeHmac(OtpHashMode mode, byte[] data); + #endregion + //------------------------------------------------- + } +} diff --git a/Socialvoid/Security/Otp/InMemoryKey.cs b/Socialvoid/Security/Otp/InMemoryKey.cs new file mode 100644 index 0000000..81a62ce --- /dev/null +++ b/Socialvoid/Security/Otp/InMemoryKey.cs @@ -0,0 +1,169 @@ +/* + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this source code of library. + * If not, see . + */ + +/* + * Credits to Devin Martin and the original OtpSharp library: + * https://github.com/kspearrin/Otp.NET + */ + +using System; +using System.Security.Cryptography; + +namespace Socialvoid.Security.Otp +{ + /// + /// Represents a key in memory. + /// since: v0.0.0 + /// + /// + /// This will attempt to use the Windows data protection api to + /// encrypt the key in memory. + /// However, this type favors working over memory protection. + /// This is an attempt to minimize exposure in memory, nothing more. + /// This protection is flawed in many ways and is limited to Windows. + /// + /// In order to use the key to compute an hmac it must be temporarily + /// decrypted, used, then re-encrypted. + /// This does expose the key in memory for a time. + /// If a memory dump occurs in this time the plaintext key will be part + /// of it. Furthermore, there are potentially artifacts from the hmac + /// computation, GC compaction, or any number of other leaks even after + /// the key is re-encrypted. + /// + /// This type favors working over memory protection. If the particular + /// platform isn't supported then, unless forced by modifying the + /// IsPlatformSupported method, it will just store the key in a standard + /// byte array. + /// + public class InMemoryKey : IKeyProvider + { + //------------------------------------------------- + #region field's Region + /// + /// The key data in memory. + /// since: v0.0.0 + /// + internal readonly byte[] _KeyData; + + /// + /// The key length representing the length of the . + /// since: v0.0.0 + /// + internal readonly int _keyLength; + /// + /// Used for locking. + /// since: v0.0.0 + /// + private readonly object _stateSync = new(); + #endregion + //------------------------------------------------- + #region Constructor's Region + /// + /// Creates an instance of a key. + /// + /// Plaintext key data + public InMemoryKey(byte[] key) + { + if (key == null || key.Length == 0) + { + throw new ArgumentException("Key cannot be empty or null", + nameof(key)); + } + + + _keyLength = key.Length; + int paddedKeyLength = (int)Math.Ceiling((decimal)key.Length / (decimal)16) * 16; + _KeyData = new byte[paddedKeyLength]; + Array.Copy(key, _KeyData, key.Length); + } + #endregion + //------------------------------------------------- + #region Get Method's Region + /// + /// Gets a copy of the plaintext key. + /// since: v0.0.0 + /// + /// + /// This is internal rather than protected so that the tests can + /// use this method. + /// + /// + /// Plaintext Key + /// + internal byte[] GetCopyOfKey() + { + var plainKey = new byte[_keyLength]; + lock(_stateSync) + { + Array.Copy(_KeyData, plainKey, _keyLength); + } + return plainKey; + } + /// + /// Uses the key to get an HMAC using the specified algorithm and data. + /// since: v0.0.0 + /// + /// + /// The HMAC algorithm to use + /// + /// + /// The data used to compute the HMAC + /// + /// + /// HMAC of the key and data + /// + public byte[] ComputeHmac(OtpHashMode mode, byte[] data) + { + byte[] hashedValue = null; + using(HMAC hmac = CreateHmacHash(mode)) + { + byte[] key = this.GetCopyOfKey(); + try + { + hmac.Key = key; + hashedValue = hmac.ComputeHash(data); + } + finally + { + KeyUtilities.Destroy(key); + } + } + + return hashedValue; + } + + #endregion + //------------------------------------------------- + #region static Method's Region + /// + /// Create an HMAC object for the specified algorithm. + /// since: v0.0.0 + /// + private static HMAC CreateHmacHash(OtpHashMode otpHashMode) + { + return otpHashMode switch + { + OtpHashMode.Sha256 => new HMACSHA256(), + OtpHashMode.Sha512 => new HMACSHA512(), + _ => new HMACSHA1() //OtpHashMode.Sha1 + }; + } + #endregion + //------------------------------------------------- + } +} diff --git a/Socialvoid/Security/Otp/KeyGeneration.cs b/Socialvoid/Security/Otp/KeyGeneration.cs new file mode 100644 index 0000000..0963eab --- /dev/null +++ b/Socialvoid/Security/Otp/KeyGeneration.cs @@ -0,0 +1,143 @@ +/* + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this source code of library. + * If not, see . + */ + +/* + * Credits to Devin Martin and the original OtpSharp library: + * https://github.com/kspearrin/Otp.NET + */ + + +using System; +using System.Text; +using System.Security.Cryptography; + +namespace Socialvoid.Security.Otp +{ + /// + /// Helpers to work with key generations. + /// since: v0.0.0 + /// + public static class KeyGeneration + { + //------------------------------------------------- + #region static Method's Region + /// + /// Generates a random key in accordance with the RFC recommened + /// length for each algorithm. + /// since: v0.0.0 + /// + /// the key length + /// The generated key + public static byte[] GenerateRandomKey(int length) + { + byte[] key = new byte[length]; + using(var rnd = RandomNumberGenerator.Create()) + { + rnd.GetBytes(key); + return key; + } + } + /// + /// Generates a random key in accordance with the RFC recommened + /// length for each algorithm. + /// since: v0.0.0 + /// + /// HashMode + /// Key + public static byte[] GenerateRandomKey(OtpHashMode mode = OtpHashMode.Sha1) => + GenerateRandomKey(LengthForMode(mode)); + /// + /// Uses the procedure defined in RFC 4226 section 7.5 to derive a key + /// from the master key. + /// since: v0.0.0 + /// + /// + /// The master key from which to derive a device specific key. + /// + /// + /// The public identifier that is unique to the authenticating device. + /// + /// + /// The hash mode to use. This will determine the resulting key lenght. + /// The default value is sha-1 (as per the RFC) which is 20 bytes + /// + /// Derived key + public static byte[] DeriveKeyFromMaster(IKeyProvider masterKey, + byte[] publicIdentifier, OtpHashMode mode = OtpHashMode.Sha1) + { + if(masterKey == null) + { + throw new ArgumentNullException(nameof(masterKey), + "The master key cannot be null"); + } + return masterKey.ComputeHmac(mode, publicIdentifier); + } + /// + /// Uses the procedure defined in RFC 4226 section 7.5 to derive a key + /// from the master key. + /// + /// The master key from which to derive a device specific key + /// A serial number that is unique to the authenticating device + /// The hash mode to use. This will determine the resulting key lenght. The default is sha-1 (as per the RFC) which is 20 bytes + /// Derived key + public static byte[] DeriveKeyFromMaster(IKeyProvider masterKey, + int serialNumber, + OtpHashMode mode = OtpHashMode.Sha1) => + DeriveKeyFromMaster(masterKey, + KeyUtilities.GetBigEndianBytes(serialNumber), mode); + + internal static HashAlgorithm GetHashAlgorithmForMode(OtpHashMode mode) + { + switch(mode) + { + case OtpHashMode.Sha256: + return SHA256.Create(); + case OtpHashMode.Sha512: + return SHA512.Create(); + default: //case OtpHashMode.Sha1: + return SHA1.Create(); + } + } + + internal static int LengthForMode(OtpHashMode mode) + { + switch(mode) + { + case OtpHashMode.Sha256: + return 32; + case OtpHashMode.Sha512: + return 64; + default: //case OtpHashMode.Sha1: + return 20; + } + } + internal static string GetSha1(string value) + { + var data = Encoding.ASCII.GetBytes(value); + var hashData = new SHA1Managed().ComputeHash(data); + var hash = string.Empty; + foreach (var b in hashData) + { + hash += b.ToString("X2"); + } + return hash; + } + #endregion + //------------------------------------------------- + } +} diff --git a/Socialvoid/Security/Otp/KeyUtilities.cs b/Socialvoid/Security/Otp/KeyUtilities.cs new file mode 100644 index 0000000..1c0f2cf --- /dev/null +++ b/Socialvoid/Security/Otp/KeyUtilities.cs @@ -0,0 +1,96 @@ +/* + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this source code of library. + * If not, see . + */ + +/* + * Credits to Devin Martin and the original OtpSharp library: + * https://github.com/kspearrin/Otp.NET + */ + + +using System; + +namespace Socialvoid.Security.Otp +{ + /// + /// Some helper methods to perform common key functions. + /// since: v0.0.0 + /// + internal static class KeyUtilities + { + //------------------------------------------------- + #region static Method's Region + /// + /// Overwrite potentially sensitive data with random junk. + /// since: v0.0.0 + /// + /// + /// Warning! + /// + /// This isn't foolproof by any means. + /// The garbage collector could have moved the actual location in memory + /// to another location during a collection cycle and left the old data + /// in place simply marking it as available. + /// We can't control this or even detect it. + /// This method is simply a good faith effort to limit the exposure of + /// sensitive data in memory as much as possible. + /// + internal static void Destroy(byte[] sensitiveData) + { + if(sensitiveData == null || sensitiveData.Length == 0) + { + // if there is no data, there is nothing to destroy; + // don't throw an exception, just return. + return; + } + + new Random().NextBytes(sensitiveData); + } + /// + /// converts a long into a big endian byte array. + /// since: v0.0.0 + /// + /// + /// RFC 4226 specifies big endian as the method for converting the counter + /// to data and then to hash. + /// + static internal byte[] GetBigEndianBytes(long input) + { + // Since .net uses little endian numbers, we need to reverse the byte order to get big endian. + var data = BitConverter.GetBytes(input); + Array.Reverse(data); + return data; + } + /// + /// converts an int into a big endian byte array. + /// since: v0.0.0 + /// + /// + /// RFC 4226 specifies big endian as the method for converting + /// the counter to data and then to hash. + /// + static internal byte[] GetBigEndianBytes(int input) + { + // Since .net uses little endian numbers, we need to reverse the byte order to get big endian. + var data = BitConverter.GetBytes(input); + Array.Reverse(data); + return data; + } + #endregion + //------------------------------------------------- + } +} diff --git a/Socialvoid/Security/Otp/Otp.cs b/Socialvoid/Security/Otp/Otp.cs new file mode 100644 index 0000000..7a1d4c6 --- /dev/null +++ b/Socialvoid/Security/Otp/Otp.cs @@ -0,0 +1,194 @@ +/* + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this source code of library. + * If not, see . + */ + +/* + * Credits to Devin Martin and the original OtpSharp library: + * https://github.com/kspearrin/Otp.NET + */ + +using System; + +namespace Socialvoid.Security.Otp +{ + /// + /// An abstract class that contains common OTP calculations. + /// since: v0.0.0 + /// + /// + /// https://tools.ietf.org/html/rfc4226 + /// + public abstract class Otp + { + //------------------------------------------------- + #region field's Region + /// + /// the secret key. + /// since: v0.0.0 + /// + protected readonly IKeyProvider _secretKey; + + /// + /// The hash mode to use. + /// since: v0.0.0 + /// + protected readonly OtpHashMode _hashMode; + #endregion + //------------------------------------------------- + #region Constructor's Region + /// + /// Constructor for the abstract class using an explicit secret key. + /// since: v0.0.0 + /// + /// + /// The secret key. + /// + /// + /// The hash mode to use. + /// + public Otp(byte[] secretKey, OtpHashMode mode) + { + if(secretKey == null || secretKey.Length == 0) + { + throw new ArgumentNullException(nameof(secretKey), + "Secret key cannot be null or empty"); + } + + // when passing a key into the constructor the caller may depend on + // the reference to the key remaining intact. + _secretKey = new InMemoryKey(secretKey); + _hashMode = mode; + } + /// + /// Constructor for the abstract class using a generic key provider. + /// since: v0.0.0 + /// + /// + /// The hash mode to use + public Otp(IKeyProvider key, OtpHashMode mode) + { + if (key == null) + { + throw new ArgumentNullException(nameof(key), "key cannot be null"); + } + + _hashMode = mode; + _secretKey = key; + } + #endregion + //------------------------------------------------- + #region Get Method's Region + /// + /// An abstract definition of a compute method. + /// Takes a counter and runs it through the derived algorithm. + /// since: v0.0.0 + /// + /// Counter or step + /// The hash mode to use + /// OTP calculated code + protected abstract string Compute(long counter, OtpHashMode mode); + /// + /// Helper method that calculates OTPs. + /// since: v0.0.0 + /// + protected internal long CalculateOtp(byte[] data, OtpHashMode mode) + { + byte[] hmacComputedHash = _secretKey.ComputeHmac(mode, data); + + // The RFC has a hard coded index 19 in this value. + // This is the same thing but also accomodates SHA256 and SHA512 + // hmacComputedHash[19] => hmacComputedHash[hmacComputedHash.Length - 1] + + int offset = hmacComputedHash[hmacComputedHash.Length - 1] & 0x0F; + return (hmacComputedHash[offset] & 0x7f) << 24 + | (hmacComputedHash[offset + 1] & 0xff) << 16 + | (hmacComputedHash[offset + 2] & 0xff) << 8 + | (hmacComputedHash[offset + 3] & 0xff) % 1000000; + } + /// + /// truncates a number down to the specified number of digits. + /// since: v0.0.0 + /// + protected internal static string Digits(long input, int digitCount) + { + var truncatedValue = ((int)input % (int)Math.Pow(10, digitCount)); + return truncatedValue.ToString().PadLeft(digitCount, '0'); + } + /// + /// Verify an OTP value. + /// since: v0.0.0 + /// + /// + /// The initial step to try. + /// + /// + /// The value to verify + /// + /// + /// Output parameter that provides the step + /// where the match was found. If no match was found it will be 0 + /// + /// + /// The window to verify. + /// + /// + /// true if a match is found; otherwise false. + /// + protected bool Verify(long initialStep, string valueToVerify, out long matchedStep, VerificationWindow window) + { + window ??= new(); + foreach(var frame in window.ValidationCandidates(initialStep)) + { + var comparisonValue = this.Compute(frame, _hashMode); + if(ValuesEqual(comparisonValue, valueToVerify)) + { + matchedStep = frame; + return true; + } + } + + matchedStep = 0; + return false; + } + /// + /// Constant time comparison of two values. + /// since: v0.0.0 + /// + private bool ValuesEqual(string a, string b) + { + if (string.IsNullOrWhiteSpace(a) && string.IsNullOrWhiteSpace(b)) + { + return true; + } + + if(a.Length != b.Length) + { + return false; + } + + var result = 0; + for(int i = 0; i < a.Length; i++) + { + result |= a[i] ^ b[i]; + } + + return result == 0; + } + #endregion + //------------------------------------------------- + } +} diff --git a/Socialvoid/Security/Otp/OtpHashMode.cs b/Socialvoid/Security/Otp/OtpHashMode.cs new file mode 100644 index 0000000..82ce4e9 --- /dev/null +++ b/Socialvoid/Security/Otp/OtpHashMode.cs @@ -0,0 +1,52 @@ +/* + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this source code of library. + * If not, see . + */ + +/* + * Credits to Devin Martin and the original OtpSharp library: + * https://github.com/kspearrin/Otp.NET + */ + +namespace Socialvoid.Security.Otp +{ + /// + /// Indicates which HMAC hashing algorithm should be used. + /// since: v0.0.0 + /// + public enum OtpHashMode + { + //------------------------------------------------- + #region SHA region + /// + /// Sha1 is used as the HMAC hashing algorithm. + /// since: v0.0.0 + /// + Sha1, + /// + /// Sha256 is used as the HMAC hashing algorithm. + /// since: v0.0.0 + /// + Sha256, + /// + /// Sha512 is used as the HMAC hashing algorithm. + /// since: v0.0.0 + /// + Sha512, + #endregion + //------------------------------------------------- + } +} diff --git a/Socialvoid/Security/Otp/TimeCorrection.cs b/Socialvoid/Security/Otp/TimeCorrection.cs new file mode 100644 index 0000000..af80431 --- /dev/null +++ b/Socialvoid/Security/Otp/TimeCorrection.cs @@ -0,0 +1,144 @@ +/* + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this source code of library. + * If not, see . + */ + +/* + * Credits to Devin Martin and the original OtpSharp library: + * https://github.com/kspearrin/Otp.NET + */ + +using System; + +namespace Socialvoid.Security.Otp +{ + /// + /// Class to apply a correction factor to the system time. + /// since: v0.0.0 + /// + /// + /// In cases where the local system time is incorrect it is preferable to simply correct the system time. + /// This class is provided to handle cases where it isn't possible for the client, the server, or both, to be on the correct time. + /// + /// This library provides limited facilities to to ping NIST for a correct network time. This class can be used manually however in cases where a server's time is off + /// and the consumer of this library can't control it. In that case create an instance of this class and provide the current server time as the correct time parameter + /// + /// This class is immutable and therefore threadsafe. + /// + public class TimeCorrection + { + //------------------------------------------------- + #region Properties Region + /// + /// Applies the correction factor to the current system UTC time and + /// returns a corrected time. + /// since: v0.0.0 + /// + public DateTime CorrectedUtcNow + { + get => GetCorrectedTime(DateTime.UtcNow); + } + /// + /// The timespan that is used to calculate a corrected time. + /// since: v0.0.0 + /// + public TimeSpan CorrectionFactor + { + get => _timeCorrectionFactor; + } + #endregion + //------------------------------------------------- + #region static field's Region + /// + /// An instance that provides no correction factor. + /// since: v0.0.0 + /// + public static readonly TimeCorrection UncorrectedInstance = new(); + #endregion + //------------------------------------------------- + #region field's Region + /// + /// The timespan that is used as a correction factor. + /// since: v0.0.0 + /// + private readonly TimeSpan _timeCorrectionFactor; + #endregion + //------------------------------------------------- + #region Constructor's Region + /// + /// Constructor used solely for the static + /// field to provide an instance without a correction factor. + /// since: v0.0.0 + /// + private TimeCorrection() + { + _timeCorrectionFactor = TimeSpan.FromSeconds(0); + } + + /// + /// Creates a corrected time object by providing the known correct + /// current UTC time. + /// The current system UTC time will be used as the reference. + /// since: v0.0.0 + /// + /// + /// This overload assumes UTC. + /// If a base and reference time other than UTC are required then use the + /// other overlaod. + /// + /// The current correct UTC time + public TimeCorrection(DateTime correctUtc) + { + _timeCorrectionFactor = DateTime.UtcNow - correctUtc; + } + + /// + /// Creates a corrected time object by providing the known correct current time + /// and the current reference time that needs correction. + /// since: v0.0.0 + /// + /// + /// The current correct time. + /// + /// + /// The current reference time (time that will have the correction factor + /// applied in subsequent calls). + /// + public TimeCorrection(DateTime correctTime, DateTime referenceTime) + { + _timeCorrectionFactor = referenceTime - correctTime; + } + #endregion + //------------------------------------------------- + #region Get Method's Region + /// + /// Applies the correction factor to the reference time and returns a + /// corrected time. + /// since: v0.0.0 + /// + /// + /// The reference time. + /// + /// + /// The reference time with the correction factor applied. + /// + public DateTime GetCorrectedTime(DateTime referenceTime) => + referenceTime - _timeCorrectionFactor; + + #endregion + //------------------------------------------------- + } +} diff --git a/Socialvoid/Security/Otp/Totp.cs b/Socialvoid/Security/Otp/Totp.cs new file mode 100644 index 0000000..0614aa8 --- /dev/null +++ b/Socialvoid/Security/Otp/Totp.cs @@ -0,0 +1,326 @@ +/* + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this source code of library. + * If not, see . + */ + +/* + * Credits to Devin Martin and the original OtpSharp library: + * https://github.com/kspearrin/Otp.NET + */ + + +using System; + +namespace Socialvoid.Security.Otp +{ + /// + /// Calculate Timed-One-Time-Passwords (TOTP) from a secret key. + /// since: v0.0.0 + /// + /// + /// The specifications for the methods of this class can be found in RFC 6238: + /// http://tools.ietf.org/html/rfc6238 + /// + public sealed class Totp : Otp + { + //------------------------------------------------- + #region Constant's Region + /// + /// The number of ticks as Measured at Midnight Jan 1st 1970. + /// since: v0.0.0 + /// + internal const long unixEpochTicks = 621355968000000000L; + /// + /// A divisor for converting ticks to seconds. + /// since: v0.0.0 + /// + internal const long ticksToSeconds = 10000000L; + #endregion + //------------------------------------------------- + #region field's Region + /// + /// the step value. + /// since: v0.0.0 + /// + private readonly int _step; + /// + /// the TOTP length. + /// since: v0.0.0 + /// + private readonly int _totpSize; + /// + /// the TOTP corrected time. + /// since: v0.0.0 + /// + private readonly TimeCorrection correctedTime; + #endregion + //------------------------------------------------- + #region Constructor's Region + /// + /// Creates a TOTP instance. + /// since: v0.0.0 + /// + /// + /// The secret key to use in TOTP calculations + /// + /// + /// The time window step amount to use in calculating time windows. + /// The default is 30 as recommended in the RFC + /// + /// + /// The hash mode to use + /// + /// + /// The number of digits that the returning TOTP should have. + /// The default value of this argument is 6. + /// + /// + /// If required, a time correction can be specified to compensate of + /// an out of sync local clock. + /// + public Totp(byte[] secretKey, + int step = 30, + OtpHashMode mode = OtpHashMode.Sha1, + int totpSize = 6, + TimeCorrection timeCorrection = null) + : base(secretKey, mode) + { + + if (step < 0) + { + throw new ArgumentOutOfRangeException(nameof(step), + "Step must be greater than 0"); + } + if (totpSize < 0 || totpSize > 10) + { + throw new ArgumentOutOfRangeException(nameof(totpSize), + "TOTP size must be greater than 0 and less than 10"); + } + + _step = step; + _totpSize = totpSize; + + // we never null check the corrected time object. + // Since it's readonly, we'll ensure that it isn't null here + // and provide neatral functionality in this case. + correctedTime = timeCorrection ?? TimeCorrection.UncorrectedInstance; + } + + /// + /// Creates a TOTP instance. + /// since: v0.0.0 + /// + /// + /// The secret key to use in TOTP calculations. + /// + /// + /// The time window step amount to use in calculating time windows. + /// The default is 30 as recommended in the RFC + /// + /// + /// The hash mode to use. + /// + /// + /// The number of digits that the returning TOTP should have. + /// The default is 6. + /// + /// If required, a time correction can be specified to compensate of an + /// out of sync local clock. + public Totp(IKeyProvider key, + int step = 30, + OtpHashMode mode = OtpHashMode.Sha1, + int totpSize = 6, + TimeCorrection timeCorrection = null) + : base(key, mode) + { + if (step < 0) + { + throw new ArgumentOutOfRangeException(nameof(step), + "Step must be greater than 0"); + } + if (totpSize < 0 || totpSize > 10) + { + throw new ArgumentOutOfRangeException(nameof(totpSize), + "TOTP size must be greater than 0 and less than 10"); + } + + _step = step; + _totpSize = totpSize; + + // we never null check the corrected time object. + // Since it's readonly, we'll ensure that it isn't null here and + // provide neatral functionality in this case. + correctedTime = timeCorrection ?? TimeCorrection.UncorrectedInstance; + } + #endregion + //------------------------------------------------- + #region overrided Method's Region + /// + /// Takes a time step and computes a TOTP code. + /// since: v0.0.0 + /// + /// time step + /// The hash mode to use + /// TOTP calculated code + protected override string Compute(long counter, OtpHashMode mode) + { + var data = KeyUtilities.GetBigEndianBytes(counter); + var otp = this.CalculateOtp(data, mode); + return Digits(otp, _totpSize); + } + #endregion + //------------------------------------------------- + #region Get Method's Region + /// + /// Takes a timestamp and applies correction (if provided) and then computes + /// a TOTP value. + /// since: v0.0.0 + /// + /// The timestamp to use for the TOTP calculation + /// a TOTP value + public string ComputeTotp(DateTime timestamp) => + ComputeTotpFromSpecificTime(correctedTime.GetCorrectedTime(timestamp)); + + /// + /// Takes a timestamp and computes a TOTP value for corrected UTC now. + /// since: v0.0.0 + /// + /// + /// It will be corrected against a corrected UTC time using the provided time correction. If none was provided then simply the current UTC will be used. + /// + /// a TOTP value + public string ComputeTotp() => + ComputeTotpFromSpecificTime(this.correctedTime.CorrectedUtcNow); + + /// + /// Verify a value that has been provided with the calculated value. + /// since: v0.0.0 + /// + /// + /// It will be corrected against a corrected UTC time using the provided time correction. If none was provided then simply the current UTC will be used. + /// + /// + /// the trial TOTP value + /// + /// + /// This is an output parameter that gives that time step that was used to find a match. + /// This is useful in cases where a TOTP value should only be used once. This value is a unique identifier of the + /// time step (not the value) that can be used to prevent the same step from being used multiple times + /// + /// + /// The window of steps to verify. + /// + /// True if there is a match. + public bool VerifyTotp(string totp, + out long timeStepMatched, + VerificationWindow window = null) + { + return this.VerifyTotpForSpecificTime(correctedTime.CorrectedUtcNow, + totp, window, out timeStepMatched); + } + + /// + /// Verify a value that has been provided with the calculated value. + /// since: v0.0.0 + /// + /// + /// The timestamp to use. + /// + /// + /// The trial TOTP value. + /// + /// + /// This is an output parameter that gives that time step that was + /// used to find a match. This is usefule in cases where a TOTP value + /// should only be used once. This value is a unique identifier of the + /// time step (not the value) that can be used to prevent the same step + /// from being used multiple times. + /// + /// The window of steps to verify + /// True if there is a match. + public bool VerifyTotp(DateTime timestamp, + string totp, + out long timeStepMatched, VerificationWindow window = null) + { + return this.VerifyTotpForSpecificTime( + this.correctedTime.GetCorrectedTime(timestamp), + totp, window, out timeStepMatched); + } + + /// + /// Remaining seconds in current window based on UtcNow. + /// since: v0.0.0 + /// + /// + /// It will be corrected against a corrected UTC time using the provided time correction. If none was provided then simply the current UTC will be used. + /// + /// Number of remaining seconds + public int GetRemainingSeconds() => + RemainingSecondsForSpecificTime(correctedTime.CorrectedUtcNow); + + /// + /// Remaining seconds in current window. + /// since: v0.0.0 + /// + /// The timestamp + /// Number of remaining seconds + public int GetRemainingSeconds(DateTime timestamp) => + RemainingSecondsForSpecificTime(correctedTime.GetCorrectedTime(timestamp)); + /// + /// The Remaining seconds in the current window based on + /// the provided timestamp using value. + /// since: v0.0.0 + /// + private int RemainingSecondsForSpecificTime(DateTime timestamp) + { + return _step - + (int)(((timestamp.Ticks - unixEpochTicks) / ticksToSeconds) % _step); + } + /// + /// Verify a value that has been provided with the calculated value. + /// since: v0.0.0 + /// + private bool VerifyTotpForSpecificTime(DateTime timestamp, + string totp, VerificationWindow window, out long timeStepMatched) + { + var initialStep = CalculateTimeStepFromTimestamp(timestamp); + return this.Verify(initialStep, totp, out timeStepMatched, window); + } + + /// + /// Takes a timestamp and calculates a time step. + /// since: v0.0.0 + /// + private long CalculateTimeStepFromTimestamp(DateTime timestamp) + { + var unixTimestamp = (timestamp.Ticks - unixEpochTicks) / ticksToSeconds; + var window = unixTimestamp / (long)_step; + return window; + } + /// + /// Takes a timestamp and computes a TOTP value for corrected UTC value. + /// since: v0.0.0 + /// + private string ComputeTotpFromSpecificTime(DateTime timestamp) + { + var window = CalculateTimeStepFromTimestamp(timestamp); + return this.Compute(window, _hashMode); + } + + #endregion + //------------------------------------------------- + } +} diff --git a/Socialvoid/Security/Otp/VerificationWindow.cs b/Socialvoid/Security/Otp/VerificationWindow.cs new file mode 100644 index 0000000..9f441d8 --- /dev/null +++ b/Socialvoid/Security/Otp/VerificationWindow.cs @@ -0,0 +1,100 @@ +/* + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this source code of library. + * If not, see . + */ + +/* + * Credits to Devin Martin and the original OtpSharp library: + * https://github.com/kspearrin/Otp.NET + */ + + +using System.Collections.Generic; + +namespace Socialvoid.Security.Otp +{ + /// + /// A verification window. + /// since: v0.0.0 + /// + public sealed class VerificationWindow + { + //------------------------------------------------- + #region static field's Region + /// + /// The verification window that accomodates network delay that is + /// recommended in the RFC. + /// since: v0.0.0 + /// + public static readonly VerificationWindow RfcSpecifiedNetworkDelay = new(1, 1); + #endregion + //------------------------------------------------- + #region field's Region + /// + /// the previous value in the window. + /// since: v0.0.0 + /// + private readonly int _previous; + /// + /// the future value in the window. + /// since: v0.0.0 + /// + private readonly int _future; + #endregion + //------------------------------------------------- + #region Constructor's Region + /// + /// Creates an instance of a verification window. + /// since: v0.0.0 + /// + /// The number of previous frames to accept + /// The number of future frames to accept + public VerificationWindow(int previous = 0, int future = 0) + { + _previous = previous; + _future = future; + } + #endregion + //------------------------------------------------- + #region Get Method's Region + /// + /// Gets an enumberable of all the possible validation candidates. + /// since: v0.0.0 + /// + /// + /// The initial frame to validate. + /// + /// + /// Enumberable of all possible frames that need to be validated. + /// + public IEnumerable ValidationCandidates(long initialFrame) + { + yield return initialFrame; + for(int i = 1; i <= _previous; i++) + { + var val = initialFrame - i; + if(val < 0) + break; + yield return val; + } + + for(int i = 1; i <= _future; i++) + yield return initialFrame + i; + } + #endregion + //------------------------------------------------- + } +} diff --git a/Socialvoid/Security/SessionEstablished.cs b/Socialvoid/Security/SessionEstablished.cs new file mode 100644 index 0000000..c3b0079 --- /dev/null +++ b/Socialvoid/Security/SessionEstablished.cs @@ -0,0 +1,136 @@ +using System.Text.Json.Serialization; + +namespace Socialvoid.Security +{ + /// + /// A object contains basic information + /// about the session that the server has created for us. + /// since: v0.0.0 + /// + public sealed class SessionEstablished + { + //------------------------------------------------- + #region Constant's Region + // some members here + #endregion + //------------------------------------------------- + #region static Properties Region + // some members here + #endregion + //------------------------------------------------- + #region Properties Region + /// + /// The ID of the session obtained when establishing a session. + /// since: v0.0.0 + /// + [JsonPropertyName("id")] + public string SessionID { get; set; } + /// + /// The Public Hash of the client used when establishing the session. + /// since: v0.0.0 + /// + [JsonPropertyName("challenge")] + public string ChallengeSecret { get; set; } + #endregion + //------------------------------------------------- + #region static field's Region + // some members here + #endregion + //------------------------------------------------- + #region field's Region + // some members here + #endregion + //------------------------------------------------- + #region static event field's Region + // some members here + #endregion + //------------------------------------------------- + #region event field's Region + // some members here + #endregion + //------------------------------------------------- + #region Constructor's Region + /// + /// + /// + public SessionEstablished() + { + ;// make is private, so user use `EstablishNew` static method. + } + #endregion + //------------------------------------------------- + #region Destructor's Region + // some members here + #endregion + //------------------------------------------------- + #region Initialize Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region Graphical Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region event Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region overrided Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region ordinary Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region Get Method's Region + /// + /// This method will return the challenge secret received from the + /// server. + /// since: v0.0.0 + /// + /// + /// null if this object doesn't have any challenge secret; + /// otherwise a valid challenge secret. + /// + public string GetChallengeSecret() + { + return string.IsNullOrWhiteSpace(ChallengeSecret) ? + null : ChallengeSecret; + } + #endregion + //------------------------------------------------- + #region Set Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region static Method's Region + /// + /// Establishes a new session. + /// since: v0.0.0 + /// + /// + /// the session id returned from the server or being stored in + /// a file. + /// + /// + /// The challenge secret returned from the server. + /// it can be null. + /// please do notice that when you are going to load an already + /// existing session from a file, this parameter should remain null. + /// + /// + /// A new instance of class. + /// + public static SessionEstablished EstablishNew(string id, string challenge = null) + { + return new() + { + SessionID = id, + ChallengeSecret = challenge, + }; + } + #endregion + //------------------------------------------------- + } +} \ No newline at end of file diff --git a/Socialvoid/Security/SessionIdentification.cs b/Socialvoid/Security/SessionIdentification.cs new file mode 100644 index 0000000..60f6ca2 --- /dev/null +++ b/Socialvoid/Security/SessionIdentification.cs @@ -0,0 +1,111 @@ +using System.Text.Json.Serialization; + +namespace Socialvoid.Security +{ + /// + /// A SessionIdentification object allows the client to identify the + /// session it's using and prove that it is the owner of the session; + /// it proves as a identification effort and security effort. + /// Most methods that requires authentication or some sort of identity + /// will require you to pass on this object as a parameter under + /// `session_identification`; missing parameters or invalid security values + /// will cause the request to fail as it's validated upon request. + /// since: v0.0.0 + /// + public sealed class SessionIdentification + { + //------------------------------------------------- + #region Constant's Region + // some members here + #endregion + //------------------------------------------------- + #region static Properties Region + // some members here + #endregion + //------------------------------------------------- + #region Properties Region + /// + /// The ID of the session obtained when establishing a session. + /// since: v0.0.0 + /// + [JsonPropertyName("session_id")] + public string SessionID { get; set; } + /// + /// The Public Hash of the client used when establishing the session. + /// since: v0.0.0 + /// + [JsonPropertyName("client_public_hash")] + public string ClientPublicHash { get; set; } + /// + /// The session challenge answer revolving around the client's + /// private hash, the same client used to establish the session. + /// since: v0.0.0 + /// + [JsonPropertyName("challenge_answer")] + public string ChallengeAnswer { get; internal set; } + #endregion + //------------------------------------------------- + #region static field's Region + // some members here + #endregion + //------------------------------------------------- + #region field's Region + // some members here + #endregion + //------------------------------------------------- + #region static event field's Region + // some members here + #endregion + //------------------------------------------------- + #region event field's Region + // some members here + #endregion + //------------------------------------------------- + #region Constructor's Region + /// + /// + /// + public SessionIdentification() + { + + } + #endregion + //------------------------------------------------- + #region Destructor's Region + // some members here + #endregion + //------------------------------------------------- + #region Initialize Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region Graphical Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region event Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region overrided Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region ordinary Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region Get Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region Set Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region static Method's Region + // some methods here + #endregion + //------------------------------------------------- + } +} \ No newline at end of file diff --git a/SocialVoid/SocialVoid.csproj b/Socialvoid/Socialvoid.csproj similarity index 80% rename from SocialVoid/SocialVoid.csproj rename to Socialvoid/Socialvoid.csproj index 0970d03..bf66576 100644 --- a/SocialVoid/SocialVoid.csproj +++ b/Socialvoid/Socialvoid.csproj @@ -1,7 +1,7 @@ - SocialVoid - SocialVoid + Socialvoid + Socialvoid The official Socialvoid RPC Library written for C# en-US + - + - + diff --git a/Tests/Client/AuthenticateUser.cs b/Tests/Client/AuthenticateUser.cs new file mode 100644 index 0000000..1c9e67f --- /dev/null +++ b/Tests/Client/AuthenticateUser.cs @@ -0,0 +1,71 @@ +using System; +using Socialvoid.Errors; +using Socialvoid.Client; +using Socialvoid.Errors.ServerErrors; +using Socialvoid.Errors.NetworkErrors; +using Socialvoid.Errors.ValidationErrors; +using NUnit.Framework; + + +namespace Tests.Client +{ + [TestFixture] + public class ClientTest + { + [TestCase("test1: the given login credentials are incorrect.", 8704)] + [TestCase("test2: the given two-factor authentication code is incorrect.", 8705)] + [TestCase("test3: the user 'aliwoto' does not support this method of authentication", 8706)] + [TestCase("test4: the requested session was not found in the database on server-side.", 8707)] + public void AuthenticationErrorsTest(string message, int errorCode) + { + try + { + CreateException(message, errorCode); + } + catch (GeneralException ex) + { + Log("got exception of type", ex.GetType(), "with error code of", ex.ErrorCode); + if (ex.Message != message || (int)ex.ErrorCode != errorCode) + { + + throw; + } + } + } + + [TestCase( + "4c7148caff498d24deee6c8325f1c15773d637ed76c3a4056e00b77b2beb3097", // public hash + "866d3218b239d39c174fa2b16f54e0fa58f9c69fce8c2d941c12a47a7bc75229", // private hash + "Linux", // platform + "Test .NET RCP Client", // the name + "1.0.0.0" // version + )] + public void AuthenticateUserTest(string publicHash, string privateHash, + string platform, string name, string version) + { + var myClient = + SocialvoidClient.GetClient(publicHash, + privateHash, platform, name, version); + myClient.CreateSession(); + myClient.AuthenticateUser("aliwoto", "12345678"); + } + + + + private void CreateException(string message, int code) + { + throw GeneralException.GetException(message, (ErrorCodes)code); + } + + private void Log(params object[] objs) + { + foreach (var obj in objs) + { + Console.Write(obj); + Console.Write(" "); + } + + Console.Write("\n"); + } + } +} \ No newline at end of file diff --git a/Tests/Client/client_info.json b/Tests/Client/client_info.json new file mode 100644 index 0000000..a136956 --- /dev/null +++ b/Tests/Client/client_info.json @@ -0,0 +1,8 @@ +{ + "endpoint": "http://127.0.0.1:5001/", + "public_hash": "4c7148caff498d24deee6c8325f1c15773d637ed76c3a4056e00b77b2beb3097", + "private_hash": "866d3218b239d39c174fa2b16f54e0fa58f9c69fce8c2d941c12a47a7bc75229", + "platform": "Linux", + "name": "Test Python RCP Client", + "version": "1.0.0.0" +} \ No newline at end of file diff --git a/Tests/Errors/ErrorsTest.cs b/Tests/Errors/ErrorsTest.cs index c42e31e..94fddbc 100644 --- a/Tests/Errors/ErrorsTest.cs +++ b/Tests/Errors/ErrorsTest.cs @@ -1,8 +1,8 @@ using System; -using SocialVoid.Errors; -using SocialVoid.Errors.ServerErrors; -using SocialVoid.Errors.NetworkErrors; -using SocialVoid.Errors.ValidationErrors; +using Socialvoid.Errors; +using Socialvoid.Errors.ServerErrors; +using Socialvoid.Errors.NetworkErrors; +using Socialvoid.Errors.ValidationErrors; using NUnit.Framework; diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 0250398..bc3117f 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -1,7 +1,7 @@ @@ -76,8 +77,8 @@ - - + +