From 91512adbb28ff55307a4b522af8a7b97fedd85dd Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sun, 22 Apr 2018 01:04:07 +0200 Subject: [PATCH] [client.keyset] moved private methods into 'keyset.internal.go' --- .../schastsp/client/keyset/keyset.go | 48 ++----------------- .../schastsp/client/keyset/keyset.internal.go | 38 +++++++++++++++ 2 files changed, 42 insertions(+), 44 deletions(-) create mode 100644 src/git.xdrm.io/schastsp/client/keyset/keyset.internal.go diff --git a/src/git.xdrm.io/schastsp/client/keyset/keyset.go b/src/git.xdrm.io/schastsp/client/keyset/keyset.go index 913d94c..207cbf7 100644 --- a/src/git.xdrm.io/schastsp/client/keyset/keyset.go +++ b/src/git.xdrm.io/schastsp/client/keyset/keyset.go @@ -6,8 +6,6 @@ import ( "encoding/binary" "errors" "git.xdrm.io/schastsp/lib/scha" - "math/rand" - "time" ) 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 */ - 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 +/* (2) Get current hash * * @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 Remaining hashes before migration * @@ -130,7 +96,7 @@ func (s *T) Decrement() uint16 { -/* (5) Serialisation +/* (4) Serialisation * * @return serial 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 representation * * @return instance<*Set> The corresponding set * @return err Optional error * -* === FORMAT === -* -* | hsize | secret | depth | -* +-----------+------------+---------+ -* | 16 bits | hsize bits | 16 bits | -* ---------------------------------------------------------*/ func (s *T) Fetch(reader io.Reader) error { diff --git a/src/git.xdrm.io/schastsp/client/keyset/keyset.internal.go b/src/git.xdrm.io/schastsp/client/keyset/keyset.internal.go new file mode 100644 index 0000000..d0438de --- /dev/null +++ b/src/git.xdrm.io/schastsp/client/keyset/keyset.internal.go @@ -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 + +} \ No newline at end of file