// UpdateDevices takes the Device object from the given ChainLink // and updates keys to reflects any device changes encoded therein. func (ckf *ComputedKeyFamily) UpdateDevices(tcl TypedChainLink) (err error) { G.Log.Debug("+ UpdateDevice") defer func() { G.Log.Debug("- UpdateDevice -> %s", ErrToOk(err)) }() var dobj *Device if dobj = tcl.GetDevice(); dobj == nil { return } did := dobj.ID kid := dobj.Kid G.Log.Debug("| Device ID=%s; KID=%s", did, kid.String()) var prevKid keybase1.KID if existing, found := ckf.cki.Devices[did]; found { G.Log.Debug("| merge with existing") prevKid = existing.Kid existing.Merge(dobj) dobj = existing } else { G.Log.Debug("| New insert") ckf.cki.Devices[did] = dobj } // Clear out the old Key that this device used to refer to. // We might wind up just clobbering it with the same thing, but // that's fine for now. if prevKid.IsValid() { G.Log.Debug("| Clear out old key") delete(ckf.cki.KIDToDeviceID, prevKid) } if kid.IsValid() { ckf.cki.KIDToDeviceID[kid] = did } return }
// UpdateDevices takes the Device object from the given ChainLink // and updates keys to reflects any device changes encoded therein. func (ckf *ComputedKeyFamily) UpdateDevices(tcl TypedChainLink) (err error) { var dobj *Device if dobj = tcl.GetDevice(); dobj == nil { ckf.G().VDL.Log(VLog1, "Short-circuit of UpdateDevices(); not a device link") return } defer ckf.G().Trace("UpdateDevice", func() error { return err })() did := dobj.ID kid := dobj.Kid ckf.G().Log.Debug("| Device ID=%s; KID=%s", did, kid.String()) var prevKid keybase1.KID if existing, found := ckf.cki.Devices[did]; found { ckf.G().Log.Debug("| merge with existing") prevKid = existing.Kid existing.Merge(dobj) dobj = existing } else { ckf.G().Log.Debug("| New insert") ckf.cki.Devices[did] = dobj } // Clear out the old Key that this device used to refer to. // We might wind up just clobbering it with the same thing, but // that's fine for now. if prevKid.IsValid() { ckf.G().Log.Debug("| Clear out old key") delete(ckf.cki.KIDToDeviceID, prevKid) } if kid.IsValid() { ckf.cki.KIDToDeviceID[kid] = did } return }
// UpdateDevices takes the Device object from the given ChainLink // and updates keys to reflects any device changes encoded therein. func (ckf *ComputedKeyFamily) UpdateDevices(tcl TypedChainLink) (err error) { var dobj *Device if dobj = tcl.GetDevice(); dobj == nil { ckf.G().VDL.Log(VLog1, "Short-circuit of UpdateDevices(); not a device link") return } defer ckf.G().Trace("UpdateDevice", func() error { return err })() did := dobj.ID kid := dobj.Kid ckf.G().Log.Debug("| Device ID=%s; KID=%s", did, kid.String()) var prevKid keybase1.KID if existing, found := ckf.cki.Devices[did]; found { ckf.G().Log.Debug("| merge with existing") prevKid = existing.Kid existing.Merge(dobj) dobj = existing } else { ckf.G().Log.Debug("| New insert") ckf.cki.Devices[did] = dobj } // If a KID is specified, we should clear out any previous KID from the // KID->Device map. But if not, leave the map as it is. Later "device" // blobs in the sigchain aren't required to repeat the KID every time. if kid.IsValid() { if prevKid.IsValid() { ckf.G().Log.Debug("| Clear out old key") delete(ckf.cki.KIDToDeviceID, prevKid) } ckf.cki.KIDToDeviceID[kid] = did } return }