// load loads a cached certificate on disk (if it exists), and decoding the PEM
// encoded CERTIFICATE blocks, and loading the appropriate certificate leaf as
// a tls certificate.
162811
func (m *Manager) load() error {
	m.rw.Lock()
	defer m.rw.Unlock()

	domain := strings.TrimSuffix(m.Domain, ".")

	certKey, err := m.cachedKey(domain + keySuffix)
	if err != nil {
		return err
	}

	buf, err := ioutil.ReadFile(filepath.Join(m.CacheDir, domain+certSuffix))
	if err != nil {
		return err
	}

	var b *pem.Block
	var der [][]byte
	for {
		b, buf = pem.Decode(buf)
		if b == nil {
			break
		}
		if b.Type != "CERTIFICATE" {
			return ErrInvalidCertificate
		}
		der = append(der, b.Bytes)
		if buf == nil {
			break
		}
	}
	if len(der) == 0 {
		return ErrInvalidCertificate
	}

	leaf, err := parseCert(domain, der, certKey)
	if err != nil {
		return err
	}

	if time.Now().After(leaf.NotAfter) {
		return ErrCertificateExpired
	}

	m.cert = &tls.Certificate{
		Certificate: der,
		Leaf:        leaf,
		PrivateKey:  certKey,
	}

	return nil
}
1085150
func (b *backend) loadTrustedCerts(ctx context.Context, storage logical.Storage, certName string) (pool *x509.CertPool, trusted []*ParsedCert, trustedNonCAs []*ParsedCert) {
	pool = x509.NewCertPool()
	trusted = make([]*ParsedCert, 0)
	trustedNonCAs = make([]*ParsedCert, 0)
	names, err := storage.List(ctx, "cert/")
	if err != nil {
		b.Logger().Error("failed to list trusted certs", "error", err)
		return
	}
	for _, name := range names {
		// If we are trying to select a single CertEntry and this isn't it
		if certName != "" && name != certName {
			continue
		}
		entry, err := b.Cert(ctx, storage, strings.TrimPrefix(name, "cert/"))
		if err != nil {
			b.Logger().Error("failed to load trusted cert", "name", name, "error", err)
			continue
		}
		parsed := parsePEM([]byte(entry.Certificate))
		if len(parsed) == 0 {
			b.Logger().Error("failed to parse certificate", "name", name)
			continue
		}
		if !parsed[0].IsCA {
			trustedNonCAs = append(trustedNonCAs, &ParsedCert{
				Entry:        entry,
				Certificates: parsed,
			})
		} else {
			for _, p := range parsed {
				pool.AddCert(p)
			}

			// Create a ParsedCert entry
			trusted = append(trusted, &ParsedCert{
				Entry:        entry,
				Certificates: parsed,
			})
		}
	}
	return
}
510298
func (l *MemoryLoader) Load(name string) (Template, error) {
	v, ok := l.Templates[name]
	if !ok {
		return nil, os.ErrNotExist
	}
	return &stringTemplate{name, v}, nil
}
1135525
func (t *TLSConfig) Load() (*tls.Config, error) {
	if t == nil {
		return nil, fmt.Errorf("nil TLS section in config")
	}
	if t.CertFile == nil {
		return nil, fmt.Errorf("nil CertFile in TLSConfig")
	}
	if t.KeyFile == nil {
		return nil, fmt.Errorf("nil KeyFile in TLSConfig")
	}
	if t.CACertFile == nil {
		return nil, fmt.Errorf("nil CACertFile in TLSConfig")
	}
	caCertBytes, err := ioutil.ReadFile(*t.CACertFile)
	if err != nil {
		return nil, fmt.Errorf("reading CA cert from %q: %s", *t.CACertFile, err)
	}
	rootCAs := x509.NewCertPool()
	if ok := rootCAs.AppendCertsFromPEM(caCertBytes); !ok {
		return nil, fmt.Errorf("parsing CA certs from %s failed", *t.CACertFile)
	}
	cert, err := tls.LoadX509KeyPair(*t.CertFile, *t.KeyFile)
	if err != nil {
		return nil, fmt.Errorf("loading key pair from %q and %q: %s",
			*t.CertFile, *t.KeyFile, err)
	}
	return &tls.Config{
		RootCAs:      rootCAs,
		ClientCAs:    rootCAs,
		ClientAuth:   tls.RequireAndVerifyClientCert,
		Certificates: []tls.Certificate{cert},
	}, nil
}
1219859
func (c *baseCache) load(key interface{}, cb func(interface{}, *time.Duration, error) (interface{}, error), isWait bool) (interface{}, bool, error) {
	v, called, err := c.loadGroup.Do(key, func() (v interface{}, e error) {
		defer func() {
			if r := recover(); r != nil {
				e = fmt.Errorf("Loader panics: %v", r)
			}
		}()
		return cb(c.loaderExpireFunc(key))
	}, isWait)
	if err != nil {
		return nil, called, err
	}
	return v, called, nil
}
536298
func Load(db DB, table string, dst interface{}, pk int64) error {
	return Default.Load(db, table, dst, pk)
}
232589
func (s *RediStore) load(session *sessions.Session) (bool, error) {
	conn := s.Pool.Get()
	defer conn.Close()
	if err := conn.Err(); err != nil {
		return false, err
	}
	data, err := conn.Do("GET", s.keyPrefix+session.ID)
	if err != nil {
		return false, err
	}
	if data == nil {
		return false, nil // no data was associated with this key
	}
	b, err := redis.Bytes(data, err)
	if err != nil {
		return false, err
	}
	return true, s.serializer.Deserialize(b, session)
}
628780
func (c *Config) LoadKeyPair() (*tls.Certificate, error) {
	if c.CertFile == "" || c.KeyFile == "" {
		return nil, nil
	}

	if c.KeyLoader == nil {
		return nil, fmt.Errorf("No Keyloader object to perform LoadKeyPair")
	}

	cert, err := c.KeyLoader.LoadKeyPair(c.CertFile, c.KeyFile)
	if err != nil {
		return nil, fmt.Errorf("Failed to load cert/key pair: %v", err)
	}
	return cert, err
}
1048897
func LoadCACerts(c *Config) (*x509.CertPool, error) {
	if c == nil {
		c = &Config{}
	}
	if c.CAFile != "" {
		return LoadCAFile(c.CAFile)
	}
	if c.CAPath != "" {
		return LoadCAPath(c.CAPath)
	}

	return LoadSystemCAs()
}
556395
func LoadCert(filename string) (cert *x509.Certificate, err error) {
	certPEM, err := ioutil.ReadFile(filename)
	if err != nil {
		return
	}
	block, _ := pem.Decode(certPEM)
	if block == nil {
		return nil, fmt.Errorf("No data in cert PEM file %s", filename)
	}
	cert, err = x509.ParseCertificate(block.Bytes)
	return
}
1120005
func (h *handler) Load(r *http.Request) (*Session, error) {
	s := New(h.name, h.keys)

	cookie, err := r.Cookie(h.name)
	if err != nil {
		// No session cookie found, we finish initializing a new one.
		s.Cookie.MaxAge = h.maxAge
		s.Cookie.Domain = h.domain
		s.Cookie.HttpOnly = true

		// When external stores are configured, we want to store the session ID in
		// the cookie to be able to store and retrieve its data.
		if h.store != nil {
			s.Value = genID(idSize)
		}
	} else {
		s.Cookie = cookie
	}

	if r.TLS != nil {
		s.Secure = true
	}

	data := []byte(s.Value)
	if h.store != nil {
		sessionID := s.Value
		data, err = h.store.Load(sessionID)
		if err != nil {
			return s, errors.Wrapf(err, "failed loading session ID: %s", sessionID)
		}
	}

	if err := s.Decode(data); err != nil {
		return s, err
	}

	return s, nil
}
519085
func LoadCertificate(certPath string) (string, error) {
	b, err := ioutil.ReadFile(certPath)
	if err != nil {
		return "", err
	}
	cert := string(b)

	re := regexp.MustCompile("---(.*)CERTIFICATE(.*)---")
	cert = re.ReplaceAllString(cert, "")
	cert = strings.Trim(cert, " \n")
	cert = strings.Replace(cert, "\n", "", -1)

	return cert, nil
}
171257
func (c *config) load() error {
	path, err := c.path()
	if err != nil {
		return nil
	}
	return c.loadFromPath(path)
}
849910
func (c *cache) Load(id string, timeout time.Duration) (Cacheable, error) {
	// Send lookup task.
	responsec := make(responder, 1)
	c.taskc <- lookupTask(id, responsec)
	// Receive response.
	select {
	case response := <-responsec:
		cacheable, err := response()
		return cacheable, err
	case <-time.After(timeout):
		return nil, errors.New(ErrTimeout, errorMessages, "loading")
	}
}
1097252
func (s *String) Load() string {
	v := s.v.Load()
	if v == nil {
		return ""
	}
	return v.(string)
}
21478
func LoadCertificateFromPEM(pem_block []byte) (*Certificate, error) {
	if len(pem_block) == 0 {
		return nil, errors.New("empty pem block")
	}
	runtime.LockOSThread()
	defer runtime.UnlockOSThread()
	bio := C.BIO_new_mem_buf(unsafe.Pointer(&pem_block[0]),
		C.int(len(pem_block)))
	cert := C.PEM_read_bio_X509(bio, nil, nil, nil)
	C.BIO_free(bio)
	if cert == nil {
		return nil, errorFromErrorQueue()
	}
	x := &Certificate{x: cert}
	runtime.SetFinalizer(x, func(x *Certificate) {
		C.X509_free(x.x)
	})
	return x, nil
}
669241
func (j *JSONLoader) Load(s interface{}) error {
	var r io.Reader
	if j.Reader != nil {
		r = j.Reader
	} else if j.Path != "" {
		file, err := getConfig(j.Path)
		if err != nil {
			return err
		}
		defer file.Close()
		r = file
	} else {
		return ErrSourceNotSet
	}

	return json.NewDecoder(r).Decode(s)
}