[client.keyset] moved private methods into 'keyset.internal.go'

This commit is contained in:
xdrm-brackets 2018-04-22 01:04:07 +02:00
parent 3246c88e0d
commit 91512adbb2
2 changed files with 42 additions and 44 deletions

View File

@ -6,8 +6,6 @@ import (
"encoding/binary" "encoding/binary"
"errors" "errors"
"git.xdrm.io/schastsp/lib/scha" "git.xdrm.io/schastsp/lib/scha"
"math/rand"
"time"
) )
const SecretSize = scha.HSIZE * 4; const SecretSize = scha.HSIZE * 4;
@ -55,40 +53,8 @@ func Create(ctx *context.T) (*T, error) {
/* (2) Generates a pseudo-random KeySet
*
---------------------------------------------------------*/
func (s *T) generate() {
/* (1) Seed randomness */ /* (2) Get current hash
rand.Seed(time.Now().UTC().UnixNano())
/* (1) Generate new secret
---------------------------------------------------------*/
/* (1) Reset current secret */
s.sec = make([]byte, SecretSize)
/* (2) Generate each char. until same length as hash digest */
for i := uint16(0); i < SecretSize; i++ {
s.sec[i] = byte(rand.Int() % 256)
}
/* (2) Manage other attributes
---------------------------------------------------------*/
/* (1) Random depth pick init */
var randMin, randMax = s.ctx.MinDepth() + (s.ctx.MaxDepth()-s.ctx.MinDepth()) / 2, s.ctx.MaxDepth()
/* (2) Select "random" depth */
s.depth = randMin + uint16(rand.Intn(int(randMax-randMin)))
/* (3) Reset comsumption level */
s.consumed = false
}
/* (3) Get current hash
* *
* @return digest<[]byte]> Current hash representing the set * @return digest<[]byte]> Current hash representing the set
* *
@ -110,7 +76,7 @@ func (s T) Hash() ([]byte, error) {
/* (4) Decrement depth /* (3) Decrement depth
* *
* @return remaining<uint> Remaining hashes before migration * @return remaining<uint> Remaining hashes before migration
* *
@ -130,7 +96,7 @@ func (s *T) Decrement() uint16 {
/* (5) Serialisation /* (4) Serialisation
* *
* @return serial<string> String representation * @return serial<string> String representation
* *
@ -172,19 +138,13 @@ func (s *T) Store(writer io.Writer) error {
/* (6) Builds a KeySet from its serial representation /* (5) Builds a KeySet from its serial representation
* *
* @serial<string> String representation * @serial<string> String representation
* *
* @return instance<*Set> The corresponding set * @return instance<*Set> The corresponding set
* @return err<error> Optional error * @return err<error> Optional error
* *
* === FORMAT ===
*
* | hsize | secret | depth |
* +-----------+------------+---------+
* | 16 bits | hsize bits | 16 bits |
*
---------------------------------------------------------*/ ---------------------------------------------------------*/
func (s *T) Fetch(reader io.Reader) error { func (s *T) Fetch(reader io.Reader) error {

View File

@ -0,0 +1,38 @@
package keyset
import (
"math/rand"
"time"
)
/* (2) Generates a pseudo-random KeySet
*
---------------------------------------------------------*/
func (s *T) generate() {
/* (1) Seed randomness */
rand.Seed(time.Now().UTC().UnixNano())
/* (1) Generate new secret
---------------------------------------------------------*/
/* (1) Reset current secret */
s.sec = make([]byte, SecretSize)
/* (2) Generate each char. until same length as hash digest */
for i := uint16(0); i < SecretSize; i++ {
s.sec[i] = byte(rand.Int() % 256)
}
/* (2) Manage other attributes
---------------------------------------------------------*/
/* (1) Random depth pick init */
var randMin, randMax = s.ctx.MinDepth() + (s.ctx.MaxDepth()-s.ctx.MinDepth()) / 2, s.ctx.MaxDepth()
/* (2) Select "random" depth */
s.depth = randMin + uint16(rand.Intn(int(randMax-randMin)))
/* (3) Reset comsumption level */
s.consumed = false
}