1 Star 0 Fork 0

Hyperledger Fabric 国密/fabric-sdk-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
signer.go 2.17 KB
一键复制 编辑 原始数据 按行查看 历史
Jtyoui 提交于 2021-07-22 20:40 . 改造国密sdk
/*
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
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/hyperledger-fabric-gm/fabric-sdk-go.git
git@gitee.com:hyperledger-fabric-gm/fabric-sdk-go.git
hyperledger-fabric-gm
fabric-sdk-go
fabric-sdk-go
3287af796e9e

搜索帮助