MCPcopy Index your code
hub / github.com/kopia/kopia / NewMapWithOptions

Function NewMapWithOptions

internal/bigmap/bigmap_map.go:95–126  ·  view source on GitHub ↗

NewMapWithOptions creates new Map with options.

(ctx context.Context, opt *Options)

Source from the content-addressed store, hash-verified

93
94// NewMapWithOptions creates new Map with options.
95func NewMapWithOptions(ctx context.Context, opt *Options) (*Map, error) {
96 inner, err := newInternalMapWithOptions(ctx, true, opt)
97 if err != nil {
98 return nil, err
99 }
100
101 key := make([]byte, aesKeySize)
102
103 if _, err = rand.Read(key); err != nil {
104 return nil, errors.Wrap(err, "error initializing map key")
105 }
106
107 enc, err := aes.NewCipher(key)
108 if err != nil {
109 return nil, errors.Wrap(err, "error initializing map cipher")
110 }
111
112 aead, err := cipher.NewGCM(enc)
113 if err != nil {
114 return nil, errors.Wrap(err, "error initializing map AEAD")
115 }
116
117 if aead.NonceSize() != aesNonceSize {
118 return nil, errors.Errorf("unexpected nonce size: %v, expected %v", aead.NonceSize(), aesNonceSize)
119 }
120
121 return &Map{
122 aead: aead,
123 inner: inner,
124 nextNonce: new(uint64),
125 }, nil
126}

Callers 4

TestGrowingMapFunction · 0.92
BenchmarkMap_NoValueFunction · 0.92
mainFunction · 0.92
NewMapFunction · 0.85

Calls 3

ErrorfMethod · 0.80
ReadMethod · 0.45

Tested by 2

TestGrowingMapFunction · 0.74
BenchmarkMap_NoValueFunction · 0.74