diff --git a/src/git.xdrm.io/schastsp/client/keyset/keyset.go b/src/git.xdrm.io/schastsp/client/keyset/keyset.go index 207cbf7..5c47d9a 100644 --- a/src/git.xdrm.io/schastsp/client/keyset/keyset.go +++ b/src/git.xdrm.io/schastsp/client/keyset/keyset.go @@ -16,7 +16,7 @@ type T struct { depth uint16 // cur depth sec []byte // secret - consumed bool // if secret is consumed + mcode uint8 // migration code (secret renewal) // 0: none // 1: need to migrate // 2: waiting migration @@ -87,7 +87,9 @@ func (s *T) Decrement() uint16 { s.depth-- /* (2) If near minDepth (10 far): set consumption to 1 */ - s.consumed = s.depth <= s.ctx.MinDepth()+s.ctx.DepthThreshold() + if s.mcode == 0 && s.depth <= s.ctx.MinDepth()+s.ctx.DepthThreshold() { + s.mcode = 1 + } /* (3) Return remaining attempts */ return s.depth - s.ctx.MaxDepth() @@ -128,8 +130,8 @@ func (s *T) Store(writer io.Writer) error { err = binary.Write(writer, binary.BigEndian, s.depth) if err != nil { return err } - /* (4) Copy migration level */ - err = binary.Write(writer, binary.BigEndian, s.consumed) + /* (4) Copy migration code */ + err = binary.Write(writer, binary.BigEndian, s.mcode) if err != nil { return err } return nil @@ -174,8 +176,8 @@ func (s *T) Fetch(reader io.Reader) error { err = binary.Read(reader, binary.BigEndian, &s.depth) if err != nil { return err } - /* (6) Try to copy the consumption level */ - err = binary.Read(reader, binary.BigEndian, &s.consumed) + /* (6) Try to copy the migration code */ + err = binary.Read(reader, binary.BigEndian, &s.mcode) if err != nil { return err } return nil diff --git a/src/git.xdrm.io/schastsp/client/keyset/keyset.internal.go b/src/git.xdrm.io/schastsp/client/keyset/keyset.internal.go index d0438de..1d3819d 100644 --- a/src/git.xdrm.io/schastsp/client/keyset/keyset.internal.go +++ b/src/git.xdrm.io/schastsp/client/keyset/keyset.internal.go @@ -33,6 +33,6 @@ func (s *T) generate() { s.depth = randMin + uint16(rand.Intn(int(randMax-randMin))) /* (3) Reset comsumption level */ - s.consumed = false + s.mcode = 0 } \ No newline at end of file