// Returns whether or not the current install has an active device
// sibkey.
963000
func (u *User) HasDeviceInCurrentInstall(did keybase1.DeviceID) bool {
	ckf := u.GetComputedKeyFamily()
	if ckf == nil {
		return false
	}

	_, err := ckf.GetSibkeyForDevice(did)
	if err != nil {
		return false
	}
	return true
}
968529
func (ckf *ComputedKeyFamily) GetCurrentDevice(g *GlobalContext) (*Device, error) {
	did := g.Env.GetDeviceID()
	if did.IsNil() {
		return nil, NotProvisionedError{}
	}

	dev, ok := ckf.cki.Devices[did]
	if !ok {
		return nil, NotFoundError{}
	}

	return dev, nil
}
486855
func findDeviceKeys(m libkb.MetaContext, me *libkb.User) (*libkb.DeviceWithKeys, error) {
	// need to be logged in to get a device key (unlocked)
	lin, _ := isLoggedIn(m)
	if !lin {
		return nil, libkb.LoginRequiredError{}
	}

	// Get unlocked device for decryption and signing
	// passing in nil SecretUI since we don't know the passphrase.
	m.Debug("findDeviceKeys: getting device encryption key")
	parg := libkb.SecretKeyPromptArg{
		Ska: libkb.SecretKeyArg{
			Me:      me,
			KeyType: libkb.DeviceEncryptionKeyType,
		},
		Reason: "change passphrase",
	}
	encKey, err := m.G().Keyrings.GetSecretKeyWithPrompt(m, parg)
	if err != nil {
		return nil, err
	}
	m.Debug("findDeviceKeys: got device encryption key")
	m.Debug("findDeviceKeys: getting device signing key")
	parg.Ska.KeyType = libkb.DeviceSigningKeyType
	sigKey, err := m.G().Keyrings.GetSecretKeyWithPrompt(m, parg)
	if err != nil {
		return nil, err
	}
	m.Debug("findDeviceKeys: got device signing key")

	return libkb.NewDeviceWithKeysOnly(sigKey, encKey), nil
}
84078
func (bsd *bsdRecord) isInstalled() bool {

	if _, err := os.Stat(bsd.servicePath()); err == nil {
		return true
	}

	return false
}
961495
func (p *Protocol) isActiveSymKey(key string, topic Topic) bool {
	return p.symKeyRWPool[key] != nil
}
210569
func (n *nvmlDriver) DeviceInfoAndStatusByIndex(index uint) (*DeviceInfo, *DeviceStatus, error) {
	device, err := nvml.NewDevice(index)
	if err != nil {
		return nil, nil, err
	}
	status, err := device.Status()
	if err != nil {
		return nil, nil, err
	}
	return &DeviceInfo{
			UUID:               device.UUID,
			Name:               device.Model,
			MemoryMiB:          device.Memory,
			PowerW:             device.Power,
			BAR1MiB:            device.PCI.BAR1,
			PCIBandwidthMBPerS: device.PCI.Bandwidth,
			PCIBusID:           device.PCI.BusID,
			CoresClockMHz:      device.Clocks.Cores,
			MemoryClockMHz:     device.Clocks.Memory,
		}, &DeviceStatus{
			TemperatureC:       status.Temperature,
			GPUUtilization:     status.Utilization.GPU,
			MemoryUtilization:  status.Utilization.Memory,
			EncoderUtilization: status.Utilization.Encoder,
			DecoderUtilization: status.Utilization.Decoder,
			UsedMemoryMiB:      status.Memory.Global.Used,
			ECCErrorsL1Cache:   status.Memory.ECCErrors.L1Cache,
			ECCErrorsL2Cache:   status.Memory.ECCErrors.L2Cache,
			ECCErrorsDevice:    status.Memory.ECCErrors.Device,
			PowerUsageW:        status.Power,
			BAR1UsedMiB:        status.PCI.BAR1Used,
		}, nil
}
123330
func (ss *SecretSyncer) FindActiveKey(ckf *ComputedKeyFamily) (ret *SKB, err error) {
	ss.Lock()
	defer ss.Unlock()

	if ss.keys == nil {
		return nil, nil
	}
	for _, key := range ss.keys.PrivateKeys {
		if ret, _ = key.FindActiveKey(ss.G(), ckf); ret != nil {
			return
		}
	}
	return
}
819182
func (n *NetworkServerAPI) GetDeviceActivation(ctx context.Context, req *ns.GetDeviceActivationRequest) (*ns.GetDeviceActivationResponse, error) {
	var devEUI lorawan.EUI64
	copy(devEUI[:], req.DevEui)

	ds, err := storage.GetDeviceSession(storage.RedisPool(), devEUI)
	if err != nil {
		return nil, errToRPCError(err)
	}

	return &ns.GetDeviceActivationResponse{
		DeviceActivation: &ns.DeviceActivation{
			DevEui:        ds.DevEUI[:],
			DevAddr:       ds.DevAddr[:],
			SNwkSIntKey:   ds.SNwkSIntKey[:],
			FNwkSIntKey:   ds.FNwkSIntKey[:],
			NwkSEncKey:    ds.NwkSEncKey[:],
			FCntUp:        ds.FCntUp,
			NFCntDown:     ds.NFCntDown,
			AFCntDown:     ds.AFCntDown,
			SkipFCntCheck: ds.SkipFCntValidation,
		},
	}, nil
}
1212004
func (cert *Certificate) IsInstalled() (bool, error) {
	nssdb, err := getUserNssdb()
	if err != nil {
		return false, err
	}

	cmd := exec.Command("certutil", "-d", nssdb, "-L", "-n", cert.X509().Subject.CommonName)
	err = cmd.Run()

	found := err == nil
	return found, nil
}
1063870
func (a *ActiveDevice) KeyByType(t SecretKeyType) (GenericKey, error) {
	switch t {
	case DeviceSigningKeyType:
		return a.SigningKey()
	case DeviceEncryptionKeyType:
		return a.EncryptionKey()
	default:
		return nil, fmt.Errorf("Invalid type %v", t)
	}
}
844608
func (l *SigChainLoader) GetKeyFamily() (err error) {
	l.ckf.kf = l.user.GetKeyFamily()
	return
}
966259
func IsKeyNotFoundError(err error) bool {
	statusErr, _ := err.(*errors.StatusError)

	if statusErr != nil && statusErr.Status().Code == http.StatusNotFound {
		return true
	}

	return false
}
1240286
func (s *precheckShim) IsMigrationActive(modelUUID string) (bool, error) {
	return state.IsMigrationActive(s.State, modelUUID)
}
956154
func NewDevicesActive(Windows []uint64, Macos []uint64, Linux []uint64, Ios []uint64, Android []uint64, Other []uint64, Total []uint64) *DevicesActive {
	s := new(DevicesActive)
	s.Windows = Windows
	s.Macos = Macos
	s.Linux = Linux
	s.Ios = Ios
	s.Android = Android
	s.Other = Other
	s.Total = Total
	return s
}
1092899
func (configMgr *ConfigurationManager) IsKeyExist(key string) bool {
	configMgr.configMapMux.Lock()
	defer configMgr.configMapMux.Unlock()

	if _, ok := configMgr.ConfigurationMap[key]; ok {
		return true
	}

	return false
}
308532
func (d *DeviceMapperDriver) verifyThinpoolDeviceUUID(thinPoolDev string) error {
	thinpoolDevPath := d.ThinpoolDevPath()

	if _, err := os.Stat(thinpoolDevPath); err != nil {
		// If the file doesn't exist or we can't stat it, continue.
		return nil
	}

	bytes, err := ioutil.ReadFile(thinpoolDevPath)
	if err != nil {
		return err
	}

	// Initialize the calculated lvuuid, and only get it from lvdisplay if
	// a valid for dm.thinpooldev was provided.
	lvuuid := ""
	if len(thinPoolDev) > 0 {
		lvuuid, err = getlvmuuid(thinPoolDev)
		if err != nil {
			return err
		}
	}

	if lvuuid != strings.TrimSpace(string(bytes)) {
		return ErrThinpoolDevMismatch
	}
	return nil
}
932888
func IsKeyExistsError(err error) bool {
	cause := errors.Cause(err)
	if kvErr, ok := cause.(KeyValueError); ok && kvErr.KVError() {
		return kvErr.StatusCode() == int(gocbcore.StatusKeyExists)
	}

	return false
}