Skip to content

Commit

Permalink
Some more code documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodoufu committed Nov 11, 2018
1 parent 416f295 commit de42314
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
39 changes: 39 additions & 0 deletions NeoDataStructure/MerklePatriciaTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
using System.Linq;
using System;

/// <summary>
/// Merkle Patricia tools.
/// </summary>
public static class MerklePatriciaTools
{
private static byte[] ProcessByteArray(byte[] hexarray)
Expand Down Expand Up @@ -33,6 +36,11 @@ private static byte[] ProcessByteArray(byte[] hexarray)
return hexarray;
}

/// <summary>
/// Compact encode implementation for byte array.
/// </summary>
/// <param name="hexarray">The byte array to be encoded.</param>
/// <returns>Encoded byte array.</returns>
public static byte[] CompactEncode(this byte[] hexarray)
{
hexarray = ProcessByteArray(hexarray);
Expand All @@ -45,8 +53,18 @@ public static byte[] CompactEncode(this byte[] hexarray)
return o.ToArray();
}

/// <summary>
/// Compact encode implementation from string to byte array.
/// </summary>
/// <param name="hexarray">The string to be encoded.</param>
/// <returns>The encoded byte array.</returns>
public static byte[] CompactEncode(this string hexarray) => CompactEncode(Encoding.UTF8.GetBytes(hexarray));

/// <summary>
/// Compact encode implementation from byte array to string.
/// </summary>
/// <param name="hexarray">The byte array to be encoded.</param>
/// <returns>The string encoded.</returns>
public static string CompactEncodeString(this byte[] hexarray)
{
hexarray = ProcessByteArray(hexarray);
Expand All @@ -59,14 +77,35 @@ public static string CompactEncodeString(this byte[] hexarray)
return o.ToString();
}

/// <summary>
/// Compatc encode implementation for a string.
/// </summary>
/// <param name="hexarray">String to be encoded.</param>
/// <returns>The ecoded string.</returns>
public static string CompactEncodeString(this string hexarray) =>
CompactEncodeString(Encoding.UTF8.GetBytes(hexarray));

/// <summary>
/// Converts a byte to an hexadecimal string.
/// </summary>
/// <param name="hexchar">Byte to be converted.</param>
/// <returns>The converted string.</returns>
public static string ByteToHexString(this byte hexchar) => hexchar.ToString("x2");

/// <summary>
/// Converts a byte array to an hexadecimal string.
/// </summary>
/// <param name="hexchar">Byte array to be converted.</param>
/// <returns>The converted string.</returns>
public static string ByteToHexString(this byte[] hexchar) =>
string.Join(" ", hexchar.Select(x => x.ByteToHexString()).ToList());

/// <summary>
/// Converts a string to SHA256.
/// </summary>
/// <param name="randomString">String to be converted.</param>
/// <param name="uppercase">Use uppercase charecters.</param>
/// <returns>The converted string.</returns>
public static string Sha256(this string randomString, bool uppercase = false)
{
var crypt = new SHA256Managed();
Expand Down
3 changes: 3 additions & 0 deletions NeoDataStructure/StringTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ namespace com.github.neoresearch.NeoDataStructure
{
using System.Text;

/// <summary>
/// String help functions.
/// </summary>
public static class StringTools
{
/// <summary>
Expand Down

0 comments on commit de42314

Please sign in to comment.