NewMapWithOptions creates new Map with options.
(ctx context.Context, opt *Options)
| 93 | |
| 94 | // NewMapWithOptions creates new Map with options. |
| 95 | func 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 | } |