// NewPerUserKeyUpgradeBackground creates a PerUserKeyUpgradeBackground engine.
771891
func NewPerUserKeyUpgradeBackground(g *libkb.GlobalContext, args *PerUserKeyUpgradeBackgroundArgs) *PerUserKeyUpgradeBackground {
	task := NewBackgroundTask(g, &BackgroundTaskArgs{
		Name:     "PerUserKeyUpgradeBackground",
		F:        PerUserKeyUpgradeBackgroundRound,
		Settings: PerUserKeyUpgradeBackgroundSettings,

		testingMetaCh:     args.testingMetaCh,
		testingRoundResCh: args.testingRoundResCh,
	})
	return &PerUserKeyUpgradeBackground{
		Contextified: libkb.NewContextified(g),
		args:         args,
		// Install the task early so that Shutdown can be called before RunEngine.
		task: task,
	}
}
771022
func NewPerUserKeyUpkeepBackground(g *libkb.GlobalContext, args *PerUserKeyUpkeepBackgroundArgs) *PerUserKeyUpkeepBackground {
	task := NewBackgroundTask(g, &BackgroundTaskArgs{
		Name:     "PerUserKeyUpkeepBackground",
		F:        PerUserKeyUpkeepBackgroundRound,
		Settings: PerUserKeyUpkeepBackgroundSettings,

		testingMetaCh:     args.testingMetaCh,
		testingRoundResCh: args.testingRoundResCh,
	})
	return &PerUserKeyUpkeepBackground{
		Contextified: libkb.NewContextified(g),
		args:         args,
		// Install the task early so that Shutdown can be called before RunEngine.
		task: task,
	}
}
1260856
func (s *UserService) NewRegisterUserKeysParams(id string) *RegisterUserKeysParams {
	p := &RegisterUserKeysParams{}
	p.p = make(map[string]interface{})
	p.p["id"] = id
	return p
}
151602
func openPerUserKeyPrev(sbox PerUserKeyPrev, symmetricKey NaclSecretBoxKey) (PerUserKeySeed, error) {
	var res PerUserKeySeed

	// decode b64
	msgpacked, err := base64.StdEncoding.DecodeString(string(sbox))
	if err != nil {
		return res, err
	}

	// decode msgpack
	mh := codec.MsgpackHandle{WriteExt: true}
	dec := codec.NewDecoderBytes(msgpacked, &mh)
	var parts struct {
		Version int
		Nonce   []byte
		Sealed  []byte
	}
	err = dec.Decode(&parts)
	if err != nil {
		return res, err
	}

	// check parts
	if parts.Version != 1 {
		return res, fmt.Errorf("per user key secret box version %v != 1", parts.Version)
	}

	if len(parts.Nonce) != NaclDHNonceSize {
		return res, fmt.Errorf("per user key secret box nonce length %v != %v",
			len(parts.Nonce), NaclDHNonceSize)
	}
	var nonce [NaclDHNonceSize]byte
	copy(nonce[:], parts.Nonce)

	expectedSealedLength := PerUserKeySeedSize + secretbox.Overhead
	if len(parts.Sealed) != expectedSealedLength {
		return res, fmt.Errorf("per user key secret box sealed length %v != %v", len(parts.Sealed), expectedSealedLength)
	}

	// open secretbox
	var symmetricKey2 [NaclSecretBoxKeySize]byte = symmetricKey
	contents, ok := secretbox.Open(nil, parts.Sealed, &nonce, &symmetricKey2)
	if !ok {
		return res, errors.New("per user key secret box open failed")
	}
	if len(contents) != PerUserKeySeedSize {
		return res, fmt.Errorf("per user key seed length %v != %v", len(contents), PerUserKeySeedSize)
	}
	return MakeByte32(contents), nil
}
350001
func (md *RootMetadata) KeyGenerationsToUpdate() (kbfsmd.KeyGen, kbfsmd.KeyGen) {
	return md.bareMd.KeyGenerationsToUpdate()
}
1215907
func NewUpgradeCharmCommand() cmd.Command {
	cmd := &upgradeCharmCommand{
		DeployResources: resourceadapters.DeployResources,
		ResolveCharm:    resolveCharm,
		NewCharmAdder:   newCharmAdder,
		NewCharmClient: func(conn base.APICallCloser) CharmClient {
			return charms.NewClient(conn)
		},
		NewCharmUpgradeClient: func(conn base.APICallCloser) CharmAPIClient {
			return application.NewClient(conn)
		},
		NewModelConfigGetter: func(conn base.APICallCloser) ModelConfigGetter {
			return modelconfig.NewClient(conn)
		},
		NewResourceLister: func(conn base.APICallCloser) (ResourceLister, error) {
			resclient, err := resourceadapters.NewAPIClient(conn)
			if err != nil {
				return nil, err
			}
			return resclient, nil
		},
		CharmStoreURLGetter: getCharmStoreAPIURL,
	}
	return modelcmd.Wrap(cmd)
}
1045342
func (s *PerUserKeyring) PreparePrev(m MetaContext, newSeed PerUserKeySeed,
	newGeneration keybase1.PerUserKeyGeneration) (PerUserKeyPrev, error) {
	s.Lock()
	defer s.Unlock()

	if newSeed.IsBlank() {
		return "", errors.New("attempt to prev with blank per-user-key")
	}

	currentGen := s.currentGenerationLocked()
	if currentGen == 0 {
		return "", errors.New("attempt to prepare per-user-key prev with no keys")
	}
	if currentGen != newGeneration-1 {
		return "", fmt.Errorf("incompatible prev generations %v != %v-1", currentGen, newGeneration)
	}

	symmetricKey, err := newSeed.derivePrevKey()
	if err != nil {
		return "", err
	}

	contents := s.generations[currentGen].seed

	return newPerUserKeyPrev(contents, symmetricKey)
}
824989
func (c *Client) UpsertUser(user services.User) error {
	data, err := services.GetUserMarshaler().MarshalUser(user)
	if err != nil {
		return trace.Wrap(err)
	}
	_, err = c.PostJSON(c.Endpoint("users"), &upsertUserRawReq{User: data})
	return trace.Wrap(err)
}
517255
func NewMockUpgrader(ctrl *gomock.Controller) *MockUpgrader {
	mock := &MockUpgrader{ctrl: ctrl}
	mock.recorder = &MockUpgraderMockRecorder{mock}
	return mock
}
331016
func (u UserPlusKeysV2) GetPerUserKeyByGen(gen PerUserKeyGeneration) *PerUserKey {
	genint := int(gen)
	if genint <= 0 || genint > len(u.PerUserKeys) {
		return nil
	}
	puk := u.PerUserKeys[genint-1]
	if puk.Gen != genint {
		// The PerUserKeys field of this object is malformed
		return nil
	}
	return &puk
}
1014445
func (l *Logger) newBackground(qtyConsumer int) error {
	if qtyConsumer < 1 {
		qtyConsumer = 1
	}
	var consumers []*background
	consumers = make([]*background, 0, 0)
	ch := make(chan *event)
	for i := 0; i < qtyConsumer; i++ {
		var a = &background{
			ch:     ch,
			url:    l.baseURL,
			apiKey: l.APIKey,
		}
		consumers = append(consumers, a)
		a.wg.Add(1)

		l.background = consumers
		l.channel = ch

		errCh := make(chan error)

		go func() {
			errCh <- a.initBackground()
		}()

		select {
		case err := <-errCh:
			return err
		}
	}
	return nil
}
1084587
func NewLeveldbAuthBackend(filepath string) (b LeveldbAuthBackend, e error) {
	b.filepath = filepath
	if _, err := os.Stat(b.filepath); err == nil {
		db, err := leveldb.OpenFile(b.filepath, nil)
		defer db.Close()
		if err != nil {
			return b, fmt.Errorf("leveldbauthbackend: %v", err.Error())
		}
		data, err := db.Get([]byte("httpauth::userdata"), nil)
		err = json.Unmarshal(data, &b.users)
		if err != nil {
			b.users = make(map[string]UserData)
		}
	} else {
		return b, ErrMissingLeveldbBackend
	}
	if b.users == nil {
		b.users = make(map[string]UserData)
	}
	return b, nil
}
735150
func NewUpgrader(toSeries string, manager service.SystemdServiceManager, logger Logger) (Upgrader, error) {
	fromSeries, err := hostSeries()
	if err != nil {
		return nil, errors.Trace(err)
	}
	fromInit, err := service.VersionInitSystem(fromSeries)
	if err != nil {
		return nil, errors.Trace(err)
	}

	toInit, err := service.VersionInitSystem(toSeries)
	if err != nil {
		return nil, errors.Trace(err)
	}

	return &upgrader{
		logger:     logger,
		fromSeries: fromSeries,
		fromInit:   fromInit,
		toSeries:   toSeries,
		toInit:     toInit,
		manager:    manager,
	}, nil
}
679452
func (pgb *ChainDB) handleAgendasTableUpgrade(msgBlock *wire.MsgBlock) (int64, error) {
	// neither isValid or isMainchain are important
	dbTxns, _, _ := dbtypes.ExtractBlockTransactions(msgBlock,
		wire.TxTreeStake, pgb.chainParams, true, false)

	var rowsUpdated int64
	for i, tx := range dbTxns {
		if tx.TxType != int16(stake.TxTypeSSGen) {
			continue
		}
		_, _, _, choices, err := txhelpers.SSGenVoteChoices(msgBlock.STransactions[i],
			pgb.chainParams)
		if err != nil {
			return 0, err
		}

		var rowID uint64
		for _, val := range choices {
			// check if agenda id exists, if not it skips to the next agenda id
			var progress, ok = votingMilestones[val.ID]
			if !ok {
				log.Debugf("The Agenda ID: '%s' is unknown", val.ID)
				continue
			}

			var index, err = dbtypes.ChoiceIndexFromStr(val.Choice.Id)
			if err != nil {
				return 0, err
			}

			err = pgb.db.QueryRow(internal.MakeAgendaInsertStatement(false),
				val.ID, index, tx.TxID, tx.BlockHeight, tx.BlockTime,
				progress.VotingDone == tx.BlockHeight,
				progress.Activated == tx.BlockHeight,
				progress.HardForked == tx.BlockHeight).Scan(&rowID)
			if err != nil {
				return 0, err
			}

			rowsUpdated++
		}
	}
	return rowsUpdated, nil
}
1248700
func NewUserProfileService(context servicecontext.ServiceContext) service.UserProfileService {
	return &userProfileService{
		client: http.DefaultClient,
	}
}
613564
func (api *Client) UpdateUserGroup(userGroup UserGroup) (UserGroup, error) {
	return api.UpdateUserGroupContext(context.Background(), userGroup)
}
961727
func NewKeyManager() *KeyManager {
	return &KeyManager{
		dirtmap: make(map[Key]Key),
		mapper:  make(map[Key]KeyState),
	}
}