// PublicKeyPinning helps you set the Public-Key-Pins header to prevent
// person-in-the-middle attacks(HPKP).
// See https://developer.mozilla.org/en-US/docs/Web/HTTP/Public_Key_Pinning .
437540
func PublicKeyPinning(options PublicKeyPinningOptions) gear.Middleware {
	if len(options.Sha256s) == 0 {
		panic(gear.Err.WithMsg("empty Public-Key-Pins sha256s"))
	}

	return func(ctx *gear.Context) error {
		publicKeyPins := ""
		for _, sha256 := range options.Sha256s {
			publicKeyPins += fmt.Sprintf(`pin-sha256="%v";`, sha256)
		}
		if options.MaxAge != 0 {
			publicKeyPins += fmt.Sprintf("max-age=%.f;", options.MaxAge.Seconds())
		}
		if options.IncludeSubdomains {
			publicKeyPins += "includeSubDomains;"
		}
		if options.ReportURI != "" {
			publicKeyPins += fmt.Sprintf(`report-uri="%v"`, options.ReportURI)
		}

		if options.ReportOnly {
			ctx.SetHeader(gear.HeaderPublicKeyPinsReportOnly, publicKeyPins)
		} else {
			ctx.SetHeader(gear.HeaderPublicKeyPins, publicKeyPins)
		}
		return nil
	}
}
802586
func (s *Session) publicKey() ([]byte, error) {
	response, err := s.Channel.transmitEncrypted(claSCWallet, insExportKey, exportP1Any, exportP2Pubkey, nil)
	if err != nil {
		return nil, err
	}
	keys := new(keyExport)
	if _, err := asn1.UnmarshalWithParams(response.Data, keys, "tag:1"); err != nil {
		return nil, err
	}
	return keys.PublicKey, nil
}
964973
func publicKeysToSet(publicKeys []string) set.Strings {
	acceptedKeys := set.NewStrings()
	for _, pubKey := range publicKeys {
		// key, comment, options, rest, err
		sshKey, _, _, _, err := ssh.ParseAuthorizedKey([]byte(pubKey))
		if err != nil {
			logger.Warningf("unable to handle public key: %q\n", pubKey)
			continue
		}
		acceptedKeys.Add(string(sshKey.Marshal()))
	}
	return acceptedKeys
}
293013
func publicKeyID(pubKey *packet.PublicKey) string {
	return fmt.Sprintf("%X", pubKey.Fingerprint[len(pubKey.Fingerprint)-4:])
}
358597
func (s *UpdatePublicKeyOutput) SetPublicKey(v *PublicKey) *UpdatePublicKeyOutput {
	s.PublicKey = v
	return s
}
545510
func (s *GetPublicKeyConfigOutput) SetPublicKeyConfig(v *PublicKeyConfig) *GetPublicKeyConfigOutput {
	s.PublicKeyConfig = v
	return s
}
1145085
func (n *Node) Pubkey() *ecdsa.PublicKey {
	var key ecdsa.PublicKey
	if n.Load((*Secp256k1)(&key)) != nil {
		return nil
	}
	return &key
}
510745
func IDFromPublicKey(pk ic.PubKey) (ID, error) {
	b, err := pk.Bytes()
	if err != nil {
		return "", err
	}
	var alg uint64 = mh.SHA2_256
	if AdvancedEnableInlining && len(b) <= maxInlineKeyLength {
		alg = mh.ID
	}
	hash, _ := mh.Sum(b, alg, -1)
	return ID(hash), nil
}
1077714
func TogglePin(pin Pin) {
	p := uint8(pin)

	setReg := p/32 + 7
	clearReg := p/32 + 10
	levelReg := p/32 + 13

	bit := uint32(1 << (p & 31))

	memlock.Lock()

	if (gpioMem[levelReg] & bit) != 0 {
		gpioMem[clearReg] = bit
	} else {
		gpioMem[setReg] = bit
	}
	memlock.Unlock()
}
154705
func (c UserClient) LoadMyPublicKeys(ctx context.Context, sessionID int) (res []PublicKey, err error) {
	__arg := LoadMyPublicKeysArg{SessionID: sessionID}
	err = c.Cli.Call(ctx, "keybase.1.user.loadMyPublicKeys", []interface{}{__arg}, &res)
	return
}
345839
func (c *ClientsetCAStore) AddSSHPublicKey(name string, pubkey []byte) error {
	_, _, _, _, err := ssh.ParseAuthorizedKey(pubkey)
	if err != nil {
		return fmt.Errorf("error parsing SSH public key: %v", err)
	}

	// TODO: Reintroduce or remove
	//// compute fingerprint to serve as id
	//h := md5.New()
	//_, err = h.Write(sshPublicKey.Marshal())
	//if err != nil {
	//	return err
	//}
	//id = formatFingerprint(h.Sum(nil))

	return c.addSshCredential(name, string(pubkey))
}
103883
func (s *GetParametersForImportOutput) SetPublicKey(v []byte) *GetParametersForImportOutput {
	s.PublicKey = v
	return s
}
950066
func (s *CreatePublicKeyInput) SetPublicKeyConfig(v *PublicKeyConfig) *CreatePublicKeyInput {
	s.PublicKeyConfig = v
	return s
}
143606
func (a *oauth) setPkSafe(pk *rsa.PublicKey) {
	a.rwMutex.Lock()
	a.gPkey = pk
	a.rwMutex.Unlock()
}
534661
func (g *GPGKey) GetPublicKey() string {
	if g == nil || g.PublicKey == nil {
		return ""
	}
	return *g.PublicKey
}
201747
func (s *HostKeyAttributes) SetPublicKey(v string) *HostKeyAttributes {
	s.PublicKey = &v
	return s
}
1175253
func (e *Ed25519) PublicKeys(keyIDs ...string) (map[string]data.PublicKey, error) {
	k := make(map[string]data.PublicKey)
	for _, keyID := range keyIDs {
		if edKey, ok := e.keys[keyID]; ok {
			k[keyID] = data.PublicKeyFromPrivate(edKey.privKey)
		}
	}
	return k, nil
}