// CreateCAExtension creates a pkix.Extension for the x509 Basic Constraints
// IsCA field ()
424833
func CreateCAExtension() (pkix.Extension, error) {
	type basicConstraints struct {
		IsCA       bool `asn1:"optional"`
		MaxPathLen int  `asn1:"optional"`
	}
	basicCon := basicConstraints{IsCA: true, MaxPathLen: 0}
	bitstr, err := asn1.Marshal(basicCon)
	if err != nil {
		return pkix.Extension{}, err
	}

	return pkix.Extension{
		Id:       []int{2, 5, 29, 19}, // from x509 package
		Critical: true,
		Value:    bitstr,
	}, nil
}
416543
func (o *L2Domain) CreatePGExpression(child *PGExpression) *bambou.Error {

	return bambou.CurrentSession().CreateChild(o, child)
}
1368604
func CreatePluginSysCCs(p *Provider) []SelfDescribingSysCC {
	var sdscs []SelfDescribingSysCC
	for _, pscc := range loadSysCCs(p) {
		sdscs = append(sdscs, &SysCCWrapper{SCC: pscc})
	}
	return sdscs
}
594558
func (configurationApi *ConfigurationApi) Create(body []byte, options map[string]string) ([]byte, error) {
	request := api.CcaRequest{
		Method:   api.POST,
		Body:     body,
		Endpoint: configurationApi.buildEndpoint(),
		Options:  options,
	}
	response, err := configurationApi.apiClient.Do(request)
	if err != nil {
		return nil, err
	} else if response.IsError() {
		return nil, api.CcaErrorResponse(*response)
	}
	return response.Data, nil
}
881179
func (c *Clientset) ApiextensionsV1beta1() apiextensionsv1beta1.ApiextensionsV1beta1Interface {
	return &fakeapiextensionsv1beta1.FakeApiextensionsV1beta1{Fake: &c.Fake}
}
429183
func CreateConsensusEngine(ctx *node.ServiceContext, chainConfig *params.ChainConfig, config *ethash.Config, notify []string, noverify bool, db ethdb.Database) consensus.Engine {
	// If proof-of-authority is requested, set it up
	if chainConfig.Clique != nil {
		return clique.New(chainConfig.Clique, db)
	}
	// Otherwise assume proof-of-work
	switch config.PowMode {
	case ethash.ModeFake:
		log.Warn("Ethash used in fake mode")
		return ethash.NewFaker()
	case ethash.ModeTest:
		log.Warn("Ethash used in test mode")
		return ethash.NewTester(nil, noverify)
	case ethash.ModeShared:
		log.Warn("Ethash used in shared mode")
		return ethash.NewShared()
	default:
		engine := ethash.New(ethash.Config{
			CacheDir:       ctx.ResolvePath(config.CacheDir),
			CachesInMem:    config.CachesInMem,
			CachesOnDisk:   config.CachesOnDisk,
			DatasetDir:     config.DatasetDir,
			DatasetsInMem:  config.DatasetsInMem,
			DatasetsOnDisk: config.DatasetsOnDisk,
		}, notify, noverify)
		engine.SetThreads(-1) // Disable CPU mining
		return engine
	}
}
397682
func (c *SpaceCodebasesController) Create(ctx *app.CreateSpaceCodebasesContext) error {
	identityID, err := login.ContextIdentity(ctx)
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, goa.ErrUnauthorized(err.Error()))
	}
	// Validate Request
	if ctx.Payload.Data == nil {
		return jsonapi.JSONErrorResponse(ctx, errors.NewBadParameterError("data", nil).Expected("not nil"))
	}
	reqIter := ctx.Payload.Data
	if reqIter.Attributes.Type == nil {
		return jsonapi.JSONErrorResponse(ctx, errors.NewBadParameterError("data.attributes.type", nil).Expected("not nil"))
	}
	if reqIter.Attributes.URL == nil {
		return jsonapi.JSONErrorResponse(ctx, errors.NewBadParameterError("data.attributes.url", nil).Expected("not nil"))
	}
	// the default value of cveScan
	cveScan := false
	if reqIter.Attributes.CveScan != nil {
		cveScan = *reqIter.Attributes.CveScan
	}

	var cdb *codebase.Codebase
	err = application.Transactional(c.db, func(appl application.Application) error {
		sp, err := appl.Spaces().Load(ctx, ctx.SpaceID)
		if err != nil {
			return err
		}
		if *identityID != sp.OwnerID {
			return errors.NewForbiddenError("user is not the space owner")
		}
		cdb = &codebase.Codebase{
			SpaceID: ctx.SpaceID,
			Type:    *reqIter.Attributes.Type,
			URL:     *reqIter.Attributes.URL,
			StackID: reqIter.Attributes.StackID,
			CVEScan: cveScan,
		}
		return appl.Codebases().Create(ctx, cdb)
	})
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, err)
	}

	res := &app.CodebaseSingle{
		Data: ConvertCodebase(ctx.Request, *cdb),
	}
	ctx.ResponseData.Header().Set("Location", rest.AbsoluteURL(ctx.Request, app.CodebaseHref(res.Data.ID)))
	return ctx.Created(res)
}
862177
func newExtensionHandler(params []byte, pers protocol.Perspective) tlsExtensionHandler {
	return &extensionHandler{
		ourParams:   params,
		paramsChan:  make(chan []byte),
		perspective: pers,
	}
}
274348
func parseTypeExtensionDefinition(parser *Parser) (ast.Node, error) {
	start := parser.Token.Start
	_, err := expectKeyWord(parser, lexer.EXTEND)
	if err != nil {
		return nil, err
	}

	definition, err := parseObjectTypeDefinition(parser)
	if err != nil {
		return nil, err
	}
	return ast.NewTypeExtensionDefinition(&ast.TypeExtensionDefinition{
		Loc:        loc(parser, start),
		Definition: definition.(*ast.ObjectDefinition),
	}), nil
}
748465
func (gq *Schema) AddExtensions(e ...Extension) {
	gq.extensions = append(gq.extensions, e...)
}
962309
func (handle *ContextHandle) createNewPKCS11Ctx() *mPkcs11.Ctx {
	newCtx := mPkcs11.New(handle.lib)
	if newCtx == nil {
		logger.Warn("Failed to recreate new context for given library")
		return nil
	}

	//initialize new context
	err := newCtx.Initialize()
	if err != nil {
		if err != mPkcs11.Error(mPkcs11.CKR_CRYPTOKI_ALREADY_INITIALIZED) {
			logger.Warn("Failed to initialize context:", err)
			return nil
		}
	}

	return newCtx
}
749628
func ValidateKubeconfigsForExternalCA(outDir string, cfg *kubeadmapi.InitConfiguration) error {
	kubeConfigFileNames := []string{
		kubeadmconstants.AdminKubeConfigFileName,
		kubeadmconstants.KubeletKubeConfigFileName,
		kubeadmconstants.ControllerManagerKubeConfigFileName,
		kubeadmconstants.SchedulerKubeConfigFileName,
	}

	// Creates a kubeconfig file with the target CA and server URL
	// to be used as a input for validating user provided kubeconfig files
	caCert, err := pkiutil.TryLoadCertFromDisk(cfg.CertificatesDir, kubeadmconstants.CACertAndKeyBaseName)
	if err != nil {
		return errors.Wrapf(err, "the CA file couldn't be loaded")
	}

	controlPlaneEndpoint, err := kubeadmutil.GetControlPlaneEndpoint(cfg.ControlPlaneEndpoint, &cfg.LocalAPIEndpoint)
	if err != nil {
		return err
	}

	validationConfig := kubeconfigutil.CreateBasic(controlPlaneEndpoint, "dummy", "dummy", pkiutil.EncodeCertPEM(caCert))

	// validate user provided kubeconfig files
	for _, kubeConfigFileName := range kubeConfigFileNames {
		if err = validateKubeConfig(outDir, kubeConfigFileName, validationConfig); err != nil {
			return errors.Wrapf(err, "the %s file does not exists or it is not valid", kubeConfigFileName)
		}
	}
	return nil
}
1066366
func createAccess(label string, trustedApplications []string) (C.CFTypeRef, error) {
	var err error
	var labelRef C.CFStringRef
	if labelRef, err = StringToCFString(label); err != nil {
		return nil, err
	}
	defer C.CFRelease(C.CFTypeRef(labelRef))

	var trustedApplicationsArray C.CFArrayRef
	if trustedApplications != nil {
		if len(trustedApplications) > 0 {
			// Always prepend with empty string which signifies that we
			// include a NULL application, which means ourselves.
			trustedApplications = append([]string{""}, trustedApplications...)
		}

		var trustedApplicationsRefs []C.CFTypeRef
		for _, trustedApplication := range trustedApplications {
			trustedApplicationRef, createErr := createTrustedApplication(trustedApplication)
			if createErr != nil {
				return nil, createErr
			}
			defer C.CFRelease(C.CFTypeRef(trustedApplicationRef))
			trustedApplicationsRefs = append(trustedApplicationsRefs, trustedApplicationRef)
		}

		trustedApplicationsArray = ArrayToCFArray(trustedApplicationsRefs)
		defer C.CFRelease(C.CFTypeRef(trustedApplicationsArray))
	}

	var access C.SecAccessRef
	errCode := C.SecAccessCreate(labelRef, trustedApplicationsArray, &access)
	err = checkError(errCode)
	if err != nil {
		return nil, err
	}

	return C.CFTypeRef(access), nil
}
661360
func (c *FakeCertificateSigningRequests) Create(certificateSigningRequest *v1beta1.CertificateSigningRequest) (result *v1beta1.CertificateSigningRequest, err error) {
	obj, err := c.Fake.
		Invokes(testing.NewRootCreateAction(certificatesigningrequestsResource, certificateSigningRequest), &v1beta1.CertificateSigningRequest{})
	if obj == nil {
		return nil, err
	}
	return obj.(*v1beta1.CertificateSigningRequest), err
}
1276456
func (c *consulClient) CreateOnly(ctx context.Context, key string, value []byte, lease bool) (bool, error) {
	k := &consulAPI.KVPair{
		Key:         key,
		Value:       value,
		CreateIndex: 0,
	}

	if lease {
		k.Session = c.lease
	}
	opts := &consulAPI.WriteOptions{}

	duration := spanstat.Start()
	success, _, err := c.KV().CAS(k, opts.WithContext(ctx))
	increaseMetric(key, metricSet, "CreateOnly", duration.EndError(err).Total(), err)
	if err != nil {
		return false, fmt.Errorf("unable to compare-and-swap: %s", err)
	}
	return success, nil
}
525061
func (s *ArchiveOutputSettings) SetExtension(v string) *ArchiveOutputSettings {
	s.Extension = &v
	return s
}
407261
func createRootCAs(tlsCACertFile string, tlsCACertEnvVar []byte, tlsUseSystemCerts bool) (*x509.CertPool, error) {

	var newRootCAs *x509.CertPool

	if tlsUseSystemCerts {
		systemCertPool, err := x509.SystemCertPool()
		if err != nil {
			return nil, err
		}
		newRootCAs = systemCertPool
	} else {
		newRootCAs = x509.NewCertPool()
	}

	if len(tlsCACertFile) > 0 {
		// Append our cert to the system pool
		caCert, err := readCertFromFile(tlsCACertFile)
		if err != nil {
			return nil, err
		}
		if ok := newRootCAs.AppendCertsFromPEM(caCert); !ok {
			return nil, fmt.Errorf("could not append CA cert from %q", tlsCACertFile)
		}
	}

	if len(tlsCACertEnvVar) > 0 {
		// Append our cert to the system pool
		if ok := newRootCAs.AppendCertsFromPEM(tlsCACertEnvVar); !ok {
			return nil, fmt.Errorf("error appending cert from env var %q into system certs", tlsCACertEnvVar)
		}
	}

	return newRootCAs, nil
}