Files
threshold/internal/kms/rewrapping.go
T
429247f407 [COMPLIANCE] Update Copyright Headers (#6282)
* [COMPLIANCE] Update Copyright and License Headers

* chore: make gen to generate files with copyright headers

* chore: update missed copyright headers

---------

Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
Co-authored-by: Justin Nguyen <justin.nguyen@hashicorp.com>
2026-01-28 11:05:07 -06:00

38 lines
1.2 KiB
Go

// Copyright IBM Corp. 2020, 2025
// SPDX-License-Identifier: BUSL-1.1
package kms
import (
"context"
"fmt"
"github.com/hashicorp/boundary/internal/db"
wrapping "github.com/hashicorp/go-kms-wrapping/v2"
"golang.org/x/exp/maps"
)
// GetWrapperer defines (and constrains) the kms features required by the
// RewrapFn
type GetWrapperer interface {
// GetWrapper returns a wrapper for the given scope and purpose.
GetWrapper(ctx context.Context, scopeId string, purpose KeyPurpose, opt ...Option) (wrapping.Wrapper, error)
}
type RewrapFn func(ctx context.Context, dataKeyVersionId string, scopeId string, reader db.Reader, writer db.Writer, kms GetWrapperer) error
var tableNameToRewrapFn = map[string]RewrapFn{}
// RegisterTableRewrapFn registers a function to be used to rewrap data in a specific table with a new key
func RegisterTableRewrapFn(tableName string, rewrapFn RewrapFn) {
if _, ok := tableNameToRewrapFn[tableName]; ok {
panic(fmt.Sprintf("rewrap function for table name %q already exists", tableName))
}
tableNameToRewrapFn[tableName] = rewrapFn
}
// ListTablesSupportingRewrap lists all the table names registered with a rewrap function
func ListTablesSupportingRewrap() []string {
return maps.Keys(tableNameToRewrapFn)
}