<commit_before>package main

import (
	"fmt"
	"github.com/keybase/go-libkb"
	"os"
	"strconv"
	"strings"
)

type UI struct {
	Terminal    *Terminal
	SecretEntry *SecretEntry
}

type BaseIdentifyUI struct {
	parent *UI
	them   *libkb.User
}

type IdentifySelfUI struct {
	BaseIdentifyUI
}

type IdentifyLubaUI struct {
	BaseIdentifyUI
}

type IdentifyUI struct {
	BaseIdentifyUI
}

func (u IdentifySelfUI) Start() {
	G.Log.Info("Verifying your key fingerprint....")
}
func (u IdentifyTrackUI) Start() {
	G.Log.Info("Generating tracking statement for " + ColorString("bold", u.them.GetName()))
}
func (u IdentifyLubaUI) Start() {
	G.Log.Info("LoadUserByAssertion: Verifying identify for " + ColorString("bold", u.them.GetName()))
}
func (u IdentifyUI) Start() {
	G.Log.Info("Identifying " + ColorString("bold", u.them.GetName()))
}

func (ui BaseIdentifyUI) baseFinishAndPrompt(ires *libkb.IdentifyRes) (i libkb.TrackInstructions, err error) {
	var warnings libkb.Warnings
	err, warnings = ires.GetErrorLax()
	if err != nil {
		return
	} else if !warnings.IsEmpty() {
		ui.ShowWarnings(warnings)
	}
	return
}

func (ui IdentifyLubaUI) FinishAndPrompt(ires *libkb.IdentifyRes) (i libkb.TrackInstructions, err error) {
	return ui.baseFinishAndPrompt(ires)
}
func (ui IdentifyUI) FinishAndPrompt(ires *libkb.IdentifyRes) (i libkb.TrackInstructions, err error) {
	return ui.baseFinishAndPrompt(ires)
}

func (ui IdentifySelfUI) FinishAndPrompt(ires *libkb.IdentifyRes) (i libkb.TrackInstructions, err error) {
	var warnings libkb.Warnings
	err, warnings = ires.GetErrorLax()
	var prompt string
	if err != nil {
		return
	} else if !warnings.IsEmpty() {
		ui.ShowWarnings(warnings)
		prompt = "Do you still accept these credentials to be your own?"
	} else if len(ires.ProofChecks) == 0 {
		prompt = "We found your account, but you have no hosted proofs. Check your fingerprint carefully. Is this you?"
	} else {
		prompt = "Is this you?"
	}

	err = ui.PromptForConfirmation(prompt)
	if err != nil {
		return
	}
	return
}

type IdentifyTrackUI struct {
	BaseIdentifyUI
	strict bool
}

func (ui IdentifyTrackUI) FinishAndPrompt(res *libkb.IdentifyRes) (i libkb.TrackInstructions, err error) {
	var prompt string
	un := ui.them.GetName()
	var warnings libkb.Warnings

	if err, warnings = res.GetErrorAndWarnings(ui.strict); err != nil {
		return
	} else if !warnings.IsEmpty() {
		ui.ShowWarnings(warnings)
		prompt = "Some proofs failed; still track " + un + "?"
	} else if len(res.ProofChecks) == 0 {
		prompt = "We found an account for " + un +
			", but they haven't proven their identity. Still track them?"
	} else {
		prompt = "Is this the " + un + "you wanted?"
	}

	if err = ui.PromptForConfirmation(prompt); err != nil {
		return
	}
	return
}

func (u BaseIdentifyUI) ReportHook(s string) {
	os.Stdout.Write([]byte(s + "\n"))
}

func (u BaseIdentifyUI) ShowWarnings(w libkb.Warnings) {
	w.Warn()
}

func (u BaseIdentifyUI) PromptForConfirmation(s string) error {
	return u.parent.PromptForConfirmation(s)
}

func (u BaseIdentifyUI) FinishSocialProofCheck(s *libkb.SocialProofChainLink, lcr libkb.LinkCheckResult) {
	var msg, lcrs string

	if diff := lcr.GetDiff(); diff != nil {
		lcrs = TrackDiffToColoredString(diff) + " "
	}

	if err := lcr.GetError(); err == nil {
		msg += (CHECK + " " + lcrs + `"` +
			ColorString("green", s.GetUsername()) + `" on ` + s.GetService() +
			": " + lcr.GetHint().GetHumanUrl())
	} else {
		msg += (BADX + " " + lcrs +
			ColorString("red", `"`+s.GetUsername()+`" on `+s.GetService()+" "+
				ColorString("bold", "failed")+": "+
				lcr.GetError().Error()))
	}
	if cached := lcr.GetCached(); cached != nil {
		msg += " " + ColorString("magenta", cached.ToDisplayString())
	}
	u.ReportHook(msg)
}

func TrackDiffToColoredString(t libkb.TrackDiff) string {
	s := t.ToDisplayString()
	var color string
	switch t.(type) {
	case libkb.TrackDiffError, libkb.TrackDiffClash, libkb.TrackDiffLost:
		color = "red"
	case libkb.TrackDiffUpgraded:
		color = "orange"
	case libkb.TrackDiffNew:
		color = "blue"
	case libkb.TrackDiffNone:
		color = "green"
	}
	if len(color) == 0 {
		s = ColorString(color, s)
	}
	return s
}

func (u BaseIdentifyUI) TrackDiffErrorToString(libkb.TrackDiffError) string {
	return ColorString("red", "<error>")
}
func (u BaseIdentifyUI) TrackDiffUpgradedToString(t libkb.TrackDiffUpgraded) string {
	return ColorString("orange", "<Upgraded from "+t.GetPrev()+" to "+t.GetCurr()+">")
}

func (u BaseIdentifyUI) FinishWebProofCheck(s *libkb.WebProofChainLink, lcr libkb.LinkCheckResult) {
	var msg, lcrs string

	if diff := lcr.GetDiff(); diff != nil {
		lcrs = TrackDiffToColoredString(diff) + " "
	}

	great_color := "green"
	ok_color := "yellow"

	if err := lcr.GetError(); err == nil {
		if s.GetProtocol() == "dns" {
			msg += (CHECK + " " + lcrs + "admin of " +
				ColorString(ok_color, "DNS") + " zone " +
				ColorString(ok_color, s.GetHostname()) +<commit_msg>working through more tracking stuff<commit_after>package main

import (
	"fmt"
	"github.com/keybase/go-libkb"
	"os"
	"strconv"
	"strings"
)

type UI struct {
	Terminal    *Terminal
	SecretEntry *SecretEntry
}

type BaseIdentifyUI struct {
	parent *UI
	them   *libkb.User
}

type IdentifySelfUI struct {
	BaseIdentifyUI
}

type IdentifyLubaUI struct {
	BaseIdentifyUI
}

type IdentifyUI struct {
	BaseIdentifyUI
}

func (u IdentifySelfUI) Start() {
	G.Log.Info("Verifying your key fingerprint....")
}
func (u IdentifyTrackUI) Start() {
	G.Log.Info("Generating tracking statement for " + ColorString("bold", u.them.GetName()))
}
func (u IdentifyLubaUI) Start() {
	G.Log.Info("LoadUserByAssertion: Verifying identify for " + ColorString("bold", u.them.GetName()))
}
func (u IdentifyUI) Start() {
	G.Log.Info("Identifying " + ColorString("bold", u.them.GetName()))
}

func (ui BaseIdentifyUI) baseFinishAndPrompt(ires *libkb.IdentifyRes) (i libkb.TrackInstructions, err error) {
	var warnings libkb.Warnings
	err, warnings = ires.GetErrorLax()
	if err != nil {
		return
	} else if !warnings.IsEmpty() {
		ui.ShowWarnings(warnings)
	}
	return
}

func (ui IdentifyLubaUI) FinishAndPrompt(ires *libkb.IdentifyRes) (i libkb.TrackInstructions, err error) {
	return ui.baseFinishAndPrompt(ires)
}
func (ui IdentifyUI) FinishAndPrompt(ires *libkb.IdentifyRes) (i libkb.TrackInstructions, err error) {
	return ui.baseFinishAndPrompt(ires)
}

func (ui IdentifySelfUI) FinishAndPrompt(ires *libkb.IdentifyRes) (i libkb.TrackInstructions, err error) {
	var warnings libkb.Warnings
	err, warnings = ires.GetErrorLax()
	var prompt string
	if err != nil {
		return
	} else if !warnings.IsEmpty() {
		ui.ShowWarnings(warnings)
		prompt = "Do you still accept these credentials to be your own?"
	} else if len(ires.ProofChecks) == 0 {
		prompt = "We found your account, but you have no hosted proofs. Check your fingerprint carefully. Is this you?"
	} else {
		prompt = "Is this you?"
	}

	err = ui.PromptForConfirmation(prompt)
	if err != nil {
		return
	}
	return
}

type IdentifyTrackUI struct {
	BaseIdentifyUI
	strict bool
}

func (ui IdentifyTrackUI) FinishAndPrompt(res *libkb.IdentifyRes) (i libkb.TrackInstructions, err error) {
	var prompt string
	un := ui.them.GetName()
	var warnings libkb.Warnings

	if err, warnings = res.GetErrorAndWarnings(ui.strict); err != nil {
		return
	} else if !warnings.IsEmpty() {
		ui.ShowWarnings(warnings)
		prompt = "Some proofs failed; still track " + un + "?"
	} else if len(res.ProofChecks) == 0 {
		prompt = "We found an account for " + un +
			", but they haven't proven their identity. Still track them?"
	} else {
		prompt = "Is this the " + ColorString("bold", un) + " you wanted?"
	}

	if err = ui.PromptForConfirmation(prompt); err != nil {
		return
	}

	i.Local = true

	def := true
	prompt = "Publicly write tracking statement to server?"
	if i.Remote, err = ui.parent.PromptYesNo(prompt, &def); err != nil {
		return
	}

	return
}

func (u BaseIdentifyUI) ReportHook(s string) {
	os.Stdout.Write([]byte(s + "\n"))
}

func (u BaseIdentifyUI) ShowWarnings(w libkb.Warnings) {
	w.Warn()
}

func (u BaseIdentifyUI) PromptForConfirmation(s string) error {
	return u.parent.PromptForConfirmation(s)
}

func (u BaseIdentifyUI) FinishSocialProofCheck(s *libkb.SocialProofChainLink, lcr libkb.LinkCheckResult) {
	var msg, lcrs string

	if diff := lcr.GetDiff(); diff != nil {
		lcrs = TrackDiffToColoredString(diff) + " "
	}

	if err := lcr.GetError(); err == nil {
		msg += (CHECK + " " + lcrs + `"` +
			ColorString("green", s.GetUsername()) + `" on ` + s.GetService() +
			": " + lcr.GetHint().GetHumanUrl())
	} else {
		msg += (BADX + " " + lcrs +
			ColorString("red", `"`+s.GetUsername()+`" on `+s.GetService()+" "+
				ColorString("bold", "failed")+": "+
				lcr.GetError().Error()))
	}
	if cached := lcr.GetCached(); cached != nil {
		msg += " " + ColorString("magenta", cached.ToDisplayString())
	}
	u.ReportHook(msg)
}

func TrackDiffToColoredString(t libkb.TrackDiff) string {
	s := t.ToDisplayString()
	var color string
	switch t.(type) {
	case libkb.TrackDiffError, libkb.TrackDiffClash, libkb.TrackDiffLost:
		color = "red"
	case libkb.TrackDiffUpgraded:
		color = "orange"
	case libkb.TrackDiffNew:
		color = "blue"
	case libkb.TrackDiffNone:
		color = "green"
	}
	if len(color) > 0 {
		s = ColorString(color, s)
	}
	return s
}

func (u BaseIdentifyUI) TrackDiffErrorToString(libkb.TrackDiffError) string {
	return ColorString("red", "<error>")
}
func (u BaseIdentifyUI) TrackDiffUpgradedToString(t libkb.TrackDiffUpgraded) string {
	return ColorString("orange", "<Upgraded from "+t.GetPrev()+" to "+t.GetCurr()+">")
}

func (u BaseIdentifyUI) FinishWebProofCheck(s *libkb.WebProofChainLink, lcr libkb.LinkCheckResult) {
	var msg, lcrs string

	if diff := lcr.GetDiff(); diff != nil {
		lcrs = TrackDiffToColoredString(diff) + " "
	}

	great_color := "green"
	ok_color := "yellow"

	if err := lcr.GetError(); err == nil {
		if s.GetProtocol() == "dns" {
			msg += (CHECK + " " + lcrs + "admin of " +
				ColorString(ok_color, "DNS") + " zone " +
				ColorString(ok_color, s.GetHostname()) +
{'fraction_non_alphanumeric': 0.14081145584725538, 'fraction_numerical': 0.0005966587112171838, 'mean_word_length': 4.3580181140117205, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4160822', 'n_tokens_mistral': 3799, 'n_tokens_neox': 3638, 'n_words': 888}