Пример #1
0
func (p ProvisionUI) ChooseDevice(ctx context.Context, arg keybase1.ChooseDeviceArg) (keybase1.DeviceID, error) {
	p.parent.Output("\nThe device you are currently using needs to be provisioned.\n")
	p.parent.Output("Which one of your existing devices would you like to use\n")
	p.parent.Output("to provision this new device?\n\n")
	for i, d := range arg.Devices {
		var ft string
		switch d.Type {
		case libkb.DeviceTypePaper:
			ft = "paper key"
		case libkb.DeviceTypeDesktop:
			ft = "computer"
		case libkb.DeviceTypeMobile:
			ft = "mobile"
		}
		p.parent.Printf("\t%d. [%s]\t%s\n", i+1, ft, d.Name)
	}
	p.parent.Printf("\t%d. I don't have access to any of these devices.\n", len(arg.Devices)+1)
	p.parent.Output("\n")

	ret, err := PromptSelectionOrCancel(PromptDescriptorChooseDevice, p.parent, "Choose a device", 1, len(arg.Devices)+1)

	if err != nil {
		if err == ErrInputCanceled {
			return keybase1.DeviceID(""), libkb.InputCanceledError{}
		}
		return keybase1.DeviceID(""), err
	}

	if ret == len(arg.Devices)+1 {
		// no access selection
		return keybase1.DeviceID(""), nil
	}

	return arg.Devices[ret-1].DeviceID, nil
}
Пример #2
0
func genKeybase1DeviceID(t *testing.T) keybase1.DeviceID {
	did := make([]byte, 16)
	if _, err := rand.Read(did); err != nil {
		t.Fatalf("rand failed: %v\n", err)
	}
	return keybase1.DeviceID(hex.EncodeToString(did))
}