Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom hash calculation function, allowing content streaming #92

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

idangutman-ms
Copy link

This change provides the ability to add a custom function for calculating the content hash.

This is useful for calculating the hash of the content as it is being streamed, instead of requiring the entire content to be loaded into memory, and is necessary for calculating hashes on large files without excessive memory usage.

Example for usage can be seen in test file, where instead of setting p7.Content, we use the p7.HashCalc (setting Content is optional when using HashCalc):

	reader := bytes.NewReader([]byte(longBuffer))
	p7.HashCalc = func(h hash.Hash, b []byte) []byte {
		bufferSize := 128
		buffer := make([]byte, bufferSize)
		for {
			count, err := reader.Read(buffer)
			if err != nil {
				break
			}
			h.Write(buffer[:count])
		}
		return h.Sum(nil)
	}

@jessepeterson
Copy link

Hello @idangutman-ms. You may want to check out #73 and #88 and perhaps submit this to https://github.com/smallstep/pkcs7 or another fork. FYI and thanks!

@hslatman
Copy link

This has been completed in smallstep#41, and was released in v0.2.0 of https://github.com/smallstep/pkcs7 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants