-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use associated data along with the key
Signed-off-by: Volodymyr Kit <[email protected]>
- Loading branch information
Showing
5 changed files
with
163 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package localkms | ||
|
||
import ( | ||
"github.com/google/tink/go/tink" | ||
kmsapi "github.com/trustbloc/kms-go/spi/kms" | ||
"github.com/trustbloc/kms-go/spi/secretlock" | ||
) | ||
|
||
type kmsOpts struct { | ||
store kmsapi.Store | ||
lock secretlock.Service | ||
aeadService tink.AEAD | ||
primaryKeyURI string | ||
} | ||
|
||
// NewKMSOpt creates a new empty KMS options. | ||
func NewKMSOpt() *kmsOpts { // nolint | ||
return &kmsOpts{} | ||
} | ||
|
||
func (k *kmsOpts) Store() kmsapi.Store { | ||
return k.store | ||
} | ||
|
||
func (k *kmsOpts) SecretLock() secretlock.Service { | ||
return k.lock | ||
} | ||
|
||
func (k *kmsOpts) AEADService() tink.AEAD { | ||
return k.aeadService | ||
} | ||
|
||
func (k *kmsOpts) PrimaryKeyURI() string { | ||
return k.primaryKeyURI | ||
} | ||
|
||
// KMSOpts are the create KMS option. | ||
type KMSOpts func(opts *kmsOpts) | ||
|
||
// WithStore option is for setting store for KMS. | ||
func WithStore(store kmsapi.Store) KMSOpts { | ||
return func(opts *kmsOpts) { | ||
opts.store = store | ||
} | ||
} | ||
|
||
// WithSecretLock option is for setting secret-lock for KMS. | ||
func WithSecretLock(secretLock secretlock.Service) KMSOpts { | ||
return func(opts *kmsOpts) { | ||
opts.lock = secretLock | ||
} | ||
} | ||
|
||
// WithPrimaryKeyURI option is for setting secret-lock for KMS. | ||
func WithPrimaryKeyURI(primaryKeyURI string) KMSOpts { | ||
return func(opts *kmsOpts) { | ||
opts.primaryKeyURI = primaryKeyURI | ||
} | ||
} | ||
|
||
// WithAEAD option is for setting AEAD service directly for KMS. | ||
// If not set, secretLock and primaryKeyURI will be used. | ||
func WithAEAD(aeadService tink.AEAD) KMSOpts { | ||
return func(opts *kmsOpts) { | ||
opts.aeadService = aeadService | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters