// copied more or less from loginProvision.paper()
357713
func (e *PaperProvisionEngine) paper(m libkb.MetaContext, keys *libkb.DeviceWithKeys) error {
	// After obtaining login session, this will be called before the login state is released.
	// It signs this new device with the paper key.
	u := e.User
	nn := u.GetNormalizedName()
	uv := u.ToUserVersion()

	// Set the active device to be a special paper key active device, which keeps
	// a cached copy around for DeviceKeyGen, which requires it to be in memory.
	// It also will establish a NIST so that API calls can proceed on behalf of the user.
	m = m.WithProvisioningKeyActiveDevice(keys, uv)
	m.LoginContext().SetUsernameUserVersion(nn, uv)

	// need lksec to store device keys locally
	if err := e.fetchLKS(m, keys.EncryptionKey()); err != nil {
		return err
	}

	if err := e.makeDeviceKeysWithSigner(m, keys.SigningKey()); err != nil {
		return err
	}

	// Cache the paper keys globally now that we're logged in
	m = m.WithGlobalActiveDevice()
	m.ActiveDevice().CacheProvisioningKey(m, keys)

	return nil
}
13207
func (self *SimplePageMapper) LoginLandingPage(conn OauthConnector, state string, code string) string {
	v := url.Values{
		"service": []string{conn.Name()},
		"state":   []string{state},
	}
	return fmt.Sprintf("%s?%s", self.loginOk, v.Encode())
}
223023
func NewScribble(url *url.URL) (Authenticator, error) {

	// get the desired location of the scribble database
	dir := url.Query().Get("db")

	// if no database location is provided, fail
	if dir == "" {
		return nil, fmt.Errorf("Missing database location in scheme (?db=)")
	}

	// create a new scribble database at the specified location
	db, err := scribbleDB.New(dir, nil)
	if err != nil {
		return nil, err
	}

	return &scribble{driver: db}, nil
}
880050
func checkPropsExist(loginDoc map[string]interface{}) error {
	// Make sure the user provides a username
	id, ok := loginDoc["username"].(string)
	if ok != true {
		return errors.New("Need username to login")
	} else if len(id) < variables.ShortestUsername {
		// FIXME: Make concatination constant
		return errors.New("Username must be at least " + strconv.Itoa(variables.ShortestUsername))
	}
	// Make sure the user provides a password
	password, ok := loginDoc["password"].(string)
	if ok != true {
		return errors.New("Need password to login")
	} else if len(password) < variables.ShortestPassword {
		// FIXME: Make concatination constant
		return errors.New("Password must be at least " + strconv.Itoa(variables.ShortestPassword))
	}
	return nil
}
142714
func NewPaperContentRemoveMemberDetails(EventUuid string) *PaperContentRemoveMemberDetails {
	s := new(PaperContentRemoveMemberDetails)
	s.EventUuid = EventUuid
	return s
}
1056606
func SortByRevision(list []*rspb.Release) {
	s := &sorter{list: list}
	s.less = func(i, j int) bool {
		vi := s.list[i].Version
		vj := s.list[j].Version
		return vi < vj
	}
	sort.Sort(s)
}
355959
func (rm *RoleManager) PrintRoles() error {
	line := ""
	rm.allRoles.Range(func(_, value interface{}) bool {
		if text := value.(*Role).toString(); text != "" {
			if line == "" {
				line = text
			} else {
				line += ", " + text
			}
		}
		return true
	})
	log.LogPrint(line)
	return nil
}
412330
func printDocumentV3(code *printer.Code, document *openapiv3.Document) {
	code.Print("OpenAPI: %+v", document.Openapi)
	code.Print("Servers: %+v", document.Servers)
	if document.Info != nil {
		code.Print("Info:")
		code.Indent()
		if document.Info.Title != "" {
			code.Print("Title: %s", document.Info.Title)
		}
		if document.Info.Description != "" {
			code.Print("Description: %s", document.Info.Description)
		}
		if document.Info.Version != "" {
			code.Print("Version: %s", document.Info.Version)
		}
		code.Outdent()
	}
	code.Print("Paths:")
	code.Indent()
	for _, pair := range document.Paths.Path {
		v := pair.Value
		if v.Get != nil {
			code.Print("GET %+v", pair.Name)
		}
		if v.Post != nil {
			code.Print("POST %+v", pair.Name)
		}
	}
	code.Outdent()
}
1243334
func (sra ShardReferenceArray) Less(i, j int) bool {
	if sra[i].KeyRange == nil || len(sra[i].KeyRange.Start) == 0 {
		return true
	}
	if sra[j].KeyRange == nil || len(sra[j].KeyRange.Start) == 0 {
		return false
	}
	return bytes.Compare(sra[i].KeyRange.Start, sra[j].KeyRange.Start) < 0
}
677322
func (th *TlfHistory) FlushRevision(rev kbfsmd.Revision) {
	th.lock.Lock()
	defer th.lock.Unlock()
	if th.unflushed == nil {
		return
	}
	lastToKeep := len(th.unflushed.notifications) - 1
	for ; lastToKeep >= 0; lastToKeep-- {
		if th.unflushed.notifications[lastToKeep].Revision > rev {
			break
		}
	}
	if lastToKeep < len(th.unflushed.notifications)-1 {
		th.unflushed.notifications = th.unflushed.notifications[:lastToKeep+1]
		// Invalidate the cached results.
		th.computed = false
		th.cachedLoggedInUser = ""
	}
}
675085
func (p PendingEvaluations) Less(i, j int) bool {
	if p[i].JobID != p[j].JobID && p[i].Priority != p[j].Priority {
		return !(p[i].Priority < p[j].Priority)
	}
	return p[i].CreateIndex < p[j].CreateIndex
}
1089024
func (win *Window) SliderInt(min int, val *int, max int, step int) bool {
	value := float64(*val)
	ret := win.SliderFloat(float64(min), &value, float64(max), float64(step))
	*val = int(value)
	return ret
}
935097
func (e *SelfProvisionEngine) ppStream(m libkb.MetaContext) (*libkb.PassphraseStream, error) {
	if m.LoginContext() == nil {
		return nil, errors.New("SelfProvisionEngine: ppStream() -> nil ctx.LoginContext")
	}
	cached := m.LoginContext().PassphraseStreamCache()
	if cached == nil {
		return nil, errors.New("SelfProvisionEngine: ppStream() -> nil PassphraseStreamCache")
	}
	return cached.PassphraseStream(), nil
}
386314
func NewPaperFolderTeamInviteDetails(EventUuid string) *PaperFolderTeamInviteDetails {
	s := new(PaperFolderTeamInviteDetails)
	s.EventUuid = EventUuid
	return s
}
1160680
func NewPaperFolderLogInfo(FolderId string, FolderName string) *PaperFolderLogInfo {
	s := new(PaperFolderLogInfo)
	s.FolderId = FolderId
	s.FolderName = FolderName
	return s
}
720125
func (c *Client) UpdatePapertrail(i *UpdatePapertrailInput) (*Papertrail, error) {
	if i.Service == "" {
		return nil, ErrMissingService
	}

	if i.Version == 0 {
		return nil, ErrMissingVersion
	}

	if i.Name == "" {
		return nil, ErrMissingName
	}

	path := fmt.Sprintf("/service/%s/version/%d/logging/papertrail/%s", i.Service, i.Version, i.Name)
	resp, err := c.PutForm(path, i, nil)
	if err != nil {
		return nil, err
	}

	var p *Papertrail
	if err := decodeJSON(&p, resp.Body); err != nil {
		return nil, err
	}
	return p, nil
}
120990
func NewPaperExternalViewAllowDetails(EventUuid string) *PaperExternalViewAllowDetails {
	s := new(PaperExternalViewAllowDetails)
	s.EventUuid = EventUuid
	return s
}