// LoadPackagedKeypair loads a cert/key pair from the package store
// It looks for the ${name}-[cert,key].pem files from either the PEM dir
// if just a filename is given or from the fullpath if a path is given.
500813
func LoadPackagedKeypair(name string) (cert tls.Certificate, certFile, keyFile string, err error) {
	certFile, err = LocatePackagedPEMFile(name + "-cert")
	if err != nil {
		return
	}
	keyFile, err = LocatePackagedPEMFile(name + "-key")
	if err != nil {
		return
	}
	cert, err = tls.LoadX509KeyPair(certFile, keyFile)
	return
}
491218
func goGetPackageDeps(repo, module string) []string {
	dir, deps := goGetDeps(repo, module)
	return goGetFiles(dir, deps)
}
597394
func LoadPrivateKeyFromPEMWidthPassword(pem_block []byte, password string) (
	PrivateKey, error) {
	return LoadPrivateKeyFromPEMWithPassword(pem_block, password)
}
1017597
func LoadPKFromFile(filename string) (key *PrivateKey, err error) {
	privateKeyData, err := ioutil.ReadFile(filename)
	if err != nil {
		if os.IsNotExist(err) {
			return nil, err
		}
		return nil, fmt.Errorf("Unable to read private key file from file %s: %s", filename, err)
	}
	block, _ := pem.Decode(privateKeyData)
	if block == nil {
		return nil, fmt.Errorf("Unable to decode PEM encoded private key data: %s", err)
	}
	rsaKey, err := x509.ParsePKCS1PrivateKey(block.Bytes)
	if err != nil {
		return nil, fmt.Errorf("Unable to decode X509 private key data: %s", err)
	}
	return &PrivateKey{rsaKey: rsaKey}, nil
}
1002954
func LoadX509Signer(privateKeyPath, certPath string) (*X509Signer, error) {
	pkey, err := ioutil.ReadFile(privateKeyPath)
	if err != nil {
		return nil, err
	}
	cert, err := ioutil.ReadFile(certPath)
	if err != nil {
		return nil, err
	}
	signer := &X509Signer{
		PrivateKeyPEM:  pkey,
		CertificatePEM: cert,
	}
	if err = signer.Validate(); err != nil {
		return nil, err
	}
	return signer, nil
}
210874
func (dcp *diskCertProvider) loadCertAndKey() error {
	cert, err := tls.LoadX509KeyPair(dcp.certPath, dcp.keyPath)
	if err != nil {
		return err
	}

	dcp.Lock()
	defer dcp.Unlock()

	dcp.cert = &cert
	return nil
}
1246446
func (c *dependencyCompiler) resolvePackageDependencies(releasePackage *birelpkg.Package, packageMap map[string]*birelpkg.Package) {
	for _, dependency := range releasePackage.Dependencies {
		// only add un-added packages, to avoid endless looping in case of cycles
		pkgKey := c.pkgKey(dependency)
		if _, found := packageMap[pkgKey]; !found {
			packageMap[pkgKey] = dependency
			c.resolvePackageDependencies(releasePackage, packageMap)
		}
	}
}
975806
func LoadDelegateKeysFromFile(filename string) error {
	pub, priv, err := LoadKeyPairFromFile(filename)
	if err != nil {
		return err
	}
	updateDelegateKeys(pub, priv)
	return nil
}
238647
func LoadKeyPairFromFile(filename string) (public crypto.PublicKey, private crypto.PrivateKey, err error) {
	data, err := ioutil.ReadFile(filename)
	if err != nil {
		return nil, nil, err
	}
	return LoadRSAKeyPairPackage(data)
}
382114
func LoadRSAKeyPairPackage(data []byte) (public crypto.PublicKey, private crypto.PrivateKey, err error) {
	firstblock, rest := pem.Decode(data)
	if firstblock == nil {
		return nil, nil, ErrBadKeysFile
	}
	privatekey, err := RSAPrivateKeyFromPEM(pem.EncodeToMemory(firstblock))
	if err != nil {
		return nil, nil, err
	}
	secondblock, _ := pem.Decode(rest)
	if secondblock == nil {
		return nil, nil, ErrBadKeysFile
	}
	publickey, err := RSAPublicKeyFromPEM(pem.EncodeToMemory(secondblock))
	if err != nil {
		return nil, nil, err
	}
	return publickey, privatekey, nil
}
858782
func (s *Store) Load(hash []byte) (ccInstallPkg []byte, name, version string, err error) {
	hashString := hex.EncodeToString(hash)
	ccInstallPkgPath := filepath.Join(s.Path, hashString+".bin")
	ccInstallPkg, err = s.ReadWriter.ReadFile(ccInstallPkgPath)
	if err != nil {
		err = errors.Wrapf(err, "error reading chaincode install package at %s", ccInstallPkgPath)
		return nil, "", "", err
	}

	metadataPath := filepath.Join(s.Path, hashString+".json")
	name, version, err = s.LoadMetadata(metadataPath)
	if err != nil {
		return nil, "", "", err
	}

	return ccInstallPkg, name, version, nil
}
374083
func TryLoadCertAndKeyFromDisk(pkiPath, name string) (*x509.Certificate, crypto.Signer, error) {
	cert, err := TryLoadCertFromDisk(pkiPath, name)
	if err != nil {
		return nil, nil, errors.Wrap(err, "failed to load certificate")
	}

	key, err := TryLoadKeyFromDisk(pkiPath, name)
	if err != nil {
		return nil, nil, errors.Wrap(err, "failed to load key")
	}

	return cert, key, nil
}
1349790
func (u *CachedUPAKLoader) LoadKeyV2(ctx context.Context, uid keybase1.UID, kid keybase1.KID) (ret *keybase1.UserPlusKeysV2,
	upak *keybase1.UserPlusKeysV2AllIncarnations, key *keybase1.PublicKeyV2NaCl, err error) {
	ctx = WithLogTag(ctx, "LK") // Load key
	defer u.G().CVTraceTimed(ctx, VLog0, fmt.Sprintf("LoadKeyV2 uid:%s,kid:%s", uid, kid), func() error { return err })()
	ctx, tbs := u.G().CTimeBuckets(ctx)
	defer tbs.Record("CachedUPAKLoader.LoadKeyV2")()
	if uid.IsNil() {
		return nil, nil, nil, NoUIDError{}
	}

	argBase := NewLoadUserArg(u.G()).WithUID(uid).WithPublicKeyOptional().WithNetContext(ctx)

	// Make the retry mechanism increasingly aggressive. See CORE-8851.
	// It should be that a ForcePoll is good enough, but in some rare cases,
	// people have cached values for previous pre-reset user incarnations that
	// were incorrect. So clobber over that if it comes to it.
	attempts := []LoadUserArg{
		argBase,
		argBase.WithForcePoll(true),
		argBase.WithForceReload(),
	}

	for i, arg := range attempts {

		if i > 0 {
			u.G().VDL.CLogf(ctx, VLog0, "| reloading with arg: %s", arg.String())
		}

		upak, _, err := u.LoadV2(arg)
		if err != nil {
			return nil, nil, nil, err
		}
		if upak == nil {
			return nil, nil, nil, fmt.Errorf("Nil user, nil error from LoadUser")
		}

		ret, key := upak.FindKID(kid)
		if key != nil {
			u.G().VDL.CLogf(ctx, VLog1, "- found kid in UPAK: %v", ret.Uid)
			return ret, upak, key, nil
		}
	}

	return nil, nil, nil, NotFoundError{Msg: "Not found: Key for user"}
}
50785
func LoadCertBundleFromPEM(pemBytes []byte) ([]*x509.Certificate, error) {
	certificates := []*x509.Certificate{}
	var block *pem.Block
	block, pemBytes = pem.Decode(pemBytes)
	for ; block != nil; block, pemBytes = pem.Decode(pemBytes) {
		if block.Type == "CERTIFICATE" {
			cert, err := x509.ParseCertificate(block.Bytes)
			if err != nil {
				return nil, err
			}
			certificates = append(certificates, cert)
		} else {
			return nil, fmt.Errorf("invalid pem block type: %s", block.Type)
		}
	}

	if len(certificates) == 0 {
		return nil, fmt.Errorf("no valid certificates found")
	}

	return certificates, nil
}
310892
func (k KeybaseServiceMeasured) LoadTeamPlusKeys(ctx context.Context,
	tid keybase1.TeamID, tlfType tlf.Type, desiredKeyGen kbfsmd.KeyGen,
	desiredUser keybase1.UserVersion, desiredKey kbfscrypto.VerifyingKey,
	desiredRole keybase1.TeamRole, offline keybase1.OfflineAvailability) (
	teamInfo idutil.TeamInfo, err error) {
	k.loadTeamPlusKeysTimer.Time(func() {
		teamInfo, err = k.delegate.LoadTeamPlusKeys(
			ctx, tid, tlfType, desiredKeyGen, desiredUser, desiredKey,
			desiredRole, offline)
	})
	return teamInfo, err
}
110193
func LoadCertificateFromPEMBytes(pemBytes []byte) (*Certificate, error) {
	block, _ := pem.Decode(pemBytes)
	if block == nil {
		return nil, fmt.Errorf("Unable to decode PEM encoded certificate")
	}
	return bytesToCert(block.Bytes)
}
449392
func (fkvs *FileKeyValueStore) Load(key interface{}) (interface{}, error) {
	file, err := fkvs.keySerializer(key)
	if err != nil {
		return nil, err
	}
	if _, err1 := os.Stat(file); os.IsNotExist(err1) {
		return nil, core.ErrKeyValueNotFound
	}
	bytes, err := ioutil.ReadFile(file) // nolint: gas
	if err != nil {
		return nil, err
	}
	if bytes == nil {
		return nil, core.ErrKeyValueNotFound
	}
	return fkvs.unmarshaller(bytes)
}