refactor user defined keypad

This commit is contained in:
2024-08-24 21:02:50 -05:00
parent 1a7dc45ab9
commit 3bf2b4d71f
19 changed files with 273 additions and 190 deletions

View File

@@ -8,38 +8,46 @@ import (
)
func TestUserCipherKeys_EncipherSaltHashCode(t *testing.T) {
keypadSize := m.KeypadSize{AttrsPerKey: 10, NumbOfKeys: 5}
kp := m.KeypadDimension{AttrsPerKey: 10, NumbOfKeys: 8}
maxNKodeLen := 10
customerAttrs, err := NewCustomerAttributes(keypadSize)
customerAttrs, err := NewCustomerAttributes()
assert.NoError(t, err)
newUser, err := NewUserCipherKeys(keypadSize, customerAttrs.SetVals, maxNKodeLen)
setVals, err := customerAttrs.SetVals(kp)
assert.NoError(t, err)
attrVals, err := customerAttrs.AttrVals(kp)
assert.NoError(t, err)
newUser, err := NewUserCipherKeys(&kp, setVals, maxNKodeLen)
assert.NoError(t, err)
passcodeIdx := []int{0, 1, 2, 3}
encipher0, err := newUser.EncipherSaltHashCode(passcodeIdx, *customerAttrs)
encipher0, err := newUser.EncipherSaltHashCode(passcodeIdx, attrVals)
assert.NoError(t, err)
err = newUser.ValidPassword(encipher0, passcodeIdx, *customerAttrs)
err = newUser.ValidPassword(encipher0, passcodeIdx, attrVals)
assert.NoError(t, err)
}
func TestUserCipherKeys_EncipherDecipherMask(t *testing.T) {
keypadSize := m.KeypadSize{AttrsPerKey: 10, NumbOfKeys: 5}
kp := m.KeypadDimension{AttrsPerKey: 10, NumbOfKeys: 8}
maxNKodeLen := 10
customerAttrs, err := NewCustomerAttributes(keypadSize)
customerAttrs, err := NewCustomerAttributes()
assert.NoError(t, err)
newUser, err := NewUserCipherKeys(keypadSize, customerAttrs.SetVals, maxNKodeLen)
setVals, err := customerAttrs.SetVals(kp)
assert.NoError(t, err)
attrVals, err := customerAttrs.AttrVals(kp)
assert.NoError(t, err)
newUser, err := NewUserCipherKeys(&kp, setVals, maxNKodeLen)
assert.NoError(t, err)
passcodeIdx := []int{0, 1, 2, 3}
originalSetVals := make([]uint64, len(passcodeIdx))
for idx, val := range passcodeIdx {
attr := customerAttrs.AttrVals[val]
originalSetVals[idx], err = customerAttrs.GetAttrSetVal(attr)
attr := attrVals[val]
originalSetVals[idx], err = customerAttrs.GetAttrSetVal(attr, kp)
assert.NoError(t, err)
}
encipheredCode, err := newUser.EncipherNKode(passcodeIdx, *customerAttrs)
assert.NoError(t, err)
passcodeSetVals, err := newUser.DecipherMask(encipheredCode.Mask, customerAttrs.SetVals, len(passcodeIdx))
passcodeSetVals, err := newUser.DecipherMask(encipheredCode.Mask, setVals, len(passcodeIdx))
assert.NoError(t, err)
for idx, setVal := range passcodeSetVals {
@@ -48,11 +56,11 @@ func TestUserCipherKeys_EncipherDecipherMask(t *testing.T) {
}
func TestUserInterface_RandomShuffle(t *testing.T) {
keypadSize := m.KeypadSize{
kp := m.KeypadDimension{
AttrsPerKey: 10,
NumbOfKeys: 5,
NumbOfKeys: 8,
}
userInterface, err := NewUserInterface(keypadSize)
userInterface, err := NewUserInterface(&kp)
assert.NoError(t, err)
userInterfaceCopy := make([]int, len(userInterface.IdxInterface))
copy(userInterfaceCopy, userInterface.IdxInterface)
@@ -73,9 +81,9 @@ func TestUserInterface_RandomShuffle(t *testing.T) {
func TestUserInterface_DisperseInterface(t *testing.T) {
for idx := 0; idx < 10000; idx++ {
keypadSize := m.KeypadSize{AttrsPerKey: 7, NumbOfKeys: 10}
kp := m.KeypadDimension{AttrsPerKey: 7, NumbOfKeys: 10}
userInterface, err := NewUserInterface(keypadSize)
userInterface, err := NewUserInterface(&kp)
assert.NoError(t, err)
preDispersion, err := userInterface.AttributeAdjacencyGraph()
assert.NoError(t, err)
@@ -92,8 +100,8 @@ func TestUserInterface_DisperseInterface(t *testing.T) {
}
func TestUserInterface_PartialInterfaceShuffle(t *testing.T) {
keypadSize := m.KeypadSize{AttrsPerKey: 7, NumbOfKeys: 10}
userInterface, err := NewUserInterface(keypadSize)
kp := m.KeypadDimension{AttrsPerKey: 7, NumbOfKeys: 10}
userInterface, err := NewUserInterface(&kp)
assert.NoError(t, err)
preShuffle := userInterface.IdxInterface
err = userInterface.PartialInterfaceShuffle()