Fix `JsonPropertyName` problem in `SessionIdentification` class;
Fix code style problems in `Socialvoid.Security.Otp` namespace. Signed-off-by: Aliwoto <aminnimaj@gmail.com>
This commit is contained in:
parent
fa13a7e88d
commit
a23ef86d83
|
@ -399,7 +399,6 @@ namespace Socialvoid.Client
|
|||
{
|
||||
var otp = new Totp(Encoding.UTF8.GetBytes(secret));
|
||||
return KeyGeneration.GetSha1(otp.ComputeTotp() + PrivateHash);;
|
||||
//return null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -45,7 +45,7 @@ namespace Socialvoid.Security.Otp
|
|||
/// <exception cref="ArgumentException"/>
|
||||
public static byte[] ToBytes(string input)
|
||||
{
|
||||
if(string.IsNullOrEmpty(input))
|
||||
if (string.IsNullOrEmpty(input))
|
||||
{
|
||||
throw new ArgumentNullException("input");
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ namespace Socialvoid.Security.Otp
|
|||
{
|
||||
int cValue = CharToValue(c);
|
||||
|
||||
if(bitsRemaining > 5)
|
||||
if (bitsRemaining > 5)
|
||||
{
|
||||
mask = cValue << (bitsRemaining - 5);
|
||||
curByte = (byte)(curByte | mask);
|
||||
|
@ -77,8 +77,8 @@ namespace Socialvoid.Security.Otp
|
|||
}
|
||||
}
|
||||
|
||||
//if we didn't end with a full byte
|
||||
if(arrayIndex != byteCount)
|
||||
// in the case we didn't end with a full byte
|
||||
if (arrayIndex != byteCount)
|
||||
{
|
||||
returnArray[arrayIndex] = curByte;
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ namespace Socialvoid.Security.Otp
|
|||
/// <exception cref="ArgumentException"/>
|
||||
public static string ToString(byte[] input)
|
||||
{
|
||||
if(input == null || input.Length == 0)
|
||||
if (input == null || input.Length == 0)
|
||||
{
|
||||
throw new ArgumentNullException("input");
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ namespace Socialvoid.Security.Otp
|
|||
nextChar = (byte)(nextChar | (b >> (8 - bitsRemaining)));
|
||||
returnArray[arrayIndex++] = ValueToChar(nextChar);
|
||||
|
||||
if(bitsRemaining < 4)
|
||||
if (bitsRemaining < 4)
|
||||
{
|
||||
nextChar = (byte)((b >> (3 - bitsRemaining)) & 31);
|
||||
returnArray[arrayIndex++] = ValueToChar(nextChar);
|
||||
|
@ -120,8 +120,8 @@ namespace Socialvoid.Security.Otp
|
|||
nextChar = (byte)((b << bitsRemaining) & 31);
|
||||
}
|
||||
|
||||
//if we didn't end with a full char
|
||||
if(arrayIndex != charCount)
|
||||
// in the case we didn't end with a full char
|
||||
if (arrayIndex != charCount)
|
||||
{
|
||||
returnArray[arrayIndex++] = ValueToChar(nextChar);
|
||||
while(arrayIndex != charCount) returnArray[arrayIndex++] = '='; //padding
|
||||
|
@ -137,19 +137,19 @@ namespace Socialvoid.Security.Otp
|
|||
private static int CharToValue(char c)
|
||||
{
|
||||
// 65 - 90 == uppercase letters
|
||||
if(c < 91 && c > 64)
|
||||
if (c < 91 && c > 64)
|
||||
{
|
||||
return c - 65;
|
||||
}
|
||||
|
||||
// 50 - 55 == numbers 2-7
|
||||
if(c < 56 && c > 49)
|
||||
if (c < 56 && c > 49)
|
||||
{
|
||||
return c - 24;
|
||||
}
|
||||
|
||||
// 97 - 122 == lowercase letters
|
||||
if(c < 123 && c > 96)
|
||||
if (c < 123 && c > 96)
|
||||
{
|
||||
return c - 97;
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ namespace Socialvoid.Security.Otp
|
|||
public Hotp(byte[] secretKey, OtpHashMode mode = OtpHashMode.Sha1, int hotpSize = 6)
|
||||
: base(secretKey, mode)
|
||||
{
|
||||
if(hotpSize < 6 || hotpSize > 8)
|
||||
if (hotpSize < 6 || hotpSize > 8)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(hotpSize),
|
||||
"The hotpSize must be between 6 and 8");
|
||||
|
@ -87,7 +87,7 @@ namespace Socialvoid.Security.Otp
|
|||
: base(key, mode)
|
||||
{
|
||||
|
||||
if(hotpSize < 6 || hotpSize > 8)
|
||||
if (hotpSize < 6 || hotpSize > 8)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(hotpSize),
|
||||
"The hotpSize must be between 6 and 8");
|
||||
|
|
|
@ -79,10 +79,12 @@ namespace Socialvoid.Security.Otp
|
|||
/// <param name="key">Plaintext key data</param>
|
||||
public InMemoryKey(byte[] key)
|
||||
{
|
||||
if(!(key != null))
|
||||
throw new ArgumentNullException("key");
|
||||
if(!(key.Length > 0))
|
||||
throw new ArgumentException("The key must not be empty");
|
||||
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;
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Socialvoid.Security
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -26,17 +28,20 @@ namespace Socialvoid.Security
|
|||
/// The ID of the session obtained when establishing a session.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
[JsonPropertyName("session_id")]
|
||||
public string SessionID { get; internal set; }
|
||||
/// <summary>
|
||||
/// The Public Hash of the client used when establishing the session.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
[JsonPropertyName("client_public_hash")]
|
||||
public string ClientPublicHash { get; internal set; }
|
||||
/// <summary>
|
||||
/// The session challenge answer revolving around the client's
|
||||
/// private hash, the same client used to establish the session.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
[JsonPropertyName("challenge_answer")]
|
||||
public string ChallengeAnswer { get; internal set; }
|
||||
#endregion
|
||||
//-------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue