Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var Algorithms = map[Algorithm]func() hash.Hash{ MD4: crypto.MD4.New, MD5: crypto.MD5.New, SHA1: crypto.SHA1.New, SHA224: crypto.SHA224.New, SHA256: crypto.SHA256.New, SHA384: crypto.SHA384.New, SHA512: crypto.SHA512.New, SHA512_224: crypto.SHA512_224.New, SHA512_256: crypto.SHA512_256.New, SHA3_224: crypto.SHA3_224.New, SHA3_256: crypto.SHA3_256.New, SHA3_384: crypto.SHA3_384.New, SHA3_512: crypto.SHA3_512.New, RIPEMD160: crypto.RIPEMD160.New, BLAKE2S_256: crypto.BLAKE2s_256.New, BLAKE2B_256: crypto.BLAKE2b_256.New, BLAKE2B_384: crypto.BLAKE2b_384.New, BLAKE2B_512: crypto.BLAKE2b_512.New, ADLER32: func() hash.Hash { return adler32.New() }, CRC32: func() hash.Hash { return crc32.New(crc32.IEEETable) }, CRC64: func() hash.Hash { return crc64.New(crc64.MakeTable(crc64.ISO)) }, FNV: func() hash.Hash { return fnv.New32() }, FNV1: func() hash.Hash { return fnv.New32() }, FNV1A: func() hash.Hash { return fnv.New32a() }, }
Functions ¶
This section is empty.
Types ¶
type Algorithm ¶
type Algorithm string
const ( MD4 Algorithm = "md4" MD5 Algorithm = "md5" SHA1 Algorithm = "sha1" SHA224 Algorithm = "sha224" SHA256 Algorithm = "sha256" SHA384 Algorithm = "sha384" SHA512 Algorithm = "sha512" SHA512_224 Algorithm = "sha512224" SHA512_256 Algorithm = "sha512256" SHA3_224 Algorithm = "sha3224" SHA3_256 Algorithm = "sha3256" SHA3_384 Algorithm = "sha3384" SHA3_512 Algorithm = "sha3512" RIPEMD160 Algorithm = "ripemd160" BLAKE2S_256 Algorithm = "blake2s256" BLAKE2B_256 Algorithm = "blake2b256" BLAKE2B_384 Algorithm = "blake2b384" BLAKE2B_512 Algorithm = "blake2b512" ADLER32 Algorithm = "adler32" CRC32 Algorithm = "crc32" CRC64 Algorithm = "crc64" FNV Algorithm = "fnv" FNV1 Algorithm = "fnv1" FNV1A Algorithm = "fnv1a" )
func GetAlgorithm ¶
type DeferTrailerReader ¶
type DeferTrailerReader struct {
// contains filtered or unexported fields
}
DeferTrailerReader is io.Reader that concatenates body and trailer readers and substitutes trailer values to request just after body data was drawn out. This is suitable when trailer values are unknown before the whole body was fully read. For example -- get the checksum of huge body without copying it to an intermediate buffer.
Example ¶
package main import ( "crypto" "io" "net/http" "strings" "github.com/bdragon300/tusgo/checksum" ) func main() { req, err := http.NewRequest(http.MethodPost, "http://example.com", nil) if err != nil { panic(err) } b64hash := checksum.NewHashBase64ReadWriter(crypto.SHA1.New(), "sha1 ") body := io.TeeReader(strings.NewReader("Hello world!"), b64hash) trailers := map[string]io.Reader{"Checksum": body} req.Body = io.NopCloser(checksum.NewDeferTrailerReader(body, trailers, req)) // Request will contain header "Trailer: Checksum" // and an HTTP trailer "Checksum: sha1 00hq6RNueFa8QiEjhep5cJRHWAI=" response, err := http.DefaultClient.Do(req) if err != nil { panic(err) } defer response.Body.Close() }
Output:
func NewDeferTrailerReader ¶
func NewDeferTrailerReader(body io.Reader, trailers map[string]io.Reader, request *http.Request) *DeferTrailerReader
NewDeferTrailerReader constructs a new DeferTrailerReader object. Receives a body data reader, trailers and their readers to be sent, and a request object
func (DeferTrailerReader) Read ¶
func (h DeferTrailerReader) Read(p []byte) (n int, err error)
Read reads up to len(p) bytes of request body into p. After the body reader has fully drawn out, it sequentially gets given trailers data from their readers and assigns it to the request. The function returns the number of bytes read (0 <= n <= len(p)) and any error encountered. Returns io.EOF error if all result has read and no more data available.
type HashBase64ReadWriter ¶
HashBase64ReadWriter an io.Reader that wraps a hash.Hash, it feeds the prefix + hash in base64 format
func NewHashBase64ReadWriter ¶
func NewHashBase64ReadWriter(h hash.Hash, prefix string) *HashBase64ReadWriter
NewHashBase64ReadWriter constructs a new HashBase64ReadWriter. Receives a hash object to wrap and a prefix to prepend hash result string
Example ¶
package main import ( "crypto" "fmt" "io" "github.com/bdragon300/tusgo/checksum" ) func main() { data := []byte("Hello world!") rw := checksum.NewHashBase64ReadWriter(crypto.SHA1.New(), "sha1 ") if _, err := rw.Write(data); err != nil { panic(err) } sum, err := io.ReadAll(rw) if err != nil { panic(err) } fmt.Printf("%s\n", sum) }
Output: sha1 00hq6RNueFa8QiEjhep5cJRHWAI=
func (*HashBase64ReadWriter) Read ¶
func (h *HashBase64ReadWriter) Read(p []byte) (n int, err error)
Read reads up to len(p) bytes of base64 hash sum into p. It invokes Sum calculation on the first call. The function returns the number of bytes read (0 <= n <= len(p)) and any error encountered. Returns io.EOF error if all result has read and no more data available.