代码拉取完成,页面将自动刷新
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
/*
Notice: This file has been modified for Hyperledger Fabric SDK Go usage.
Please review third_party pinning scripts and patches for more details.
*/
package x509
import (
"crypto/x509"
"fmt"
"gitee.com/hyperledger-fabric-gm/fabric-sdk-go/pkg/common/providers/core"
"gitee.com/hyperledger-fabric-gm/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/lib/attrmgr"
"gitee.com/hyperledger-fabric-gm/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/sdkinternal/pkg/util"
"github.com/pkg/errors"
)
// NewSigner is constructor for Signer
func NewSigner(key core.Key, cert []byte) (*Signer, error) {
s := &Signer{
key: key,
certBytes: cert,
}
var err error
s.cert, err = util.GetX509CertificateFromPEM(s.certBytes)
if err != nil {
return nil, errors.WithMessage(err, "Failed to unmarshal X509 certificate bytes")
}
s.name = util.GetEnrollmentIDFromX509Certificate(s.cert)
return s, nil
}
// Signer represents a signer
// Each identity may have multiple signers and currently one ecert
type Signer struct {
// Private key
key core.Key
// Certificate bytes
certBytes []byte
// X509 certificate that is constructed from the cert bytes associated with this signer
cert *x509.Certificate
// Common name from the certificate associated with this signer
name string
}
// Key returns the key bytes of this signer
func (s *Signer) Key() core.Key {
return s.key
}
// Cert returns the cert bytes of this signer
func (s *Signer) Cert() []byte {
return s.certBytes
}
// GetX509Cert returns the X509 certificate for this signer
func (s *Signer) GetX509Cert() *x509.Certificate {
return s.cert
}
// GetName returns common name that is retrieved from the Subject of the certificate
// associated with this signer
func (s *Signer) GetName() string {
return s.name
}
// Attributes returns the attributes that are in the certificate
func (s *Signer) Attributes() (*attrmgr.Attributes, error) {
cert := s.GetX509Cert()
attrs, err := attrmgr.New().GetAttributesFromCert(cert)
if err != nil {
return nil, fmt.Errorf("Failed getting attributes for '%s': %s", s.name, err)
}
return attrs, nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。