Skip to content

Latest commit

 

History

28 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Coverage Report Go Reference

dchash

Package dchash implements a configurable variation of Dropbox's Content Hash algorithm in idiomatic Go.

Usage

package checksum

import (
	"crypto/sha512"
	"io"

	"github.com/azazeal/dchash"
)

// Dropbox hashes the data in src as per Dropbox's Content Hash algorithm, using
// SHA256 and over blocks of 4 MiB in size.
func Dropbox(src io.Reader) (sum []byte, err error) {
	h := dchash.New(nil, -1)

	if _, err = io.Copy(h, src); err == nil {
		sum = h.Sum(nil)
	}

	return
}

// SHA512m1 hashes the data in src as per Dropbox's Content Hash algorithm but
// with SHA512 (instead of SHA256) and over blocks of 1 (instead  of 4) MiB in
// size.
func SHA512m1(src io.Reader) (sum []byte, err error) {
	h := dchash.New(sha512.New, 1<<20)

	if _, err = io.Copy(h, src); err == nil {
		sum = h.Sum(nil)
	}

	return
}

About

A configurable variation of Dropbox's Content Hash algorithm in idiomatic Go.

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages