Nim-Libp2p Copyright (c) 2018 Status Research & Development GmbH
- Licensed under either of
- Apache License, version 2.0, (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option. This file may not be copied, modified, or distributed except according to those terms.
This module implements MultiHash. Supported hashes are:- IDENTITY
- SHA2-256/SHA2-512
- DBL-SHA2-256
- SHA3/KECCAK
- SHAKE-128/SHAKE-256
- BLAKE2s/BLAKE2s
- SHA1
Hashes which are not yet supported
- SKEIN
- MURMUR
Types
MHash = object mcodec*: MultiCodec size*: int coder*: MHashCoderProc
- Source Edit
MHashCoderProc = proc (data: openArray[byte]; output: var openArray[byte]) {. nimcall, ...gcsafe, noSideEffect, ...raises: [Defect].}
- Source Edit
MultiHash = object data*: VBuffer mcodec*: MultiCodec size*: int dpos*: int
- Source Edit
Consts
MaxHashSize = 128
- Source Edit
Procs
proc `==`(a: MultiHash; b: MultiHash): bool {....raises: [Defect], tags: [].}
- Compares MultiHashes a and b, returns true if hashes are equal, false otherwise. Source Edit
proc decode(mhtype: typedesc[MultiHash]; data: openArray[byte]; mhash: var MultiHash): MhResult[int] {....raises: [Defect].}
-
Decode MultiHash value from array of bytes data.
On success decoded MultiHash will be stored into mhash and number of bytes consumed will be returned.
On error -1 will be returned.
Source Edit proc init(mhtype: typedesc[MultiHash]; data: openArray[byte]): MhResult[ MultiHash] {.inline, ...raises: [Defect].}
- Create MultiHash from bytes array data. Source Edit
proc init(mhtype: typedesc[MultiHash]; data: string): MhResult[MultiHash] {. inline, ...raises: [Defect].}
- Create MultiHash from hexadecimal string representation data. Source Edit
proc init(mhtype: typedesc[MultiHash]; hashcode: MultiCodec; bdigest: openArray[byte]): MhResult[MultiHash] {.inline, ...raises: [Defect].}
- Create MultiHash from array of bytes bdigest and hash algorithm code hashcode. Source Edit
proc init(mhtype: typedesc[MultiHash]; hashname: string; bdigest: openArray[byte]): MhResult[MultiHash] {.inline, ...raises: [Defect].}
- Create MultiHash from array of bytes bdigest and hash algorithm code hashcode. Source Edit