Show / Hide Table of Contents

Class MultiHash

A protocol for differentiating outputs from various well-established cryptographic hash functions, addressing size + encoding considerations.

Inheritance
Object
MultiHash
Implements
IEquatable<MultiHash>
Inherited Members
Object.Equals(Object, Object)
Object.GetType()
Object.MemberwiseClone()
Object.ReferenceEquals(Object, Object)
Namespace: Ipfs
Assembly: Ipfs.Core.dll
Syntax
[JsonConverter(typeof(MultiHash.Json))]
public class MultiHash : IEquatable<MultiHash>
Remarks

See the HashingAlgorithm for supported algorithms.

Constructors

| Improve this Doc View Source

MultiHash(CodedInputStream)

Creates a new instance of the MultiHash class from the specified Google.Protobuf.CodedInputStream.

Declaration
public MultiHash(CodedInputStream stream)
Parameters
Type Name Description
Google.Protobuf.CodedInputStream stream

A Google.Protobuf.CodedInputStream containing the binary representation of the MultiHash.

Remarks

Reads the binary representation of MultiHash from the stream.

The binary representation is a Varint of the Code, Varint of the DigestSize followed by the Digest.

When an unknown Code is encountered a new hashing algorithm is Register(String, Int32, Int32, Func<HashAlgorithm>). This new algorithm does not support matching nor computing a hash. This behaviour allows parsing of any well formed MultiHash even when the hashing algorithm is unknown.

| Improve this Doc View Source

MultiHash(Byte[])

Creates a new instance of the MultiHash class from the specified byte array.

Declaration
public MultiHash(byte[] buffer)
Parameters
Type Name Description
Byte[] buffer

A sequence of bytes containing the binary representation of the MultiHash.

Remarks

Reads the binary representation of MultiHash from the buffer.

The binary representation is a Varint of the Code, Varint of the DigestSize followed by the Digest.

When an unknown Code is encountered a new hashing algorithm is Register(String, Int32, Int32, Func<HashAlgorithm>). This new algorithm does not support matching nor computing a hash. This behaviour allows parsing of any well formed MultiHash even when the hashing algorithm is unknown.

See Also
ToArray()
| Improve this Doc View Source

MultiHash(Stream)

Creates a new instance of the MultiHash class from the specified Stream.

Declaration
public MultiHash(Stream stream)
Parameters
Type Name Description
Stream stream

A Stream containing the binary representation of the MultiHash.

Remarks

Reads the binary representation of MultiHash from the stream.

The binary representation is a Varint of the Code, Varint of the DigestSize followed by the Digest.

When an unknown Code is encountered a new hashing algorithm is Register(String, Int32, Int32, Func<HashAlgorithm>). This new algorithm does not support matching nor computing a hash. This behaviour allows parsing of any well formed MultiHash even when the hashing algorithm is unknown.

| Improve this Doc View Source

MultiHash(String)

Creates a new instance of the MultiHash class from the specified Base58 encoded String.

Declaration
public MultiHash(string s)
Parameters
Type Name Description
String s

A Base58 encoded MultiHash.

Remarks

When an unknown Code is encountered a new hashing algorithm is Register(String, Int32, Int32, Func<HashAlgorithm>). This new algorithm does not support matching nor computing a hash. This behaviour allows parsing of any well formed MultiHash even when the hashing algorithm is unknown.

See Also
ToBase58()
| Improve this Doc View Source

MultiHash(String, Byte[])

Creates a new instance of the MultiHash class with the specified HashingAlgorithm and Digest value.

Declaration
public MultiHash(string algorithmName, byte[] digest)
Parameters
Type Name Description
String algorithmName

A valid IPFS hashing algorithm name, e.g. "sha2-256" or "sha2-512".

Byte[] digest

The digest value as a byte array.

Fields

| Improve this Doc View Source

DefaultAlgorithmName

The default hashing algorithm is "sha2-256".

Declaration
public const string DefaultAlgorithmName = "sha2-256"
Field Value
Type Description
String
| Improve this Doc View Source

UnknownHashingAlgorithm

Occurs when an unknown hashing algorithm number is parsed.

Declaration
public static EventHandler<UnknownHashingAlgorithmEventArgs> UnknownHashingAlgorithm
Field Value
Type Description
EventHandler<UnknownHashingAlgorithmEventArgs>

Properties

| Improve this Doc View Source

Algorithm

The hashing algorithm.

Declaration
public HashingAlgorithm Algorithm { get; }
Property Value
Type Description
HashingAlgorithm

Details on the hashing algorithm.

| Improve this Doc View Source

Digest

The hashing algorithm's digest value.

Declaration
public byte[] Digest { get; }
Property Value
Type Description
Byte[]

The output of the hashing algorithm.

| Improve this Doc View Source

IsIdentityHash

Determines if the identity hash algorithm is in use.

Declaration
public bool IsIdentityHash { get; }
Property Value
Type Description
Boolean

true if the identity hash algorithm is used; otherwise, false.

Remarks

The identity hash is used to inline a small amount of data into a Cid. When true, the Digest is also the content.

Methods

| Improve this Doc View Source

ComputeHash(Byte[], String)

Generate the multihash for the specified byte array.

Declaration
public static MultiHash ComputeHash(byte[] data, string algorithmName = "sha2-256")
Parameters
Type Name Description
Byte[] data

The byte array containing the data to hash.

String algorithmName

The name of the hashing algorithm to use; defaults to DefaultAlgorithmName.

Returns
Type Description
MultiHash

A MultiHash for the data.

| Improve this Doc View Source

ComputeHash(Stream, String)

Generate the multihash for the specified Stream.

Declaration
public static MultiHash ComputeHash(Stream data, string algorithmName = "sha2-256")
Parameters
Type Name Description
Stream data

The Stream containing the data to hash.

String algorithmName

The name of the hashing algorithm to use; defaults to DefaultAlgorithmName.

Returns
Type Description
MultiHash

A MultiHash for the data.

| Improve this Doc View Source

Equals(MultiHash)

Declaration
public bool Equals(MultiHash that)
Parameters
Type Name Description
MultiHash that
Returns
Type Description
Boolean
| Improve this Doc View Source

Equals(Object)

Declaration
public override bool Equals(object obj)
Parameters
Type Name Description
Object obj
Returns
Type Description
Boolean
Overrides
Object.Equals(Object)
| Improve this Doc View Source

GetHashAlgorithm(String)

Gets the HashAlgorithm with the specified IPFS multi-hash name.

Declaration
public static HashAlgorithm GetHashAlgorithm(string name = "sha2-256")
Parameters
Type Name Description
String name

The name of a hashing algorithm, see https://github.com/multiformats/multicodec/blob/master/table.csv for IPFS defined names.

Returns
Type Description
HashAlgorithm

The hashing implementation associated with the name. After using the hashing algorithm it should be disposed.

Exceptions
Type Condition
KeyNotFoundException

When name is not registered.

| Improve this Doc View Source

GetHashAlgorithmName(Int32)

Gets the name of hashing algorithm name with the specified code.

Declaration
public static string GetHashAlgorithmName(int code)
Parameters
Type Name Description
Int32 code

The code of a hashing algorithm, see https://github.com/multiformats/multicodec/blob/master/table.csv for IPFS defined codes.

Returns
Type Description
String

The name assigned to code.

Exceptions
Type Condition
KeyNotFoundException

When code is not registered.

| Improve this Doc View Source

GetHashCode()

Declaration
public override int GetHashCode()
Returns
Type Description
Int32
Overrides
Object.GetHashCode()
| Improve this Doc View Source

Matches(Byte[])

Determines if the data matches the hash.

Declaration
public bool Matches(byte[] data)
Parameters
Type Name Description
Byte[] data

The data to check.

Returns
Type Description
Boolean

true if the data matches the MultiHash; otherwise, false.

Remarks

Matches is used to ensure data integrity.

| Improve this Doc View Source

Matches(Stream)

Determines if the stream data matches the hash.

Declaration
public bool Matches(Stream data)
Parameters
Type Name Description
Stream data

The Stream containing the data to check.

Returns
Type Description
Boolean

true if the data matches the MultiHash; otherwise, false.

Remarks

Matches is used to ensure data integrity.

| Improve this Doc View Source

ToArray()

Returns the IPFS binary representation as a byte array.

Declaration
public byte[] ToArray()
Returns
Type Description
Byte[]

A byte array.

Remarks

The binary representation is a sequence of MultiHash.

| Improve this Doc View Source

ToBase32()

Returns the Base32 encoding of the MultiHash.

Declaration
public string ToBase32()
Returns
Type Description
String

The Base32 representation of the MultiHash.

| Improve this Doc View Source

ToBase58()

Returns the Base58 encoding of the MultiHash.

Declaration
public string ToBase58()
Returns
Type Description
String

The Base58 representation of the MultiHash.

| Improve this Doc View Source

ToString()

Returns the Base58 encoding of the MultiHash.

Declaration
public override string ToString()
Returns
Type Description
String

A base-58 representaton of the MultiHash.

Overrides
Object.ToString()
See Also
ToBase58()
| Improve this Doc View Source

Write(CodedOutputStream)

Writes the binary representation of the multihash to the specified Google.Protobuf.CodedOutputStream.

Declaration
public void Write(CodedOutputStream stream)
Parameters
Type Name Description
Google.Protobuf.CodedOutputStream stream

The Google.Protobuf.CodedOutputStream to write to.

Remarks

The binary representation is a Varint of the Code, Varint of the DigestSize followed by the Digest.

| Improve this Doc View Source

Write(Stream)

Writes the binary representation of the multihash to the specified Stream.

Declaration
public void Write(Stream stream)
Parameters
Type Name Description
Stream stream

The Stream to write to.

Remarks

The binary representation is a 1-byte Code, 1-byte DigestSize followed by the Digest.

Operators

| Improve this Doc View Source

Equality(MultiHash, MultiHash)

Value equality.

Declaration
public static bool operator ==(MultiHash a, MultiHash b)
Parameters
Type Name Description
MultiHash a
MultiHash b
Returns
Type Description
Boolean
| Improve this Doc View Source

Implicit(String to MultiHash)

Implicit casting of a String to a MultiHash.

Declaration
public static implicit operator MultiHash(string s)
Parameters
Type Name Description
String s

A Base58 encoded MultiHash.

Returns
Type Description
MultiHash

A new MultiHash.

Remarks

Equivalent to

new MultiHash(s)

| Improve this Doc View Source

Inequality(MultiHash, MultiHash)

Value inequality.

Declaration
public static bool operator !=(MultiHash a, MultiHash b)
Parameters
Type Name Description
MultiHash a
MultiHash b
Returns
Type Description
Boolean

Implements

System.IEquatable<T>

See Also

https://github.com/jbenet/multihash
  • Improve this Doc
  • View Source
Back to top Generated by DocFX