Пример #1
0
// Init initializes this CryptoSigner.
func (s *CryptoSigner) Init(csp bccsp.BCCSP, key bccsp.Key) error {
	// Validate arguments
	if csp == nil {
		return errors.New("Invalid BCCSP. Nil.")
	}
	if key == nil {
		return errors.New("Invalid Key. Nil.")
	}
	if key.Symmetric() {
		return errors.New("Invalid Key. Symmetric.")
	}

	// Marshall the bccsp public key as a crypto.PublicKey
	pub, err := key.PublicKey()
	if err != nil {
		return fmt.Errorf("Failed getting public key [%s]", err)
	}

	raw, err := pub.Bytes()
	if err != nil {
		return fmt.Errorf("Failed marshalling public key [%s]", err)
	}

	pk, err := utils.DERToPublicKey(raw)
	if err != nil {
		return fmt.Errorf("Failed marshalling public key [%s]", err)
	}

	// Init fields
	s.csp = csp
	s.key = key
	s.pk = pk

	return nil

}