...

Source file src/github.com/letsencrypt/boulder/goodkey/sagoodkey/good_key.go

Documentation: github.com/letsencrypt/boulder/goodkey/sagoodkey

     1  package sagoodkey
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/letsencrypt/boulder/goodkey"
     7  	sapb "github.com/letsencrypt/boulder/sa/proto"
     8  	"google.golang.org/grpc"
     9  )
    10  
    11  // BlockedKeyCheckFunc is used to pass in the sa.BlockedKey method to KeyPolicy,
    12  // rather than storing a full sa.SQLStorageAuthority. This makes testing
    13  // significantly simpler.
    14  type BlockedKeyCheckFunc func(context.Context, *sapb.KeyBlockedRequest, ...grpc.CallOption) (*sapb.Exists, error)
    15  
    16  // NewKeyPolicy returns a KeyPolicy that uses a sa.BlockedKey method.
    17  // See goodkey.NewKeyPolicy for more details about the policy itself.
    18  func NewKeyPolicy(config *goodkey.Config, bkc BlockedKeyCheckFunc) (goodkey.KeyPolicy, error) {
    19  	var genericCheck goodkey.BlockedKeyCheckFunc
    20  	if bkc != nil {
    21  		genericCheck = func(ctx context.Context, keyHash []byte) (bool, error) {
    22  			exists, err := bkc(ctx, &sapb.KeyBlockedRequest{KeyHash: keyHash})
    23  			if err != nil {
    24  				return false, err
    25  			}
    26  			return exists.Exists, nil
    27  		}
    28  	}
    29  
    30  	return goodkey.NewKeyPolicy(config, genericCheck)
    31  }
    32  

View as plain text