ecc.go
func NewEllipticSigner(alg Algorithm, curve elliptic.Curve) func(Store, crypto.Hash) (Signer, error) {
	curveBitSize := curve.Params().BitSize

	// precompute curve key len
	keyLen := curveBitSize / 8
	if curveBitSize%8 > 0 {
		keyLen++
	}

	return func(store Store, hash crypto.Hash) (Signer, error) {
		var ok bool
		var privRaw, pubRaw interface{}
		var priv *ecdsa.PrivateKey
		var pub *ecdsa.PublicKey

		// check private key
		if privRaw, ok = store.PrivateKey(); ok {
			if priv, ok = privRaw.(*ecdsa.PrivateKey); !ok {
				return nil, ErrInvalidPrivateKey
			}

			// check curve type matches private key curve type
			if curveBitSize != priv.Curve.Params().BitSize {
				return nil, ErrInvalidPrivateKeySize
			}
		}

		// check public key
		if pubRaw, ok = store.PublicKey(); ok {
			if pub, ok = pubRaw.(*ecdsa.PublicKey); !ok {
				return nil, ErrInvalidPublicKey
			}
		}

		// check that either a private or public key has been provided
		if priv == nil && pub == nil {
			return nil, ErrMissingPrivateOrPublicKey
		}

		return &EccSigner{
			alg:    alg,
			curve:  curve,
			hash:   hash,
			priv:   priv,
			pub:    pub,
			keyLen: keyLen,
		}, nil
	}
}
func NewEllipticSigner(alg Algorithm, curve elliptic.Curve) func(Store, crypto.Hash) (Signer, error) {
	curveBitSize := curve.Params().BitSize

	// precompute curve key len
	keyLen := curveBitSize / 8
	if curveBitSize%8 > 0 {
		keyLen++
	}

	return func(store Store, hash crypto.Hash) (Signer, error) {
		var ok bool
		var privRaw, pubRaw interface{}
		var priv *ecdsa.PrivateKey
		var pub *ecdsa.PublicKey

		// check private key
		if privRaw, ok = store.PrivateKey(); ok {
			if priv, ok = privRaw.(*ecdsa.PrivateKey); !ok {
				return nil, ErrInvalidPrivateKey
			}

			// check curve type matches private key curve type
			if curveBitSize != priv.Curve.Params().BitSize {
				return nil, ErrInvalidPrivateKeySize
			}
		}

		// check public key
		if pubRaw, ok = store.PublicKey(); ok {
			if pub, ok = pubRaw.(*ecdsa.PublicKey); !ok {
				return nil, ErrInvalidPublicKey
			}
		}

		// check that either a private or public key has been provided
		if priv == nil && pub == nil {
			return nil, ErrMissingPrivateOrPublicKey
		}

		return &EccSigner{
			alg:    alg,
			curve:  curve,
			hash:   hash,
			priv:   priv,
			pub:    pub,
			keyLen: keyLen,
		}, nil
	}
}
func NewEllipticSigner ( alg Algorithm , curve elliptic . Curve ) func ( Store , crypto . Hash ) ( Signer , error ) { curveBitSize := curve . Params ( ) . BitSize // precompute curve key len keyLen := curveBitSize / 8 if curveBitSize % 8 > 0 { keyLen ++ } return func ( store Store , hash crypto . Hash ) ( Signer , error ) { var ok bool var privRaw , pubRaw interface { } var priv * ecdsa . PrivateKey var pub * ecdsa . PublicKey // check private key if privRaw , ok = store . PrivateKey ( ) ; ok { if priv , ok = privRaw . ( * ecdsa . PrivateKey ) ; ! ok { return nil , ErrInvalidPrivateKey } // check curve type matches private key curve type if curveBitSize != priv . Curve . Params ( ) . BitSize { return nil , ErrInvalidPrivateKeySize } } // check public key if pubRaw , ok = store . PublicKey ( ) ; ok { if pub , ok = pubRaw . ( * ecdsa . PublicKey ) ; ! ok { return nil , ErrInvalidPublicKey } } // check that either a private or public key has been provided if priv == nil && pub == nil { return nil , ErrMissingPrivateOrPublicKey } return & EccSigner { alg : alg , curve : curve , hash : hash , priv : priv , pub : pub , keyLen : keyLen , } , nil } }
// NewEllipticSigner creates an Elliptic Curve Signer for the specified curve.
NewEllipticSigner creates an Elliptic Curve Signer for the specified curve .