Show / Hide Table of Contents

Struct HashDigest<T>

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

Implements
System.Runtime.Serialization.ISerializable
System.IEquatable<HashDigest<T>>
IBencodable
Inherited Members
System.Object.Equals(System.Object, System.Object)
System.Object.GetType()
System.Object.ReferenceEquals(System.Object, System.Object)
Namespace: Libplanet.Common
Assembly: Libplanet.Common.dll
Syntax
[TypeConverter(typeof(HashDigestTypeConverter))]
[Serializable]
public readonly struct HashDigest<T> : ISerializable, IEquatable<HashDigest<T>> where T : HashAlgorithm
Type Parameters
Name Description
T

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

Constructors

| Improve this Doc View Source

HashDigest(in ImmutableArray<Byte>)

Converts an immutable System.Byte array into a HashDigest<T>.

Declaration
public HashDigest(in ImmutableArray<byte> hashDigest)
Parameters
Type Name Description
ImmutableArray<System.Byte> hashDigest

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

Exceptions
Type Condition
System.ArgumentOutOfRangeException

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

See Also
System.Security.Cryptography.HashAlgorithm
| Improve this Doc View Source

HashDigest(IValue)

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

Declaration
public HashDigest(IValue bencoded)
Parameters
Type Name Description
IValue bencoded
See Also
System.Security.Cryptography.HashAlgorithm
| Improve this Doc View Source

HashDigest(Byte[])

Converts a System.Byte array into a HashDigest<T>.

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

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

Exceptions
Type Condition
System.ArgumentNullException

Thrown when the given hashDigest is null.

System.ArgumentOutOfRangeException

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

See Also
System.Security.Cryptography.HashAlgorithm

Fields

| Improve this Doc View Source

Size

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

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

Declaration
public static readonly int Size
Field Value
Type Description
System.Int32
See Also
System.Security.Cryptography.HashAlgorithm

Properties

| Improve this Doc View Source

Bencoded

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

Declaration
public readonly IValue Bencoded { get; }
Property Value
Type Description
IValue
See Also
System.Security.Cryptography.HashAlgorithm
| Improve this Doc View Source

ByteArray

A bare immutable System.Byte array of the digest.

Declaration
public readonly ImmutableArray<byte> ByteArray { get; }
Property Value
Type Description
ImmutableArray<System.Byte>
Remarks

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

See Also
ToByteArray()

Methods

| Improve this Doc View Source

DeriveFrom(ImmutableArray<Byte>)

Computes a hash digest of the algorithm T from the given input bytes.

Declaration
[Pure]
public static HashDigest<T> DeriveFrom(ImmutableArray<byte> input)
Parameters
Type Name Description
ImmutableArray<System.Byte> input

The bytes to compute its hash.

Returns
Type Description
HashDigest<T>

The hash digest derived from input.

See Also
System.Security.Cryptography.HashAlgorithm
| Improve this Doc View Source

DeriveFrom(Byte[])

Computes a hash digest of the algorithm T from the given input bytes.

Declaration
[Pure]
public static HashDigest<T> DeriveFrom(byte[] input)
Parameters
Type Name Description
System.Byte[] input

The bytes to compute its hash.

Returns
Type Description
HashDigest<T>

The hash digest derived from input.

See Also
System.Security.Cryptography.HashAlgorithm
| Improve this Doc View Source

DeriveFrom(ReadOnlySpan<Byte>)

Computes a hash digest of the algorithm T from the given input bytes.

Declaration
[Pure]
public static HashDigest<T> DeriveFrom(ReadOnlySpan<byte> input)
Parameters
Type Name Description
System.ReadOnlySpan<System.Byte> input

The bytes to compute its hash.

Returns
Type Description
HashDigest<T>

The hash digest derived from input.

See Also
System.Security.Cryptography.HashAlgorithm
| Improve this Doc View Source

Equals(HashDigest<T>)

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

Declaration
[Pure]
public readonly bool Equals(HashDigest<T> other)
Parameters
Type Name Description
HashDigest<T> other
Returns
Type Description
System.Boolean
See Also
System.Security.Cryptography.HashAlgorithm
| Improve this Doc View Source

Equals(Object)

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

Declaration
[Pure]
public override readonly bool Equals(object obj)
Parameters
Type Name Description
System.Object obj
Returns
Type Description
System.Boolean
Overrides
System.ValueType.Equals(System.Object)
See Also
System.Security.Cryptography.HashAlgorithm
| 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
System.String hexDigest

A hexadecimal representation of a HashDigest<T>.

Returns
Type Description
HashDigest<T>

A corresponding HashDigest<T> value.

Exceptions
Type Condition
System.ArgumentNullException

Thrown when the given hexDigest is null.

System.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

GetHashCode()

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

Declaration
[Pure]
public override readonly int GetHashCode()
Returns
Type Description
System.Int32
Overrides
System.ValueType.GetHashCode()
See Also
System.Security.Cryptography.HashAlgorithm
| Improve this Doc View Source

GetObjectData(SerializationInfo, StreamingContext)

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

Declaration
public readonly void GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
Type Name Description
System.Runtime.Serialization.SerializationInfo info
System.Runtime.Serialization.StreamingContext context
See Also
System.Security.Cryptography.HashAlgorithm
| Improve this Doc View Source

ToByteArray()

Gets a bare mutable System.Byte array of the digest.

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

A new mutable System.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 readonly string ToString()
Returns
Type Description
System.String

A hexadecimal representation of a digest.

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

Implements

System.Runtime.Serialization.ISerializable
System.IEquatable<T>
IBencodable

See Also

System.Security.Cryptography.HashAlgorithm
  • Improve this Doc
  • View Source
In This Article
Back to top Copyright © 2018–2023 Planetarium