 Documentation
      ¶
      Documentation
      ¶
    
    
  
    
  
    Index ¶
Examples ¶
Constants ¶
      View Source
      
  const ( SHA1 = 0x11 SHA2_256 = 0x12 SHA2_512 = 0x13 SHA3 = 0x14 BLAKE2B = 0x40 BLAKE2S = 0x41 )
constants
Variables ¶
      View Source
      
  var ( ErrUnknownCode = errors.New("unknown multihash code") ErrTooShort = errors.New("multihash too short. must be > 3 bytes") ErrTooLong = errors.New("multihash too long. must be < 129 bytes") ErrLenNotSupported = errors.New("multihash does not yet support digests longer than 127 bytes") )
errors
      View Source
      
  var Codes = map[int]string{ SHA1: "sha1", SHA2_256: "sha2-256", SHA2_512: "sha2-512", SHA3: "sha3", BLAKE2B: "blake2b", BLAKE2S: "blake2s", }
Codes maps a hash code to it's name
      View Source
      
  var DefaultLengths = map[int]int{ SHA1: 20, SHA2_256: 32, SHA2_512: 64, SHA3: 64, BLAKE2B: 64, BLAKE2S: 32, }
DefaultLengths maps a hash code to it's default length
      View Source
      
  
    var ErrSumNotSupported = errors.New("Function not implemented. Complain to lib maintainer.")
    
      View Source
      
  var Names = map[string]int{ "sha1": SHA1, "sha2-256": SHA2_256, "sha2-512": SHA2_512, "sha3": SHA3, "blake2b": BLAKE2B, "blake2s": BLAKE2S, }
Names maps the name of a hash to the code
Functions ¶
func Encode ¶
Encode a hash digest along with the specified function code. Note: the length is derived from the length of the digest itself.
func EncodeName ¶
Example ¶
// ignores errors for simplicity - don't do that at home.
buf, _ := hex.DecodeString("0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33")
mhbuf, _ := EncodeName(buf, "sha1")
mhhex := hex.EncodeToString(mhbuf)
fmt.Printf("hex: %v\n", mhhex)
Output: hex: 11140beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33
Types ¶
type DecodedMultihash ¶
func Decode ¶
func Decode(buf []byte) (*DecodedMultihash, error)
Decode a hash from the given Multihash.
Example ¶
// ignores errors for simplicity - don't do that at home.
buf, _ := hex.DecodeString("0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33")
mhbuf, _ := EncodeName(buf, "sha1")
o, _ := Decode(mhbuf)
mhhex := hex.EncodeToString(o.Digest)
fmt.Printf("obj: %v 0x%x %d %s\n", o.Name, o.Code, o.Length, mhhex)
Output: obj: sha1 0x11 20 0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33
type ErrInconsistentLen ¶
type ErrInconsistentLen struct {
	// contains filtered or unexported fields
}
    ErrInconsistentLen is returned when a decoded multihash has an inconsistent length
func (ErrInconsistentLen) Error ¶
func (e ErrInconsistentLen) Error() string
 Click to show internal directories. 
   Click to hide internal directories.