C# Class Ipfs.MultiHash

A protocol for differentiating outputs from various well-established cryptographic hash functions, addressing size + encoding considerations.
Mostrar archivo Open project: richardschneider/net-ipfs-core Class Usage Examples

Public Properties

Property Type Description
UnknownHashingAlgorithm EventHandler

Public Methods

Method Description
ComputeHash ( Stream data, string algorithmName = DefaultAlgorithmName ) : MultiHash

Generate the multihash for the specified data.

ComputeHash ( byte data, string algorithmName = DefaultAlgorithmName ) : MultiHash

Generate the multihash for the specified data.

GetHashAlgorithm ( string name = DefaultAlgorithmName ) : HashAlgorithm

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

Matches ( Stream data ) : bool

Determines if the stream data matches the hash.

Matches is used to ensure data integrity.

Matches ( byte data ) : bool

Determines if the data matches the hash.

Matches is used to ensure data integrity.

MultiHash ( CodedInputStream stream ) : System

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

Reads the binary representation of MultiHash from the stream.

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

When an unknown hashing algorithm number is encountered a new HashingAlgorithm.Register is defined. This 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.

MultiHash ( Stream stream ) : System

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

Reads the binary representation of MultiHash from the stream.

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

When an unknown hashing algorithm number is encountered a new HashingAlgorithm.Register is defined. This 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.

MultiHash ( string s ) : System

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

When an unknown hashing algorithm number is encountered a new HashingAlgorithm.Register is defined. This 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.

MultiHash ( string algorithmName, byte digest ) : System

Creates a new instance of the MultiHash class with the specified HashingAlgorithm">Algorithm name and

RaiseUnknownHashingAlgorithm ( HashingAlgorithm algorithm ) : void
Read ( CodedInputStream stream ) : void
Read ( Stream stream ) : void
ToArray ( ) : byte[]

Returns the IPFS binary representation as a byte array.

The binary representation is a sequence of MultiHash.

ToBase58 ( ) : string

Returns the Base58 encoding of the MultiHash.

ToString ( ) : string

Returns the Base58 encoding of the MultiHash.

Write ( CodedOutputStream stream ) : void

Writes the binary representation to the specified CodedOutputStream.

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

Write ( Stream stream ) : void

Writes the binary representation to the specified Stream.

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

Private Methods

Method Description
MultiHash ( ) : System

Register the standard hash algorithms for IPFS.

Method Details

ComputeHash() public static method

Generate the multihash for the specified data.
public static ComputeHash ( Stream data, string algorithmName = DefaultAlgorithmName ) : MultiHash
data Stream /// The containing the data to hash. ///
algorithmName string /// The name of the hashing algorithm to use; defaults to . ///
return MultiHash

ComputeHash() public static method

Generate the multihash for the specified data.
public static ComputeHash ( byte data, string algorithmName = DefaultAlgorithmName ) : MultiHash
data byte /// The containing the data to hash. ///
algorithmName string /// The name of the hashing algorithm to use; defaults to . ///
return MultiHash

GetHashAlgorithm() public static method

Gets the HashAlgorithm with the specified IPFS multi-hash name.
public static GetHashAlgorithm ( string name = DefaultAlgorithmName ) : HashAlgorithm
name string
return System.Security.Cryptography.HashAlgorithm

Matches() public method

Determines if the stream data matches the hash.
Matches is used to ensure data integrity.
public Matches ( Stream data ) : bool
data Stream /// The containing the data to check. ///
return bool

Matches() public method

Determines if the data matches the hash.
Matches is used to ensure data integrity.
public Matches ( byte data ) : bool
data byte /// The data to check. ///
return bool

MultiHash() public method

Creates a new instance of the MultiHash class from the specified CodedInputStream.
Reads the binary representation of MultiHash from the stream.

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

When an unknown hashing algorithm number is encountered a new HashingAlgorithm.Register is defined. This 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.

public MultiHash ( CodedInputStream stream ) : System
stream Google.Protobuf.CodedInputStream ( /// A containing the binary representation of the /// MultiHash. ///
return System

MultiHash() public method

Creates a new instance of the MultiHash class from the specified Stream.
Reads the binary representation of MultiHash from the stream.

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

When an unknown hashing algorithm number is encountered a new HashingAlgorithm.Register is defined. This 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.

public MultiHash ( Stream stream ) : System
stream Stream ( /// A containing the binary representation of the /// MultiHash. ///
return System

MultiHash() public method

Creates a new instance of the MultiHash class from the specified Base58 encoded string.
When an unknown hashing algorithm number is encountered a new HashingAlgorithm.Register is defined. This 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.

public MultiHash ( string s ) : System
s string /// A encoded MultiHash. ///
return System

MultiHash() public method

Creates a new instance of the MultiHash class with the specified HashingAlgorithm">Algorithm name and
public MultiHash ( string algorithmName, byte digest ) : System
algorithmName string /// A valid IPFS hashing algorithm name, e.g. "sha2-256" or "sha2-512". ///
digest byte /// The digest value as a byte array. ///
return System

RaiseUnknownHashingAlgorithm() public method

public RaiseUnknownHashingAlgorithm ( HashingAlgorithm algorithm ) : void
algorithm HashingAlgorithm
return void

Read() public method

public Read ( CodedInputStream stream ) : void
stream Google.Protobuf.CodedInputStream
return void

Read() public method

public Read ( Stream stream ) : void
stream Stream
return void

ToArray() public method

Returns the IPFS binary representation as a byte array.
The binary representation is a sequence of MultiHash.
public ToArray ( ) : byte[]
return byte[]

ToBase58() public method

Returns the Base58 encoding of the MultiHash.
public ToBase58 ( ) : string
return string

ToString() public method

Returns the Base58 encoding of the MultiHash.
public ToString ( ) : string
return string

Write() public method

Writes the binary representation to the specified CodedOutputStream.
The binary representation is a 1-byte HashingAlgorithm.Code, 1-byte HashingAlgorithm.DigestSize followed by the Digest.
public Write ( CodedOutputStream stream ) : void
stream Google.Protobuf.CodedOutputStream /// The to write to. ///
return void

Write() public method

Writes the binary representation to the specified Stream.
The binary representation is a 1-byte HashingAlgorithm.Code, 1-byte HashingAlgorithm.DigestSize followed by the Digest.
public Write ( Stream stream ) : void
stream Stream /// The to write to. ///
return void

Property Details

UnknownHashingAlgorithm public_oe static_oe property

Occurs when an unknown hashing algorithm number is parsed.
public static EventHandler UnknownHashingAlgorithm
return EventHandler