Skip to content

Commit

Permalink
rename to simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
dmihalcik-virtru committed Jan 13, 2025
1 parent 5344c0b commit b6e78ca
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions service/kas/access/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Provider struct {
URI url.URL `json:"uri"`
SDK *otdf.SDK
AttributeSvc *url.URL
recrypt.CryptoProvider
recrypt.Provider
Logger *logger.Logger
Config *serviceregistry.ServiceConfig
KASConfig
Expand Down Expand Up @@ -74,7 +74,7 @@ func (p *Provider) LoadStandardCryptoProvider() (*recrypt.Standard, error) {
if err != nil {
return nil, fmt.Errorf("recrypt.NewStandardWithOptions failed: %w", err)
}
p.CryptoProvider = c
p.Provider = c
return c, nil
}

Expand Down
14 changes: 7 additions & 7 deletions service/kas/access/publicKey.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ const (
)

func (p Provider) LegacyPublicKey(ctx context.Context, req *connect.Request[kaspb.LegacyPublicKeyRequest]) (*connect.Response[wrapperspb.StringValue], error) {
algorithm, err := p.CryptoProvider.ParseAlgorithm(req.Msg.GetAlgorithm())
algorithm, err := p.ParseAlgorithm(req.Msg.GetAlgorithm())
if err != nil {
return nil, err
}
kids, err := p.CryptoProvider.CurrentKID(algorithm)
kids, err := p.CurrentKID(algorithm)
if err != nil {
return nil, err
}
Expand All @@ -37,7 +37,7 @@ func (p Provider) LegacyPublicKey(ctx context.Context, req *connect.Request[kasp
p.Logger.ErrorContext(ctx, "multiple keys found for algorithm", "algorithm", algorithm, "kids", kids)
}
fmt := recrypt.KeyFormatPEM
pem, err := p.CryptoProvider.PublicKey(algorithm, kids[:1], fmt)
pem, err := p.Provider.PublicKey(algorithm, kids[:1], fmt)
if err != nil {
p.Logger.ErrorContext(ctx, "CryptoProvider.ECPublicKey failed", "err", err)
return nil, connect.NewError(connect.CodeInternal, errors.Join(ErrConfig, errors.New("configuration error")))
Expand All @@ -52,22 +52,22 @@ func (p Provider) PublicKey(ctx context.Context, req *connect.Request[kaspb.Publ
defer span.End()
}

algorithm, err := p.CryptoProvider.ParseAlgorithm(req.Msg.GetAlgorithm())
algorithm, err := p.ParseAlgorithm(req.Msg.GetAlgorithm())
if err != nil {
return nil, connect.NewError(connect.CodeNotFound, err)
}
if algorithm == recrypt.AlgorithmUndefined {
algorithm = recrypt.AlgorithmRSA2048
}

kids, err := p.CryptoProvider.CurrentKID(algorithm)
kids, err := p.CurrentKID(algorithm)
if err != nil {
return nil, connect.NewError(connect.CodeNotFound, err)
}
if len(kids) == 0 {
return nil, security.ErrCertNotFound
}
fmt, err := p.CryptoProvider.ParseKeyFormat(req.Msg.GetFmt())
fmt, err := p.ParseKeyFormat(req.Msg.GetFmt())
if err != nil {
return nil, connect.NewError(connect.CodeInvalidArgument, err)
}
Expand All @@ -91,7 +91,7 @@ func (p Provider) PublicKey(ctx context.Context, req *connect.Request[kaspb.Publ
return connect.NewResponse(&kaspb.PublicKeyResponse{PublicKey: value, Kid: string(kid[0])}), nil
}

v, err := p.CryptoProvider.PublicKey(algorithm, kids, fmt)
v, err := p.Provider.PublicKey(algorithm, kids, fmt)
return r(v, kids, err)
}

Expand Down
6 changes: 3 additions & 3 deletions service/kas/access/rewrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,13 @@ func (p *Provider) tdf3Rewrap(ctx context.Context, body *RequestBody, entity *en
}
}
p.Logger.DebugContext(ctx, "paging through legacy KIDs for kid free kao", "kids", kidsToCheck)
symmetricKey, err := p.CryptoProvider.Unwrap(kidsToCheck[0], body.KeyAccess.WrappedKey)
symmetricKey, err := p.Provider.Unwrap(kidsToCheck[0], body.KeyAccess.WrappedKey)
for _, kid := range kidsToCheck[1:] {
if err == nil {
break
}
p.Logger.DebugContext(ctx, "continue paging through legacy KIDs for kid free kao", "err", err, "kid", kid)
symmetricKey, err = p.CryptoProvider.Unwrap(kid, body.KeyAccess.WrappedKey)
symmetricKey, err = p.Provider.Unwrap(kid, body.KeyAccess.WrappedKey)
}
if err != nil {
p.Logger.WarnContext(ctx, "failure to decrypt dek", "err", err)
Expand Down Expand Up @@ -424,7 +424,7 @@ func (p *Provider) nanoTDFRewrap(ctx context.Context, body *RequestBody, entity
}
p.Logger.DebugContext(ctx, "nanoTDFRewrap", "kid", kid)

symmetricKey, err := p.CryptoProvider.Derive(kid, header.EphemeralKey)
symmetricKey, err := p.Provider.Derive(kid, header.EphemeralKey)
if err != nil {
return nil, fmt.Errorf("failed to generate symmetric key: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion service/kas/recrypt/recrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type KeyFormat string
// - Key agreement for nanoTDF and other EC based solutions
//
// This may be Closeable
type CryptoProvider interface {
type Provider interface {
// Return current preferred key identifier(s) for wrapping with the given algorithm.
CurrentKID(alg Algorithm) ([]KeyIdentifier, error)

Expand Down
2 changes: 1 addition & 1 deletion service/kas/recrypt/standard.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type keyHolder struct {
publicPEM []byte
}

// Implementation of the recrypt CryptoProvider interface using standard go crypto primitives.
// Implementation of the recrypt.Provider interface using standard go crypto primitives.
type Standard struct {
keys map[KeyIdentifier]keyHolder
currentKIDsByAlg map[Algorithm][]KeyIdentifier
Expand Down

0 comments on commit b6e78ca

Please sign in to comment.