// Upkeep makes sure the bundle is encrypted for the user's latest PUK.
507779
func Upkeep(mctx libkb.MetaContext) (err error) {
	defer mctx.TraceTimed("Stellar.Upkeep", func() error { return err })()
	_, _, prevAccountPukGens, err := remote.FetchBundleWithGens(mctx)
	if err != nil {
		return err
	}
	pukring, err := mctx.G().GetPerUserKeyring(mctx.Ctx())
	if err != nil {
		return err
	}
	err = pukring.Sync(mctx)
	if err != nil {
		return err
	}
	currentPukGen := pukring.CurrentGeneration()
	var madeAnyChanges bool
	for accountID, accountPukGen := range prevAccountPukGens {
		if accountPukGen < currentPukGen {
			madeAnyChanges = true
			mctx.Debug("Stellar.Upkeep: reencrypting %s... for gen %v from gen %v", accountID[:5], currentPukGen, accountPukGen)
			if err = pushSimpleUpdateForAccount(mctx, accountID); err != nil {
				mctx.Debug("Stellar.Upkeep: error reencrypting %v: %v", accountID[:5], err)
				return err
			}
		}
	}
	if !madeAnyChanges {
		mctx.Debug("Stellar.Upkeep: no need to reencrypt. Everything is at gen %v", currentPukGen)
	}
	return nil
}
587271
func unbox(encBundle stellar1.EncryptedAccountBundle, hash stellar1.Hash /* visB64 string, */, puk libkb.PerUserKeySeed) (*stellar1.AccountBundle, stellar1.AccountBundleVersion, error) {
	versioned, err := decrypt(encBundle, puk)
	if err != nil {
		return nil, 0, err
	}
	version, err := versioned.Version()
	if err != nil {
		return nil, 0, err
	}

	var bundleOut stellar1.AccountBundle
	switch version {
	case stellar1.AccountBundleVersion_V1:
		secretV1 := versioned.V1()
		bundleOut = stellar1.AccountBundle{
			AccountID: secretV1.AccountID,
			Signers:   secretV1.Signers,
		}
	case stellar1.AccountBundleVersion_V2,
		stellar1.AccountBundleVersion_V3,
		stellar1.AccountBundleVersion_V4,
		stellar1.AccountBundleVersion_V5,
		stellar1.AccountBundleVersion_V6,
		stellar1.AccountBundleVersion_V7,
		stellar1.AccountBundleVersion_V8,
		stellar1.AccountBundleVersion_V9,
		stellar1.AccountBundleVersion_V10:
		return nil, 0, errors.New("unsupported AccountBundleSecret version")
	default:
		return nil, 0, errors.New("invalid AccountBundle version")
	}

	bundleOut.OwnHash = hash
	if len(bundleOut.OwnHash) == 0 {
		return nil, 0, errors.New("stellar account bundle missing own hash")
	}

	return &bundleOut, version, nil
}
671537
func (s *DBInstance) SetStorageEncrypted(v bool) *DBInstance {
	s.StorageEncrypted = &v
	return s
}
28021
func (c *ConfigLocal) KeyBundleCache() kbfsmd.KeyBundleCache {
	c.lock.RLock()
	defer c.lock.RUnlock()
	return c.kbcache
}
692849
func (builder *RequestBuilder) SetKeepOrder(order bool) *RequestBuilder {
	builder.Request.KeepOrder = order
	return builder
}
151937
func (a *Authenticator) Maintain(done <-chan struct{}) {
	for {
		select {
		case <-done:
			return
		case <-a.authContext.clock.After(authentication.LocalLoginInteractionTimeout):
			now := a.authContext.clock.Now()
			a.authContext.localUserInteractions.Expire(now)
		}
	}
}
251501
func ChainHashUbiquity(chain []*x509.Certificate) HashUbiquity {
	ret := math.MaxInt32
	for _, cert := range chain {
		uscore := int(hashUbiquity(cert))
		if ret > uscore {
			ret = uscore
		}
	}
	return HashUbiquity(ret)
}
595147
func (s *Config) doUpdatePU(contextID string, pu *policy.PUInfo) error {

	s.Lock()

	data, err := s.versionTracker.LockedModify(contextID, revert, 1)
	if err != nil {
		return fmt.Errorf("unable to find pu %s in cache: %s", contextID, err)
	}

	c := data.(*cacheData)
	if err := s.impl.UpdateRules(c.version, contextID, pu, c.containerInfo); err != nil {
		// Try to clean up, even though this is fatal and it will most likely fail
		s.Unlock()
		s.Unsupervise(contextID) // nolint
		return err
	}

	// Updated the policy in the cached processing unit.
	c.containerInfo.Policy = pu.Policy

	s.Unlock()
	return nil
}
242371
func NewKeepAlive(timeout time.Duration, context Context) *KeepAlive {
	k := KeepAlive{
		timeout: timeout,
		context: context,
	}

	return &k
}
791393
func (w *Wrapper) NewKeepAliver(ctx context.Context) (services.KeepAliver, error) {
	return w.Write.NewKeepAliver(ctx)
}
61885
func UpdateProtectBranch(protectBranch *ProtectBranch) (err error) {
	sess := x.NewSession()
	defer sess.Close()
	if err = sess.Begin(); err != nil {
		return err
	}

	if protectBranch.ID == 0 {
		if _, err = sess.Insert(protectBranch); err != nil {
			return fmt.Errorf("Insert: %v", err)
		}
	}

	if _, err = sess.ID(protectBranch.ID).AllCols().Update(protectBranch); err != nil {
		return fmt.Errorf("Update: %v", err)
	}

	return sess.Commit()
}
87723
func (env *maasEnviron) Storage() storage.Storage {
	env.ecfgMutex.Lock()
	defer env.ecfgMutex.Unlock()
	return env.storageUnlocked
}
1284454
func (c *FakeBundles) Update(bundle *smithv1.Bundle) (result *smithv1.Bundle, err error) {
	obj, err := c.Fake.
		Invokes(testing.NewUpdateAction(bundlesResource, c.ns, bundle), &smithv1.Bundle{})

	if obj == nil {
		return nil, err
	}
	return obj.(*smithv1.Bundle), err
}
745016
func NewWalletUpkeepBackground(g *libkb.GlobalContext, args *WalletUpkeepBackgroundArgs) *WalletUpkeepBackground {
	task := NewBackgroundTask(g, &BackgroundTaskArgs{
		Name:     "WalletUpkeepBackground",
		F:        WalletUpkeepBackgroundRound,
		Settings: WalletUpkeepBackgroundSettings,

		testingMetaCh:     args.testingMetaCh,
		testingRoundResCh: args.testingRoundResCh,
	})
	return &WalletUpkeepBackground{
		Contextified: libkb.NewContextified(g),
		args:         args,
		// Install the task early so that Shutdown can be called before RunEngine.
		task: task,
	}
}
846832
func (s *Store) Protect(value bool) {
	s.Lock()
	defer s.Unlock()

	s.protected = value
}
411236
func (s *RestoreDBInstanceFromS3Input) SetStorageEncrypted(v bool) *RestoreDBInstanceFromS3Input {
	s.StorageEncrypted = &v
	return s
}
832412
func (s *Service) Up(ctx context.Context, options options.Up) error {
	containers, err := s.collectContainers(ctx)
	if err != nil {
		return err
	}

	var imageName = s.imageName()
	if len(containers) == 0 || !options.NoRecreate {
		if err = s.ensureImageExists(ctx, options.NoBuild, options.ForceBuild); err != nil {
			return err
		}
	}

	return s.up(ctx, imageName, true, options)
}