rawprovider

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2024 License: Apache-2.0 Imports: 11 Imported by: 2

Documentation

Overview

Package rawprovider contains Raw Master Key Provider implementation.

See usage below or check examples for more detailed use.

Example configuration:

// static key to use for encryption and decryption
staticKey1 := []byte("superSecureKeySecureKey32bytes32")
rawProvider, err := rawprovider.NewWithOpts(
    "raw",
    rawprovider.WithStaticKey("static1", staticKey1),
)
if err != nil {
    panic(err) // handle error
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// contains filtered or unexported fields
}

Options contains the configuration options for the RawKeyProvider.

type OptionsFunc

type OptionsFunc func(*Options) error

OptionsFunc is a function that applies an option to the Options.

func WithKeyFactory

func WithKeyFactory(keyFactory model.MasterKeyFactory) OptionsFunc

WithKeyFactory sets the master key factory for the Raw provider.

func WithKeyProvider

func WithKeyProvider(keyProvider model.BaseKeyProvider) OptionsFunc

WithKeyProvider sets the base key provider for the Raw provider.

func WithStaticKey

func WithStaticKey(keyID string, key []byte) OptionsFunc

WithStaticKey configures a static key for the Raw provider.

type RawKeyProvider

type RawKeyProvider[KT model.MasterKey] struct {
	// contains filtered or unexported fields
}

RawKeyProvider is a Raw Key Provider.

func NewWithOpts

func NewWithOpts(providerID string, optFns ...func(options *Options) error) (*RawKeyProvider[model.MasterKey], error)

NewWithOpts creates a new RawKeyProvider with the given keyIDs.

It also accepts an optional variadic set of functional Options for configuring the provider.

At least one keyID must be configured via WithStaticKey for the provider to be valid.

See usage below or check examples for more detailed use.

Example configuration:

// static key to use for encryption and decryption
staticKey1 := []byte("superSecureKeySecureKey32bytes32")
rawProvider, err := rawprovider.NewWithOpts(
    "raw",
    rawprovider.WithStaticKey("static1", staticKey1),
)
if err != nil {
    panic(err) // handle error
}

func (*RawKeyProvider[KT]) AddMasterKey

func (rawKP *RawKeyProvider[KT]) AddMasterKey(keyID string) (model.MasterKey, error)

AddMasterKey validates the given keyID, checks if it doesn't exist within the Raw Provider, creates Raw Master Key, and adds it to the master key provider.

func (*RawKeyProvider[KT]) DecryptDataKey

func (rawKP *RawKeyProvider[KT]) DecryptDataKey(ctx context.Context, encryptedDataKey model.EncryptedDataKeyI, alg *suite.AlgorithmSuite, ec suite.EncryptionContext) (model.DataKeyI, error)

DecryptDataKey attempts to decrypt the encrypted data key with a KeyProvider.

func (*RawKeyProvider[KT]) DecryptDataKeyFromList

func (rawKP *RawKeyProvider[KT]) DecryptDataKeyFromList(ctx context.Context, encryptedDataKeys []model.EncryptedDataKeyI, alg *suite.AlgorithmSuite, ec suite.EncryptionContext) (model.DataKeyI, error)

DecryptDataKeyFromList attempts to decrypt data key from the encrypted data keys with a KeyProvider.

func (*RawKeyProvider[KT]) MasterKeyForDecrypt

func (rawKP *RawKeyProvider[KT]) MasterKeyForDecrypt(_ context.Context, _ model.KeyMeta) (model.MasterKey, error)

MasterKeyForDecrypt always returns an error because RawKeyProvider doesn't support vend data keys for decryption.

func (*RawKeyProvider[KT]) MasterKeysForDecryption

func (rawKP *RawKeyProvider[KT]) MasterKeysForDecryption() []model.MasterKey

MasterKeysForDecryption returns the list of master keys registered for decryption with the Raw Provider.

This method mainly used by keyprovider.KeyProvider.

func (*RawKeyProvider[KT]) MasterKeysForEncryption

func (rawKP *RawKeyProvider[KT]) MasterKeysForEncryption(_ context.Context, _ suite.EncryptionContext) (model.MasterKey, []model.MasterKey, error)

MasterKeysForEncryption returns the primary model.MasterKey and a list of master keys registered with the Raw Provider for encryption.

func (*RawKeyProvider[KT]) NewMasterKey

func (rawKP *RawKeyProvider[KT]) NewMasterKey(_ context.Context, keyID string) (model.MasterKey, error)

NewMasterKey returns a new instance of raw.MasterKey created by raw.KeyFactory.

func (*RawKeyProvider[KT]) ProviderID

func (rawKP *RawKeyProvider[KT]) ProviderID() string

ProviderID returns the ID of the provider.

func (*RawKeyProvider[KT]) ProviderKind

func (rawKP *RawKeyProvider[KT]) ProviderKind() types.ProviderKind

ProviderKind returns the kind types.Raw.

func (*RawKeyProvider[KT]) ValidateMasterKey

func (rawKP *RawKeyProvider[KT]) ValidateMasterKey(keyID string) error

ValidateMasterKey validates the given keyID are registered in the provider.

func (*RawKeyProvider[KT]) ValidateProviderID

func (rawKP *RawKeyProvider[KT]) ValidateProviderID(otherID string) error

ValidateProviderID validates master key provider ID matches the given provider ID.

type RawProvider

type RawProvider interface {
	model.MasterKeyProvider
	// contains filtered or unexported methods
}

RawProvider is an interface for Raw Key Providers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL