renamed default 'type struct {}' into 'T' because package name is explicit by itself
This commit is contained in:
parent
930c35124f
commit
69bcb46641
|
@ -1,7 +1,7 @@
|
|||
package keyset
|
||||
|
||||
import (
|
||||
"git.xdrm.io/schastsp/lib/context"
|
||||
"git.xdrm.io/schastsp/context"
|
||||
"io"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
|
@ -13,10 +13,10 @@ import (
|
|||
const SecretSize = scha.HSIZE * 4;
|
||||
|
||||
/* Attributes */
|
||||
type Set struct {
|
||||
ctx *context.Context // current context
|
||||
depth uint16 // cur depth
|
||||
max uint16 // max depth
|
||||
type T struct {
|
||||
ctx *context.T // current context
|
||||
depth uint16 // cur depth
|
||||
max uint16 // max depth
|
||||
|
||||
sec []byte // secret
|
||||
consumed bool // if secret is consumed
|
||||
|
@ -33,7 +33,7 @@ type Set struct {
|
|||
* @ctx<Context> Context constants
|
||||
*
|
||||
---------------------------------------------------------*/
|
||||
func Create(ctx *context.Context) (*Set, error) {
|
||||
func Create(ctx *context.T) (*T, error) {
|
||||
|
||||
/* (1) Fail if min+thre >= max */
|
||||
if ctx == nil {
|
||||
|
@ -41,7 +41,7 @@ func Create(ctx *context.Context) (*Set, error) {
|
|||
}
|
||||
|
||||
/* (2) Instanciate */
|
||||
var instance = new(Set)
|
||||
var instance = new(T)
|
||||
|
||||
/* (3) Set attributes */
|
||||
instance.ctx = ctx
|
||||
|
@ -59,7 +59,7 @@ func Create(ctx *context.Context) (*Set, error) {
|
|||
/* (2) Generates a pseudo-random KeySet
|
||||
*
|
||||
---------------------------------------------------------*/
|
||||
func (s *Set) generate() {
|
||||
func (s *T) generate() {
|
||||
|
||||
/* (1) Seed randomness */
|
||||
rand.Seed(time.Now().UTC().UnixNano())
|
||||
|
@ -94,7 +94,7 @@ func (s *Set) generate() {
|
|||
* @return digest<[]byte]> Current hash representing the set
|
||||
*
|
||||
---------------------------------------------------------*/
|
||||
func (s Set) Hash() ([]byte, error) {
|
||||
func (s T) Hash() ([]byte, error) {
|
||||
|
||||
/* (1) Get digest */
|
||||
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
|
||||
*
|
||||
---------------------------------------------------------*/
|
||||
func (s *Set) Decrement() uint16 {
|
||||
func (s *T) Decrement() uint16 {
|
||||
|
||||
/* (1) Decrement the depth */
|
||||
s.depth--
|
||||
|
@ -147,7 +147,7 @@ func (s *Set) Decrement() uint16 {
|
|||
* network endianness -> big-endian
|
||||
*
|
||||
---------------------------------------------------------*/
|
||||
func (s *Set) Store(writer io.Writer) error {
|
||||
func (s *T) Store(writer io.Writer) error {
|
||||
|
||||
var err error;
|
||||
|
||||
|
@ -187,7 +187,7 @@ func (s *Set) Store(writer io.Writer) error {
|
|||
* | 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 secretLength uint16
|
||||
|
|
|
@ -2,7 +2,7 @@ package keyset
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"git.xdrm.io/schastsp/lib/context"
|
||||
"git.xdrm.io/schastsp/context"
|
||||
"git.xdrm.io/schastsp/lib/scha"
|
||||
"testing"
|
||||
)
|
||||
|
@ -11,7 +11,7 @@ func TestGenerationDepthBoundaries(t *testing.T) {
|
|||
var min, max uint16 = 0x0f0, 0xfff
|
||||
var rangeMin = min + (max-min)/2
|
||||
var rangeMax = max
|
||||
var created *Set;
|
||||
var created *T;
|
||||
|
||||
ctx, err := context.Create(2.5, min, 0, max);
|
||||
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 }
|
||||
|
||||
var h1, h2, hcheck []byte
|
||||
var created *Set
|
||||
var created *T
|
||||
|
||||
created, err = Create(ctx)
|
||||
|
||||
|
@ -79,7 +79,7 @@ func TestDecrementMinimum(t *testing.T) {
|
|||
if err != nil { t.Errorf("Do not expected an error"); return }
|
||||
|
||||
var h1, h2, hcheck []byte
|
||||
var created *Set
|
||||
var created *T
|
||||
|
||||
created, err = Create(ctx)
|
||||
|
||||
|
@ -124,8 +124,8 @@ func TestDecrementMinimum(t *testing.T) {
|
|||
func TestRestore(t *testing.T){
|
||||
|
||||
var buffer, srcData bytes.Buffer;
|
||||
var src, dst *Set;
|
||||
var ctx *context.Context;
|
||||
var src, dst *T;
|
||||
var ctx *context.T;
|
||||
var err error;
|
||||
|
||||
/* (1) Create a context */
|
||||
|
|
|
@ -13,7 +13,7 @@ const DefaultThr = 0x000a
|
|||
|
||||
|
||||
/* (2) Struct attributes */
|
||||
type Context struct {
|
||||
type T struct {
|
||||
win float64; // 'timeid' window size
|
||||
min uint16; // minimum 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 */
|
||||
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 */
|
||||
func (c Context) Window() float64 { return c.win }
|
||||
func (c Context) MinDepth() uint16 { return c.min }
|
||||
func (c Context) MaxDepth() uint16 { return c.max }
|
||||
func (c Context) DepthThreshold() uint16 { return c.thr }
|
||||
func (c T) Window() float64 { return c.win }
|
||||
func (c T) MinDepth() uint16 { return c.min }
|
||||
func (c T) MaxDepth() uint16 { return c.max }
|
||||
func (c T) DepthThreshold() uint16 { return c.thr }
|
Loading…
Reference in New Issue