...

Source file src/github.com/letsencrypt/boulder/test/inmem/nonce/nonce.go

Documentation: github.com/letsencrypt/boulder/test/inmem/nonce

     1  package inmemnonce
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/letsencrypt/boulder/nonce"
     7  	noncepb "github.com/letsencrypt/boulder/nonce/proto"
     8  	"google.golang.org/grpc"
     9  	"google.golang.org/protobuf/types/known/emptypb"
    10  	"gopkg.in/go-jose/go-jose.v2"
    11  )
    12  
    13  // Service implements noncepb.NonceServiceClient for tests.
    14  type Service struct {
    15  	*nonce.NonceService
    16  }
    17  
    18  var _ noncepb.NonceServiceClient = &Service{}
    19  
    20  // Nonce implements proto.NonceServiceClient
    21  func (imns *Service) Nonce(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*noncepb.NonceMessage, error) {
    22  	n, err := imns.NonceService.Nonce()
    23  	if err != nil {
    24  		return nil, err
    25  	}
    26  	return &noncepb.NonceMessage{Nonce: n}, nil
    27  }
    28  
    29  // Redeem implements proto.NonceServiceClient
    30  func (imns *Service) Redeem(ctx context.Context, in *noncepb.NonceMessage, opts ...grpc.CallOption) (*noncepb.ValidMessage, error) {
    31  	valid := imns.NonceService.Valid(in.Nonce)
    32  	return &noncepb.ValidMessage{Valid: valid}, nil
    33  }
    34  
    35  // AsSource returns a wrapper type that implements jose.NonceSource using this
    36  // inmemory service. This is useful so that tests can get nonces for signing
    37  // their JWS that will be accepted by the test WFE configured using this service.
    38  func (imns *Service) AsSource() jose.NonceSource {
    39  	return nonceServiceAdapter{imns}
    40  }
    41  
    42  // nonceServiceAdapter changes the gRPC nonce service interface to the one
    43  // required by jose. Used only for tests.
    44  type nonceServiceAdapter struct {
    45  	noncepb.NonceServiceClient
    46  }
    47  
    48  // Nonce returns a nonce, implementing the jose.NonceSource interface
    49  func (nsa nonceServiceAdapter) Nonce() (string, error) {
    50  	resp, err := nsa.NonceServiceClient.Nonce(context.Background(), &emptypb.Empty{})
    51  	if err != nil {
    52  		return "", err
    53  	}
    54  	return resp.Nonce, nil
    55  }
    56  
    57  var _ jose.NonceSource = nonceServiceAdapter{}
    58  

View as plain text