// NewEntity returns a entity with a name, public and private key.
7483
func NewEntity(name string, publicKey, privateKey []byte) Entity {
	return Entity{Name: name, PublicKey: publicKey, PrivateKey: privateKey}
}
483533
func (r *Request) ReadEntity(entityPointer interface{}) (err error) {
	contentType := r.Request.Header.Get(HEADER_ContentType)
	contentEncoding := r.Request.Header.Get(HEADER_ContentEncoding)

	// check if the request body needs decompression
	if ENCODING_GZIP == contentEncoding {
		gzipReader := currentCompressorProvider.AcquireGzipReader()
		defer currentCompressorProvider.ReleaseGzipReader(gzipReader)
		gzipReader.Reset(r.Request.Body)
		r.Request.Body = gzipReader
	} else if ENCODING_DEFLATE == contentEncoding {
		zlibReader, err := zlib.NewReader(r.Request.Body)
		if err != nil {
			return err
		}
		r.Request.Body = zlibReader
	}

	// lookup the EntityReader, use defaultRequestContentType if needed and provided
	entityReader, ok := entityAccessRegistry.accessorAt(contentType)
	if !ok {
		if len(defaultRequestContentType) != 0 {
			entityReader, ok = entityAccessRegistry.accessorAt(defaultRequestContentType)
		}
		if !ok {
			return NewError(http.StatusBadRequest, "Unable to unmarshal content of type:"+contentType)
		}
	}
	return entityReader.Read(r, entityPointer)
}
1000402
func GetEntities(pgpKeys []string) ([]*openpgp.Entity, error) {
	ret := make([]*openpgp.Entity, 0, len(pgpKeys))
	for _, keystring := range pgpKeys {
		data, err := base64.StdEncoding.DecodeString(keystring)
		if err != nil {
			return nil, errwrap.Wrapf("error decoding given PGP key: {{err}}", err)
		}
		entity, err := openpgp.ReadEntity(packet.NewReader(bytes.NewBuffer(data)))
		if err != nil {
			return nil, errwrap.Wrapf("error parsing given PGP key: {{err}}", err)
		}
		ret = append(ret, entity)
	}
	return ret, nil
}
259645
func GenerateNewSecRing(secRing string) (keyID string, err error) {
	ent, err := NewEntity()
	if err != nil {
		return "", fmt.Errorf("generating new identity: %v", err)
	}
	if err := os.MkdirAll(filepath.Dir(secRing), 0700); err != nil {
		return "", err
	}
	f, err := wkfs.OpenFile(secRing, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0600)
	if err != nil {
		return "", err
	}
	err = WriteKeyRing(f, openpgp.EntityList([]*openpgp.Entity{ent}))
	if err != nil {
		f.Close()
		return "", fmt.Errorf("Could not write new key ring to %s: %v", secRing, err)
	}
	if err := f.Close(); err != nil {
		return "", fmt.Errorf("Could not close %v: %v", secRing, err)
	}
	return ent.PrimaryKey.KeyIdString(), nil
}
542288
func (arc AddressResourceConfig) ValidEntity() error {
	//check if protocol set or port not 0
	violations := validation.NewValidationError()
	if arc.Protocol != "" || arc.Port > 0 {
		//some setting, now lets make sure they are valid
		if err := validation.ValidPort(int(arc.Port)); err != nil {
			violations.Add(fmt.Errorf("error AddressResourceConfig: %v", err))
		}

		if err := validation.StringIn(arc.Protocol, commons.TCP, commons.UDP); err != nil {
			violations.Add(fmt.Errorf("error AddressResourceConfig: invalid protocol: %v", err))
		}

	}
	if violations.HasError() {
		return violations
	}
	return nil
}
367179
func (s *MyNewRelic) New(appEnv *cfenv.App) *MyNewRelic {
	serviceName := os.Getenv("NEWRELIC_SERVICE_NAME")
	keyName := os.Getenv("NEWRELIC_KEY_NAME")
	appName := os.Getenv("NEWRELIC_APP_NAME")
	service, err := appEnv.Services.WithName(serviceName)

	if err != nil {
		panic(fmt.Sprintf("new relic service name error: %s", err.Error()))
	}
	s.Key = service.Credentials[keyName].(string)
	s.App = service.Credentials[appName].(string)
	return s
}
514285
func (repo *repo) Create(user service.Entity) bool {
	if dbconn.DB.NewRecord(user) {
		dbconn.DB.Create(&user)
	}
	return !dbconn.DB.NewRecord(user)
}
1347390
func NewECDSAPrivateKey(public PublicKey, private []byte) (*ECDSAPrivateKey, error) {
	switch public.(type) {
	case *ECDSAPublicKey, *ECDSAx509PublicKey:
	default:
		return nil, errors.New("invalid public key type provided to NewECDSAPrivateKey")
	}
	ecdsaPrivKey, err := x509.ParseECPrivateKey(private)
	if err != nil {
		return nil, err
	}
	return &ECDSAPrivateKey{
		PublicKey:  public,
		privateKey: privateKey{private: private},
		signer:     signer{signer: ecdsaPrivKey},
	}, nil
}
850934
func NewKey(namespace string, setName string, key interface{}) (*Key, error) {
	newKey := &Key{
		namespace: namespace,
		setName:   setName,
		userKey:   NewValue(key),
	}

	if err := newKey.computeDigest(); err != nil {
		return nil, err
	}

	return newKey, nil
}
486087
func (s *PolicyGrantingServiceAccess) SetEntityType(v string) *PolicyGrantingServiceAccess {
	s.EntityType = &v
	return s
}
905776
func NewSTSWebIdentity(stsEndpoint string, getWebIDTokenExpiry func() (*WebIdentityToken, error)) (*Credentials, error) {
	if stsEndpoint == "" {
		return nil, errors.New("STS endpoint cannot be empty")
	}
	if getWebIDTokenExpiry == nil {
		return nil, errors.New("Web ID token and expiry retrieval function should be defined")
	}
	return New(&STSWebIdentity{
		Client: &http.Client{
			Transport: http.DefaultTransport,
		},
		stsEndpoint:         stsEndpoint,
		getWebIDTokenExpiry: getWebIDTokenExpiry,
	}), nil
}
333909
func (s *ListAliasesInput) SetEntityId(v string) *ListAliasesInput {
	s.EntityId = &v
	return s
}
1142787
func (s *CreateAliasInput) SetEntityId(v string) *CreateAliasInput {
	s.EntityId = &v
	return s
}
1337557
func (p *ResourcePool) ValidEntity() error {

	trimmedID := strings.TrimSpace(p.ID)
	violations := validation.NewValidationError()
	violations.Add(validation.NotEmpty("Pool.ID", p.ID))
	violations.Add(validation.ValidPoolId(p.ID))
	violations.Add(validation.StringsEqual(p.ID, trimmedID, "leading and trailing spaces not allowed for pool id"))

	trimmedRealm := strings.TrimSpace(p.Realm)
	violations.Add(validation.NotEmpty("Pool.Realm", p.Realm))
	violations.Add(validation.StringsEqual(p.Realm, trimmedRealm, "leading and trailing spaces not allowed for pool realm"))

	if p.ConnectionTimeout < 0 {
		violations.Add(validation.NewViolation(fmt.Sprintf("connection timeout cannot be less than 0")))
	}

	if len(violations.Errors) > 0 {
		return violations
	}
	return nil
}
424573
func (l *Client) GetEntityParams(entitytype, fieldname, fieldval string, fields []string, params url.Values) (*Entity, error) {
	res := ApiResp{}
	data := Entity{}
	entFields := make(map[string]interface{})
	toAppend := ""
	endpointParams := map[string]string{}

	// handle optional endpointParams
	if entitytype == "" {
		entitytype = "user"
	}

	toAppend = fmt.Sprintf("/%s", ":entitytype")
	endpointParams["entitytype"] = entitytype

	if fieldname != "" {
		toAppend = fmt.Sprintf("%s/%s", toAppend, ":fieldname")
		endpointParams["fieldname"] = fieldname

		if fieldval != "" {
			toAppend = fmt.Sprintf("%s/%s", toAppend, ":fieldval")
			endpointParams["fieldval"] = fieldval
		}
	}
	// build dynamic endpoint
	endpoint := fmt.Sprintf("%s%s", entityEndpoint, toAppend)

	// if there are also fields, add them
	if len(fields) > 0 {
		params.Add("fields", strings.Join(fields, ","))
	}

	// make the request
	entityUrl := parseLyticsURL(endpoint, endpointParams)
	err := l.Get(entityUrl, params, nil, &res, &entFields)
	if err != nil {
		return nil, err
	}
	data.Meta = res.Meta
	data.Fields = entFields
	return &data, nil
}
822578
func (r *Registry) PutEntity(parent mo.Entity, item mo.Entity) mo.Entity {
	e := item.Entity()

	if parent != nil {
		e.Parent = &parent.Entity().Self
	}

	r.Put(item)

	return item
}
282475
func New(entity NetworkEntity, frontend bool, UID ...string) *Session {
	s := &Session{
		id:               sessionIDSvc.sessionID(),
		entity:           entity,
		data:             make(map[string]interface{}),
		handshakeData:    nil,
		lastTime:         time.Now().Unix(),
		OnCloseCallbacks: []func(){},
		IsFrontend:       frontend,
	}
	if frontend {
		sessionsByID.Store(s.id, s)
		atomic.AddInt64(&SessionCount, 1)
	}
	if len(UID) > 0 {
		s.uid = UID[0]
	}
	return s
}