Files
threshold/internal/bsr/options.go
T
Timothy Messier 5d0a9b706e feat(bsr): Add ChunkScanner
The scanner can be used to read any BSR data file. When creating a new
scanner, it will first verify the BSR magic string. Individual Chunks
can then be read back by calling Scan. The scanner will compute a
sha256sum while it is reading chunks. If the scanner was created using
the WithSha256Sum option, it will compare the computed checksum with the
one provided via the option once the scanner encounters an end chunk
(DONE) or an io.EOF error from the reader. If the checksums do not
match, and error will be returned from Scan. The current sha256sum can
be returned from the scanner using the Sum method.

There is also a convenience function, ChunkWalk that can be used to call
a function on each Chunk returned by a scanner.
2023-05-31 12:18:20 +00:00

56 lines
1.2 KiB
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package bsr
import "github.com/hashicorp/boundary/internal/bsr/kms"
// getOpts - iterate the inbound Options and return a struct
func getOpts(opt ...Option) options {
opts := getDefaultOptions()
for _, o := range opt {
o(&opts)
}
return opts
}
// Option - how Options are passed as arguments
type Option func(*options)
// options = how options are represented
type options struct {
withSupportsMultiplex bool
withKeys *kms.Keys
withSha256Sum []byte
}
func getDefaultOptions() options {
return options{
withSupportsMultiplex: false,
withKeys: nil,
withSha256Sum: nil,
}
}
// WithSupportsMultiplex is used indicate that a protocol supports multiplexing
// and therefore a BSR can contain Channels.
func WithSupportsMultiplex(b bool) Option {
return func(o *options) {
o.withSupportsMultiplex = b
}
}
// WithKeys is used to provide optional kms.Keys.
func WithKeys(k *kms.Keys) Option {
return func(o *options) {
o.withKeys = k
}
}
// WithSha256Sum is used to provide a hex encoded SHA256SUM.
func WithSha256Sum(b []byte) Option {
return func(o *options) {
o.withSha256Sum = b
}
}