renamed default 'type struct {}' into 'T' because package name is explicit by itself

This commit is contained in:
xdrm-brackets 2018-04-21 18:33:20 +02:00
parent 930c35124f
commit 69bcb46641
3 changed files with 25 additions and 25 deletions

View File

@ -1,7 +1,7 @@
package keyset package keyset
import ( import (
"git.xdrm.io/schastsp/lib/context" "git.xdrm.io/schastsp/context"
"io" "io"
"encoding/binary" "encoding/binary"
"errors" "errors"
@ -13,10 +13,10 @@ import (
const SecretSize = scha.HSIZE * 4; const SecretSize = scha.HSIZE * 4;
/* Attributes */ /* Attributes */
type Set struct { type T struct {
ctx *context.Context // current context ctx *context.T // current context
depth uint16 // cur depth depth uint16 // cur depth
max uint16 // max depth max uint16 // max depth
sec []byte // secret sec []byte // secret
consumed bool // if secret is consumed consumed bool // if secret is consumed
@ -33,7 +33,7 @@ type Set struct {
* @ctx<Context> Context constants * @ctx<Context> Context constants
* *
---------------------------------------------------------*/ ---------------------------------------------------------*/
func Create(ctx *context.Context) (*Set, error) { func Create(ctx *context.T) (*T, error) {
/* (1) Fail if min+thre >= max */ /* (1) Fail if min+thre >= max */
if ctx == nil { if ctx == nil {
@ -41,7 +41,7 @@ func Create(ctx *context.Context) (*Set, error) {
} }
/* (2) Instanciate */ /* (2) Instanciate */
var instance = new(Set) var instance = new(T)
/* (3) Set attributes */ /* (3) Set attributes */
instance.ctx = ctx instance.ctx = ctx
@ -59,7 +59,7 @@ func Create(ctx *context.Context) (*Set, error) {
/* (2) Generates a pseudo-random KeySet /* (2) Generates a pseudo-random KeySet
* *
---------------------------------------------------------*/ ---------------------------------------------------------*/
func (s *Set) generate() { func (s *T) generate() {
/* (1) Seed randomness */ /* (1) Seed randomness */
rand.Seed(time.Now().UTC().UnixNano()) rand.Seed(time.Now().UTC().UnixNano())
@ -94,7 +94,7 @@ func (s *Set) generate() {
* @return digest<[]byte]> Current hash representing the set * @return digest<[]byte]> Current hash representing the set
* *
---------------------------------------------------------*/ ---------------------------------------------------------*/
func (s Set) Hash() ([]byte, error) { func (s T) Hash() ([]byte, error) {
/* (1) Get digest */ /* (1) Get digest */
digest, err := scha.Hash(s.sec, uint(s.depth), nil, nil) digest, err := scha.Hash(s.sec, uint(s.depth), nil, nil)
@ -116,7 +116,7 @@ func (s Set) Hash() ([]byte, error) {
* @return remaining<uint> Remaining hashes before migration * @return remaining<uint> Remaining hashes before migration
* *
---------------------------------------------------------*/ ---------------------------------------------------------*/
func (s *Set) Decrement() uint16 { func (s *T) Decrement() uint16 {
/* (1) Decrement the depth */ /* (1) Decrement the depth */
s.depth-- s.depth--
@ -147,7 +147,7 @@ func (s *Set) Decrement() uint16 {
* network endianness -> big-endian * network endianness -> big-endian
* *
---------------------------------------------------------*/ ---------------------------------------------------------*/
func (s *Set) Store(writer io.Writer) error { func (s *T) Store(writer io.Writer) error {
var err error; var err error;
@ -187,7 +187,7 @@ func (s *Set) Store(writer io.Writer) error {
* | 16 bits | hsize bits | 16 bits | * | 16 bits | hsize bits | 16 bits |
* *
---------------------------------------------------------*/ ---------------------------------------------------------*/
func (s *Set) Fetch(reader io.Reader) error { func (s *T) Fetch(reader io.Reader) error {
var err error var err error
var secretLength uint16 var secretLength uint16

View File

@ -2,7 +2,7 @@ package keyset
import ( import (
"bytes" "bytes"
"git.xdrm.io/schastsp/lib/context" "git.xdrm.io/schastsp/context"
"git.xdrm.io/schastsp/lib/scha" "git.xdrm.io/schastsp/lib/scha"
"testing" "testing"
) )
@ -11,7 +11,7 @@ func TestGenerationDepthBoundaries(t *testing.T) {
var min, max uint16 = 0x0f0, 0xfff var min, max uint16 = 0x0f0, 0xfff
var rangeMin = min + (max-min)/2 var rangeMin = min + (max-min)/2
var rangeMax = max var rangeMax = max
var created *Set; var created *T;
ctx, err := context.Create(2.5, min, 0, max); ctx, err := context.Create(2.5, min, 0, max);
if err != nil { t.Errorf("Do not expected an error: %s", err); return } if err != nil { t.Errorf("Do not expected an error: %s", err); return }
@ -33,7 +33,7 @@ func TestSchaDecrementingProperty(t *testing.T) {
if err != nil { t.Errorf("Do not expected an error"); return } if err != nil { t.Errorf("Do not expected an error"); return }
var h1, h2, hcheck []byte var h1, h2, hcheck []byte
var created *Set var created *T
created, err = Create(ctx) created, err = Create(ctx)
@ -79,7 +79,7 @@ func TestDecrementMinimum(t *testing.T) {
if err != nil { t.Errorf("Do not expected an error"); return } if err != nil { t.Errorf("Do not expected an error"); return }
var h1, h2, hcheck []byte var h1, h2, hcheck []byte
var created *Set var created *T
created, err = Create(ctx) created, err = Create(ctx)
@ -124,8 +124,8 @@ func TestDecrementMinimum(t *testing.T) {
func TestRestore(t *testing.T){ func TestRestore(t *testing.T){
var buffer, srcData bytes.Buffer; var buffer, srcData bytes.Buffer;
var src, dst *Set; var src, dst *T;
var ctx *context.Context; var ctx *context.T;
var err error; var err error;
/* (1) Create a context */ /* (1) Create a context */

View File

@ -13,7 +13,7 @@ const DefaultThr = 0x000a
/* (2) Struct attributes */ /* (2) Struct attributes */
type Context struct { type T struct {
win float64; // 'timeid' window size win float64; // 'timeid' window size
min uint16; // minimum scha depth min uint16; // minimum scha depth
max uint16; // maximum scha depth max uint16; // maximum scha depth
@ -31,9 +31,9 @@ type Context struct {
* *
---------------------------------------------------------*/ ---------------------------------------------------------*/
func Create(win float64, optional... uint16) (*Context, error) { func Create(win float64, optional... uint16) (*T, error) {
var instance = new(Context); var instance = new(T);
/* (1) Window size error */ /* (1) Window size error */
if win < 0 { return nil, errors.New("Window size must be positive and is negative") } if win < 0 { return nil, errors.New("Window size must be positive and is negative") }
@ -74,7 +74,7 @@ func Create(win float64, optional... uint16) (*Context, error) {
} }
/* (4) Getters */ /* (4) Getters */
func (c Context) Window() float64 { return c.win } func (c T) Window() float64 { return c.win }
func (c Context) MinDepth() uint16 { return c.min } func (c T) MinDepth() uint16 { return c.min }
func (c Context) MaxDepth() uint16 { return c.max } func (c T) MaxDepth() uint16 { return c.max }
func (c Context) DepthThreshold() uint16 { return c.thr } func (c T) DepthThreshold() uint16 { return c.thr }