Files
threshold/internal/session/credential.go
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

45 lines
1.3 KiB
Go
Raw Normal View History

2021-12-17 11:25:30 -08:00
package session
import (
"context"
"github.com/hashicorp/boundary/internal/errors"
wrapping "github.com/hashicorp/go-kms-wrapping/v2"
"github.com/hashicorp/go-kms-wrapping/v2/extras/structwrapping"
2021-12-17 11:25:30 -08:00
)
// Credential represents the credential data which is sent to the worker.
type Credential []byte
type credential struct {
SessionId string
KeyId string
Credential []byte `gorm:"-" wrapping:"pt,credential_data"`
CtCredential []byte `gorm:"column:credential" wrapping:"ct,credential_data"`
}
// TableName returns the table name.
func (c *credential) TableName() string {
return "session_credential"
}
func (c *credential) encrypt(ctx context.Context, cipher wrapping.Wrapper) error {
const op = "session.(credential).encrypt"
if err := structwrapping.WrapStruct(ctx, cipher, c, nil); err != nil {
return errors.Wrap(ctx, err, op, errors.WithCode(errors.Encrypt))
}
var err error
c.KeyId, err = cipher.KeyId(ctx)
if err != nil {
return errors.Wrap(ctx, err, op, errors.WithMsg("unable to discover wrapper key id"))
}
2021-12-17 11:25:30 -08:00
return nil
}
func (c *credential) decrypt(ctx context.Context, cipher wrapping.Wrapper) error {
const op = "session.(credential).decrypt"
if err := structwrapping.UnwrapStruct(ctx, cipher, c, nil); err != nil {
return errors.Wrap(ctx, err, op, errors.WithCode(errors.Decrypt))
}
return nil
}