Show / Hide Table of Contents

Struct HashDigest<T>

A value type to represent digest bytes determined by a HashAlgorithm. For more type safety, it takes a type parameter T of HashAlgorithm.

Inherited Members
ValueType.Equals(Object)
ValueType.GetHashCode()
Object.Equals(Object, Object)
Object.GetType()
Object.ReferenceEquals(Object, Object)
Namespace: Libplanet
Assembly: Libplanet.dll
Syntax
[GeneratedEquality]
public struct HashDigest<T>
    where T : HashAlgorithm
Type Parameters
Name Description
T

A HashAlgorithm which corresponds to a digest. This determines Size of a digest.

Constructors

| Improve this Doc View Source

HashDigest(Byte[])

Converts a Byte array into a HashDigest<T>.

Declaration
public HashDigest(byte[] hashDigest)
Parameters
Type Name Description
Byte[] hashDigest

A Byte array that encodes a HashDigest<T>. It must not be null, and its Length must be the same to Size.

Exceptions
Type Condition
ArgumentNullException

Thrown when the given hashDigest is null.

ArgumentOutOfRangeException

Thrown when the given hashDigest's Length is not the same to the Size the hash algorithm (i.e., T requires.

Fields

| Improve this Doc View Source

Size

The fixed, and valid Length of a Byte array of every digest.

This varies depending upon what HashAlgorithm is used for T. For example, if T is SHA1 Size is 20, and if SHA256 it is 32.

Declaration
public static readonly int Size
Field Value
Type Description
Int32

Properties

| Improve this Doc View Source

ByteArray

A bare immutable Byte array of the digest.

Declaration
[EqualityKey(KeyEqualityMode.Auto)]
public ImmutableArray<byte> ByteArray { get; }
Property Value
Type Description
ImmutableArray<Byte>
Remarks

It is immutable. For a mutable array, use ToByteArray() method instead.

See Also
ToByteArray()

Methods

| Improve this Doc View Source

FromString(String)

Converts a given hexadecimal representation of a digest into a HashDigest<T> object.

This is an inverse function of ToString() method.

Declaration
[Pure]
public static HashDigest<T> FromString(string hexDigest)
Parameters
Type Name Description
String hexDigest

A hexadecimal representation of a HashDigest<T>.

Returns
Type Description
HashDigest<T>

A corresponding HashDigest<T> value.

Exceptions
Type Condition
ArgumentNullException

Thrown when the given hexDigest is null.

ArgumentOutOfRangeException

Thrown when the given hexDigest's length is not the double of the Size, the hash algorithm (i.e., T requires.

See Also
ToString()
ToHashDigest<T>(String)
| Improve this Doc View Source

HasLeadingZeroBits(Int32)

Tests if a digest starts with the given number (i.e., bits) of zero bits.

Note that it is bitwise, not bytes.

Declaration
[Pure]
public bool HasLeadingZeroBits(int bits)
Parameters
Type Name Description
Int32 bits

The number of leading zero bits to test.

Returns
Type Description
Boolean

true only if a digest has leading zero bits of the given number (i.e., bits), or more than that. If bits is 0 it always returns true. Otherwise, it returns false.

| Improve this Doc View Source

ToByteArray()

Gets a bare mutable Byte array of the digest.

Declaration
[Pure]
public byte[] ToByteArray()
Returns
Type Description
Byte[]

A new mutable Byte array of the digest. Since a returned array is created every time the method is called, any mutations on that array does not affect to the digest object.

See Also
ByteArray
| Improve this Doc View Source

ToString()

Gets a hexadecimal representation of a digest.

This is an inverse function of FromString(String).

Declaration
[Pure]
public override string ToString()
Returns
Type Description
String

A hexadecimal representation of a digest.

Overrides
ValueType.ToString()
See Also
FromString(String)

See Also

HashAlgorithm
  • Improve this Doc
  • View Source
Back to top Copyright © 2019 Planetarium
Generated by DocFX