// Convert the given CREDENTIAL struct to a more usable structure
356563
func sysToCredential(cred *sysCREDENTIAL) (result *Credential) {
	if cred == nil {
		return nil
	}
	result = new(Credential)
	result.Comment = utf16PtrToString(cred.Comment)
	result.TargetName = utf16PtrToString(cred.TargetName)
	result.TargetAlias = utf16PtrToString(cred.TargetAlias)
	result.UserName = utf16PtrToString(cred.UserName)
	result.LastWritten = time.Unix(0, cred.LastWritten.Nanoseconds())
	result.Persist = CredentialPersistence(cred.Persist)
	result.CredentialBlob = goBytes(cred.CredentialBlob, cred.CredentialBlobSize)
	result.Attributes = make([]CredentialAttribute, cred.AttributeCount)
	attrSlice := *(*[]sysCREDENTIAL_ATTRIBUTE)(unsafe.Pointer(&reflect.SliceHeader{
		Data: cred.Attributes,
		Len:  int(cred.AttributeCount),
		Cap:  int(cred.AttributeCount),
	}))
	for i, attr := range attrSlice {
		resultAttr := &result.Attributes[i]
		resultAttr.Keyword = utf16PtrToString(attr.Keyword)
		resultAttr.Value = goBytes(attr.Value, attr.ValueSize)
	}
	return result
}
714329
func NewFloatCredentialValue(f float64) *CredentialValue {
	return &CredentialValue{
		cvtype: floatCV,
		value:  strconv.FormatFloat(f, 'g', -1, 64),
		raw:    f,
	}
}
69640
func Convert_v1alpha1_ExecCredential_To_clientauthentication_ExecCredential(in *ExecCredential, out *clientauthentication.ExecCredential, s conversion.Scope) error {
	return autoConvert_v1alpha1_ExecCredential_To_clientauthentication_ExecCredential(in, out, s)
}
827752
func (c *Client) Credentials(key string, secret string) *Client {
	c.apiKey = key
	c.apiSecret = secret
	return c
}
65814
func NewCredentialNotValid(message string) error {
	err := errors.New("credential not valid: " + message)
	wrapped := errors.Wrap(err, &credentialNotValid{err})
	wrapped.(*errors.Err).SetLocation(1)
	return wrapped
}
579651
func makeGRPCCredentials(m *meta) (creds credentials.TransportCredentials, err error) {
	var config *tls.Config
	if !m.TLSEnabled {
		config = &tls.Config{
			InsecureSkipVerify: true,
		}
	} else {
		cert, err := tls.LoadX509KeyPair(m.CertPath, m.KeyPath)
		if err != nil {
			return nil, fmt.Errorf("unable to setup credentials for plugin - loading key pair failed: %v", err.Error())
		}
		config = tlsSetup.makeTLSConfig()
		config.Certificates = []tls.Certificate{cert}
		if config.ClientCAs, err = tlsSetup.readRootCAs(m.RootCertPaths); err != nil {
			return nil, fmt.Errorf("unable to read root CAs: %v", err.Error())
		}
	}
	creds = credentials.NewTLS(config)
	return creds, nil
}
1027813
func (p environProviderCredentials) FinalizeCredential(
	ctx environs.FinalizeCredentialContext,
	args environs.FinalizeCredentialParams,
) (*cloud.Credential, error) {
	switch authType := args.Credential.AuthType(); authType {
	case cloud.InteractiveAuthType:
		credAttrs := args.Credential.Attributes()
		// We don't care if the password is empty, just that it exists. Empty
		// passwords can be valid ones...
		if _, ok := credAttrs[credAttrTrustPassword]; ok {
			// check to see if the client cert, keys exist, if they do not,
			// generate them for the user.
			if _, ok := getClientCertificates(args.Credential); !ok {
				stderr := ctx.GetStderr()
				nopLogf := func(s string, args ...interface{}) {
					fmt.Fprintf(stderr, s+"\n", args...)
				}
				clientCert, clientKey, err := p.readOrGenerateCert(nopLogf)
				if err != nil {
					return nil, err
				}

				credAttrs[credAttrClientCert] = string(clientCert)
				credAttrs[credAttrClientKey] = string(clientKey)

				credential := cloud.NewCredential(cloud.CertificateAuthType, credAttrs)
				credential.Label = args.Credential.Label

				args.Credential = credential
			}
		}
		fallthrough
	case cloud.CertificateAuthType:
		return p.finalizeCredential(ctx, args)
	default:
		return &args.Credential, nil
	}
}
406244
func Convert_config_CertInfo_To_v1_CertInfo(in *config.CertInfo, out *v1.CertInfo, s conversion.Scope) error {
	return autoConvert_config_CertInfo_To_v1_CertInfo(in, out, s)
}
823046
func sysFromCredential(cred *Credential) (result *sysCREDENTIAL) {
	if cred == nil {
		return nil
	}
	result = new(sysCREDENTIAL)
	result.Flags = 0
	result.Type = 0
	result.TargetName, _ = syscall.UTF16PtrFromString(cred.TargetName)
	result.Comment, _ = syscall.UTF16PtrFromString(cred.Comment)
	result.LastWritten = syscall.NsecToFiletime(cred.LastWritten.UnixNano())
	result.CredentialBlobSize = uint32(len(cred.CredentialBlob))
	if len(cred.CredentialBlob) > 0 {
		result.CredentialBlob = uintptr(unsafe.Pointer(&cred.CredentialBlob[0]))
	} else {
		result.CredentialBlob = 0
	}
	result.Persist = uint32(cred.Persist)
	result.AttributeCount = uint32(len(cred.Attributes))
	attributes := make([]sysCREDENTIAL_ATTRIBUTE, len(cred.Attributes))
	if len(attributes) > 0 {
		result.Attributes = uintptr(unsafe.Pointer(&attributes[0]))
	} else {
		result.Attributes = 0
	}
	for i := range cred.Attributes {
		inAttr := &cred.Attributes[i]
		outAttr := &attributes[i]
		outAttr.Keyword, _ = syscall.UTF16PtrFromString(inAttr.Keyword)
		outAttr.Flags = 0
		outAttr.ValueSize = uint32(len(inAttr.Value))
		if len(inAttr.Value) > 0 {
			outAttr.Value = uintptr(unsafe.Pointer(&inAttr.Value[0]))
		} else {
			outAttr.Value = 0
		}
	}
	result.TargetAlias, _ = syscall.UTF16PtrFromString(cred.TargetAlias)
	result.UserName, _ = syscall.UTF16PtrFromString(cred.UserName)

	return
}
877208
func (api *CredentialManagerAPI) InvalidateModelCredential(args params.InvalidateCredentialArg) (params.ErrorResult, error) {
	err := api.backend.InvalidateModelCredential(args.Reason)
	if err != nil {
		return params.ErrorResult{Error: common.ServerError(err)}, nil
	}
	return params.ErrorResult{}, nil
}
1235602
func parseCredentialHeader(credElement string, region string, stype serviceType) (ch credentialHeader, aec APIErrorCode) {
	creds := strings.SplitN(strings.TrimSpace(credElement), "=", 2)
	if len(creds) != 2 {
		return ch, ErrMissingFields
	}
	if creds[0] != "Credential" {
		return ch, ErrMissingCredTag
	}
	credElements := strings.Split(strings.TrimSpace(creds[1]), "/")
	if len(credElements) < 5 {
		return ch, ErrCredMalformed
	}
	accessKey := strings.Join(credElements[:len(credElements)-4], "/") // The access key may contain one or more `/`
	if !auth.IsAccessKeyValid(accessKey) {
		return ch, ErrInvalidAccessKeyID
	}
	// Save access key id.
	cred := credentialHeader{
		accessKey: accessKey,
	}
	credElements = credElements[len(credElements)-4:]
	var e error
	cred.scope.date, e = time.Parse(yyyymmdd, credElements[0])
	if e != nil {
		return ch, ErrMalformedCredentialDate
	}

	cred.scope.region = credElements[1]
	// Verify if region is valid.
	sRegion := cred.scope.region
	// Region is set to be empty, we use whatever was sent by the
	// request and proceed further. This is a work-around to address
	// an important problem for ListBuckets() getting signed with
	// different regions.
	if region == "" {
		region = sRegion
	}
	// Should validate region, only if region is set.
	if !isValidRegion(sRegion, region) {
		return ch, ErrAuthorizationHeaderMalformed

	}
	if credElements[2] != string(stype) {
		return ch, ErrInvalidService
	}
	cred.scope.service = credElements[2]
	if credElements[3] != "aws4_request" {
		return ch, ErrInvalidRequestVersion
	}
	cred.scope.request = credElements[3]
	return cred, ErrNone
}
36623
func Convert_v1beta1_ExecCredentialSpec_To_clientauthentication_ExecCredentialSpec(in *ExecCredentialSpec, out *clientauthentication.ExecCredentialSpec, s conversion.Scope) error {
	return autoConvert_v1beta1_ExecCredentialSpec_To_clientauthentication_ExecCredentialSpec(in, out, s)
}
1239236
func NewStringCredentialValue(s string) *CredentialValue {
	return &CredentialValue{
		cvtype: stringCV,
		value:  s,
		raw:    s,
	}
}
155336
func (environProviderCredentials) CredentialSchemas() map[cloud.AuthType]cloud.CredentialSchema {
	return map[cloud.AuthType]cloud.CredentialSchema{
		// TODO(axw) we need a more appropriate name for this authentication
		//           type. ssh?
		cloud.UserPassAuthType: {{
			credAttrSDCUser, cloud.CredentialAttr{Description: "SmartDataCenter user ID"},
		}, {
			credAttrSDCKeyID, cloud.CredentialAttr{Description: "SmartDataCenter key ID"},
		}, {
			credAttrPrivateKey, cloud.CredentialAttr{
				Description: "Private key used to sign requests",
				Hidden:      true,
				FileAttr:    "private-key-path",
			},
		}, {
			credAttrAlgorithm, cloud.CredentialAttr{
				Description: "Algorithm used to generate the private key (default rsa-sha256)",
				Optional:    true,
				Options:     []interface{}{"rsa-sha256", "rsa-sha1", "rsa-sha224", "rsa-sha384", "rsa-sha512"},
			},
		}},
	}
}
1154827
func (cgs *credentialGraphSet) HeadCredential(pe *pathexp.PathExp, name string) (envelope.CredentialInf, error) {
	var head envelope.CredentialInf
	version := -1

	gpe, err := pe.WithInstance("*")
	if err != nil {
		return nil, err
	}

	graphs, ok := cgs.graphs[gpe.String()]
	if !ok {
		return nil, nil
	}

	sort.Sort(graphSorter(graphs))
	for _, graph := range graphs {
		creds := graph.GetCredentials()
		for _, cred := range creds {
			if cred.PathExp().Equal(pe) && cred.Name() == name && cred.CredentialVersion() > version {
				env := cred
				head = env
				version = cred.CredentialVersion()
			}
		}
	}

	return head, nil
}
1021262
func NewIntCredentialValue(i int) *CredentialValue {
	return &CredentialValue{
		cvtype: intCV,
		value:  strconv.Itoa(i),
		raw:    i,
	}
}
1171553
func (OpenstackCredentials) CredentialSchemas() map[cloud.AuthType]cloud.CredentialSchema {
	return map[cloud.AuthType]cloud.CredentialSchema{
		cloud.UserPassAuthType: {
			{
				CredAttrUserName, cloud.CredentialAttr{Description: "The username to authenticate with."},
			}, {
				CredAttrPassword, cloud.CredentialAttr{
					Description: "The password for the specified username.",
					Hidden:      true,
				},
			}, {
				CredAttrTenantName, cloud.CredentialAttr{
					Description: "The OpenStack tenant name.",
					Optional:    true,
				},
			}, {
				CredAttrTenantID, cloud.CredentialAttr{
					Description: "The Openstack tenant ID",
					Optional:    true,
				},
			}, {
				CredAttrVersion, cloud.CredentialAttr{
					Description: "The Openstack identity version",
					Optional:    true,
				},
			}, {
				CredAttrDomainName, cloud.CredentialAttr{
					Description: "The OpenStack domain name.",
					Optional:    true,
				},
			}, {
				CredAttrProjectDomainName, cloud.CredentialAttr{
					Description: "The OpenStack project domain name.",
					Optional:    true,
				},
			}, {
				CredAttrUserDomainName, cloud.CredentialAttr{
					Description: "The OpenStack user domain name.",
					Optional:    true,
				},
			},
		},
		cloud.AccessKeyAuthType: {
			{
				CredAttrAccessKey, cloud.CredentialAttr{Description: "The access key to authenticate with."},
			}, {
				CredAttrSecretKey, cloud.CredentialAttr{
					Description: "The secret key to authenticate with.",
					Hidden:      true,
				},
			}, {
				CredAttrTenantName, cloud.CredentialAttr{
					Description: "The OpenStack tenant name.",
					Optional:    true,
				},
			}, {
				CredAttrTenantID, cloud.CredentialAttr{
					Description: "The Openstack tenant ID",
					Optional:    true,
				},
			}, {
				CredAttrVersion, cloud.CredentialAttr{
					Description: "The Openstack identity version",
					Optional:    true,
				},
			},
		},
	}
}