// XXX: panics on nil or unknown pubkey type
// TODO: add cases when new pubkey types are added to crypto
544302
func (tm2pb) PubKey(pubKey crypto.PubKey) abci.PubKey {
	switch pk := pubKey.(type) {
	case ed25519.PubKeyEd25519:
		return abci.PubKey{
			Type: ABCIPubKeyTypeEd25519,
			Data: pk[:],
		}
	case secp256k1.PubKeySecp256k1:
		return abci.PubKey{
			Type: ABCIPubKeyTypeSecp256k1,
			Data: pk[:],
		}
	default:
		panic(fmt.Sprintf("unknown pubkey type: %v %v", pubKey, reflect.TypeOf(pubKey)))
	}
}
382311
func (entry *Entry) Panic(args ...interface{}) {
	if entry.lgEntry.Logger.Level >= lg.PanicLevel {
		entry.lgEntry.WithFields(entry.fields).Panic(args...)
	}
}
1094646
func Panicf(format string, v ...interface{}) {
	std.Fprint(std.flags, LEVEL_CRITICAL, 2, fmt.Sprintf(format, v...), nil)
	panic(v)
}
1354006
func unmarshalECKey(curve elliptic.Curve, pubkey []byte) (x, y *big.Int, err error) {
	x, y = elliptic.Unmarshal(curve, pubkey)
	if x == nil {
		return nil, nil, errors.New("ssh: elliptic.Unmarshal failure")
	}
	if !validateECPublicKey(curve, x, y) {
		return nil, nil, errors.New("ssh: public key not on curve")
	}
	return x, y, nil
}
1325428
func Panic(err error, msgs ...string) {
	if err != nil {
		if len(msgs) > 0 {
			panic(strings.Join(msgs, ",") + err.Error())
		} else {
			panic(err)
		}
	}
}
1120676
func ParsePublicKey(in []byte) (index []byte, ok bool, key PublicKey) {
	var typeTag uint16
	index, typeTag, ok = gotrax.ExtractShort(in)
	if !ok {
		return in, false, nil
	}

	switch typeTag {
	case dsaKeyTypeValue:
		key = &DSAPublicKey{}
		index, ok = key.Parse(in)
		return
	}

	return in, false, nil
}
89077
func NewKeyValueExpr(k, v Expr, pos Pos) *KeyValueExpr {
	return &KeyValueExpr{pos, k, v}
}
1284220
func ByUserIndexKeys(obj interface{}) ([]string, error) {
	group, ok := obj.(*userapi.Group)
	if !ok {
		return nil, fmt.Errorf("unexpected type: %v", obj)
	}

	return group.Users, nil
}
46091
func (i *i) PanicWith(m string, fn func()) {
	var r interface{}
	func() {
		defer func() {
			r = recover()
		}()
		fn()
	}()
	if r != m {
		i.Logf("expected panic: \"%s\"", m)
	}
}
554762
func (e Entry) Panic(v ...interface{}) {
	e.Message = fmt.Sprint(v...)
	e.Level = PanicLevel
	HandleEntry(e)
	exitFunc(1)
}
1211563
func NewRSAPKCSKeyEncrypt(alg jwa.KeyEncryptionAlgorithm, pubkey *rsa.PublicKey) (*RSAPKCSKeyEncrypt, error) {
	switch alg {
	case jwa.RSA1_5:
	default:
		return nil, errors.Wrap(ErrUnsupportedAlgorithm, "invalid RSA PKCS encrypt algorithm")
	}

	return &RSAPKCSKeyEncrypt{
		alg:    alg,
		pubkey: pubkey,
	}, nil
}
978708
func (a *managedAddress) pubKeyBytes() []byte {
	if a.compressed {
		return a.pubKey.SerializeCompressed()
	}
	return a.pubKey.SerializeUncompressed()
}
1033184
func (pk *PublicKeyV3) SerializeSignaturePrefix(w io.Writer) {
	var pLength uint16
	switch pk.PubKeyAlgo {
	case PubKeyAlgoRSA, PubKeyAlgoRSAEncryptOnly, PubKeyAlgoRSASignOnly:
		pLength += 2 + uint16(len(pk.n.bytes))
		pLength += 2 + uint16(len(pk.e.bytes))
	default:
		panic("unknown public key algorithm")
	}
	pLength += 6
	w.Write([]byte{0x99, byte(pLength >> 8), byte(pLength)})
	return
}
1062196
func (m *tokenManager) PublicKeys() []*rsa.PublicKey {
	keys := make([]*rsa.PublicKey, 0, len(m.publicKeysMap))
	for _, key := range m.publicKeys {
		keys = append(keys, key.Key)
	}
	return keys
}
321114
func (vm *Engine) checkPubKeyEncoding(pubKey []byte) error {
	if vm.hasFlag(ScriptVerifyWitnessPubKeyType) &&
		vm.isWitnessVersionActive(0) && !btcec.IsCompressedPubKey(pubKey) {

		str := "only uncompressed keys are accepted post-segwit"
		return scriptError(ErrWitnessPubKeyType, str)
	}

	if !vm.hasFlag(ScriptVerifyStrictEncoding) {
		return nil
	}

	if len(pubKey) == 33 && (pubKey[0] == 0x02 || pubKey[0] == 0x03) {
		// Compressed
		return nil
	}
	if len(pubKey) == 65 && pubKey[0] == 0x04 {
		// Uncompressed
		return nil
	}

	return scriptError(ErrPubKeyType, "unsupported public key type")
}
932881
func determinePublicKey(sig, pubkeyX []byte) ([]byte, error) {
	for v := 0; v < 2; v++ {
		sig[64] = byte(v)
		pubkey, err := crypto.Ecrecover(DerivationSignatureHash[:], sig)
		if err == nil {
			if bytes.Equal(pubkey, pubkeyX) {
				return pubkey, nil
			}
		} else if v == 1 || err != secp256k1.ErrRecoverFailed {
			return nil, err
		}
	}
	return nil, ErrPubkeyMismatch
}
880992
func (a *Assertion) Panic(fn func(), msg ...interface{}) *Assertion {
	Panic(a.t, fn, msg...)
	return a
}