github.com/adecaro/fabric-ca@v2.0.0-alpha+incompatible/lib/server/idemix/cri.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package idemix
     8  
     9  import (
    10  	proto "github.com/golang/protobuf/proto"
    11  	"github.com/hyperledger/fabric-ca/api"
    12  	"github.com/hyperledger/fabric-ca/util"
    13  	"github.com/pkg/errors"
    14  )
    15  
    16  // CRIRequestHandler is the handler for Idemix CRI (credential revocation information) request
    17  type CRIRequestHandler struct {
    18  	Ctx    ServerRequestCtx
    19  	Issuer MyIssuer
    20  }
    21  
    22  // HandleRequest handles processing for idemix/cri request
    23  func (ch *CRIRequestHandler) HandleRequest() (*api.GetCRIResponse, error) {
    24  	_, err := ch.Ctx.TokenAuthentication()
    25  	if err != nil {
    26  		return nil, err
    27  	}
    28  
    29  	cri, err := ch.Issuer.RevocationAuthority().CreateCRI()
    30  	if err != nil {
    31  		return nil, err
    32  	}
    33  	criBytes, err := proto.Marshal(cri)
    34  	if err != nil {
    35  		return nil, errors.New("Failed to marshal Idemix credential to bytes")
    36  	}
    37  	b64CriBytes := util.B64Encode(criBytes)
    38  	res := api.GetCRIResponse{
    39  		CRI: b64CriBytes,
    40  	}
    41  	return &res, nil
    42  }