[client.keyset] replace 'consumed<bool>' by 'mcode<uint8>' for migration code
This commit is contained in:
parent
4521cf1830
commit
8ef698f4c3
|
@ -16,7 +16,7 @@ type T struct {
|
||||||
depth uint16 // cur depth
|
depth uint16 // cur depth
|
||||||
|
|
||||||
sec []byte // secret
|
sec []byte // secret
|
||||||
consumed bool // if secret is consumed
|
mcode uint8 // migration code (secret renewal)
|
||||||
// 0: none
|
// 0: none
|
||||||
// 1: need to migrate
|
// 1: need to migrate
|
||||||
// 2: waiting migration
|
// 2: waiting migration
|
||||||
|
@ -87,7 +87,9 @@ func (s *T) Decrement() uint16 {
|
||||||
s.depth--
|
s.depth--
|
||||||
|
|
||||||
/* (2) If near minDepth (10 far): set consumption to 1 */
|
/* (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 */
|
/* (3) Return remaining attempts */
|
||||||
return s.depth - s.ctx.MaxDepth()
|
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)
|
err = binary.Write(writer, binary.BigEndian, s.depth)
|
||||||
if err != nil { return err }
|
if err != nil { return err }
|
||||||
|
|
||||||
/* (4) Copy migration level */
|
/* (4) Copy migration code */
|
||||||
err = binary.Write(writer, binary.BigEndian, s.consumed)
|
err = binary.Write(writer, binary.BigEndian, s.mcode)
|
||||||
if err != nil { return err }
|
if err != nil { return err }
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -174,8 +176,8 @@ func (s *T) Fetch(reader io.Reader) error {
|
||||||
err = binary.Read(reader, binary.BigEndian, &s.depth)
|
err = binary.Read(reader, binary.BigEndian, &s.depth)
|
||||||
if err != nil { return err }
|
if err != nil { return err }
|
||||||
|
|
||||||
/* (6) Try to copy the consumption level */
|
/* (6) Try to copy the migration code */
|
||||||
err = binary.Read(reader, binary.BigEndian, &s.consumed)
|
err = binary.Read(reader, binary.BigEndian, &s.mcode)
|
||||||
if err != nil { return err }
|
if err != nil { return err }
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -33,6 +33,6 @@ func (s *T) generate() {
|
||||||
s.depth = randMin + uint16(rand.Intn(int(randMax-randMin)))
|
s.depth = randMin + uint16(rand.Intn(int(randMax-randMin)))
|
||||||
|
|
||||||
/* (3) Reset comsumption level */
|
/* (3) Reset comsumption level */
|
||||||
s.consumed = false
|
s.mcode = 0
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue