Skip to content

Commit

Permalink
Corrected if negative conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
JoaoAndreSa committed Mar 12, 2020
1 parent a4d36eb commit c5dddb8
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 38 deletions.
8 changes: 4 additions & 4 deletions app/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func parseQuery(el *onet.Roster, sum string, count bool, where, predicate, group
whereRegex := "{(w[0-9]+(,\\s*[0-9]+))*(,\\s*w[0-9]+(,\\s*[0-9]+))*}"
groupByRegex := "{g[0-9]+(,\\s*g[0-9]+)*}"

if !checkRegex(sum, sumRegex) {
if checkRegex(sum, sumRegex) == false {
return nil, false, nil, "", nil, fmt.Errorf("error parsing the sum parameter(s)")
}
sum = strings.Replace(sum, " ", "", -1)
Expand All @@ -114,12 +114,12 @@ func parseQuery(el *onet.Roster, sum string, count bool, where, predicate, group
}
}

if !check {
if check == false {
return nil, false, nil, "", nil, fmt.Errorf("no 'count' attribute in the sum variables")
}
}

if !checkRegex(where, whereRegex) {
if checkRegex(where, whereRegex) == false {
return nil, false, nil, "", nil, fmt.Errorf("error parsing the where parameter(s)")
}
where = strings.Replace(where, " ", "", -1)
Expand All @@ -144,7 +144,7 @@ func parseQuery(el *onet.Roster, sum string, count bool, where, predicate, group
}
}

if !checkRegex(groupBy, groupByRegex) {
if checkRegex(groupBy, groupByRegex) == false {
return nil, false, nil, "", nil, fmt.Errorf("error parsing the groupBy parameter(s)")
}
groupBy = strings.Replace(groupBy, " ", "", -1)
Expand Down
4 changes: 2 additions & 2 deletions data/handle_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func GenerateData(numDPs, numEntries, numEntriesFiltered, numGroupsClear, numGro

testData := make(map[string][]libunlynx.DpClearResponse)

if !randomGroups {
if randomGroups == false {
numElem := 1
for _, el := range numType {
numElem = numElem * int(el)
Expand Down Expand Up @@ -362,7 +362,7 @@ func CompareClearResponses(x []libunlynx.DpClearResponse, y []libunlynx.DpClearR
}
}

if !test {
if test == false {
break
}
}
Expand Down
12 changes: 6 additions & 6 deletions lib/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,9 @@ func discreteLog(P kyber.Point, checkNeg bool) (int64, error) {
guessIntMinus := int64(0)

start := true
for i := guessInt; i < MaxHomomorphicInt && !foundPos && !foundNeg; i = i + 1 {
for i := guessInt; i < MaxHomomorphicInt && foundPos == false && foundNeg == false; i = i + 1 {
// check for 0 first
if !start {
if start == false {
guess = SuiTe.Point().Add(guess, B)
}
start = false
Expand All @@ -365,15 +365,15 @@ func discreteLog(P kyber.Point, checkNeg bool) (int64, error) {
foundNeg = true
}
}
if !foundNeg && guess.Equal(P) {
if foundNeg == false && guess.Equal(P) {
foundPos = true
}
}
currentGreatestM = guess
currentGreatestInt = guessInt
mutex.Unlock()

if !foundPos && !foundNeg {
if foundPos == false && foundNeg == false {
log.Error("out of bound encryption, bound is ", MaxHomomorphicInt)
return 0, nil
}
Expand Down Expand Up @@ -451,7 +451,7 @@ func (cv *CipherVector) Equal(cv2 *CipherVector) bool {
}

for i := range *cv2 {
if !(*cv)[i].Equal(&(*cv2)[i]) {
if (*cv)[i].Equal(&(*cv2)[i]) == false {
return false
}
}
Expand Down Expand Up @@ -490,7 +490,7 @@ func (dcv *DeterministCipherVector) Equal(dcv2 *DeterministCipherVector) bool {
}

for i := range *dcv2 {
if !(*dcv)[i].Equal(&(*dcv2)[i]) {
if (*dcv)[i].Equal(&(*dcv2)[i]) == false {
return false
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ func TestNullCipherVector(t *testing.T) {
nullVectDec := libunlynx.DecryptIntVector(secKey, &nullVectEnc)

target := []int64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
if !reflect.DeepEqual(nullVectDec, target) {
if reflect.DeepEqual(nullVectDec, target) == false {
t.Fatal("Null vector of dimension 4 should be ", target, "got", nullVectDec)
}

twoTimesNullEnc := libunlynx.NewCipherVector(10)
twoTimesNullEnc.Add(nullVectEnc, nullVectEnc)
twoTimesNullDec := libunlynx.DecryptIntVector(secKey, twoTimesNullEnc)

if !reflect.DeepEqual(twoTimesNullDec, target) {
if reflect.DeepEqual(twoTimesNullDec, target) == false {
t.Fatal("Null vector + Null vector should be ", target, "got", twoTimesNullDec)
}
}
Expand Down Expand Up @@ -198,7 +198,7 @@ func TestAbstractPointsConverter(t *testing.T) {
}

for i, el := range aps {
if !reflect.DeepEqual(el.String(), newAps[i].String()) {
if reflect.DeepEqual(el.String(), newAps[i].String()) == false {
t.Fatal("Wrong results, expected", el, "but got", newAps[i])
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/shuffle/shuffle.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func PrecomputationWritingForShuffling(appFlag bool, gobFile, serverName string,

// ReadPrecomputedFile reads the precomputation data from a .gob file
func ReadPrecomputedFile(fileName string) ([]CipherVectorScalar, error) {
if _, err := os.Stat(fileName); !os.IsNotExist(err) {
if _, err := os.Stat(fileName); os.IsNotExist(err) == false {
var encoded []CipherVectorScalarBytes
err := libunlynxtools.ReadFromGobFile(fileName, &encoded)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions lib/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func proccessParameters(data []string, clear map[string]int64, encrypted map[str
// all where and group by attributes are in clear
if noEnc {
containerClear = append(containerClear, clear[v])
} else if !noEnc {
} else if noEnc == false {
if value, ok := encrypted[v]; ok {
containerEnc = append(containerEnc, value)
} else {
Expand All @@ -80,7 +80,7 @@ func (s *Store) InsertDpResponse(cr libunlynx.DpResponse, proofsB bool, groupBy,
clearWhr, newResp.WhereEnc = proccessParameters(whereStrings, cr.WhereClear, cr.WhereEnc, noEnc)
_, newResp.AggregatingAttributes = proccessParameters(sum, cr.AggregatingAttributesClear, cr.AggregatingAttributesEnc, false)

if !noEnc {
if noEnc == false {
s.DpResponses = append(s.DpResponses, newResp)
} else {
value, ok := s.DpResponsesAggr[GroupingKeyTuple{libunlynx.Key(clearGrp), libunlynx.Key(clearWhr)}]
Expand Down
2 changes: 1 addition & 1 deletion lib/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (cv *FilteredResponse) Add(cv1, cv2 FilteredResponse) *FilteredResponse {

// AddInMap permits to add a filtered response with its deterministic tag in a map
func AddInMap(s map[GroupingKey]FilteredResponse, key GroupingKey, added FilteredResponse) {
if localResult, ok := s[key]; !ok {
if localResult, ok := s[key]; ok == false {
s[key] = added
} else {
nfr := NewFilteredResponse(len(added.GroupByEnc), len(added.AggregatingAttributes))
Expand Down
2 changes: 1 addition & 1 deletion lib/tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
func SendISMOthers(s *onet.ServiceProcessor, el *onet.Roster, msg interface{}) error {
var errStrs []string
for _, e := range el.List {
if !e.ID.Equal(s.ServerIdentity().ID) {
if e.ID.Equal(s.ServerIdentity().ID) == false {
log.Lvl3("Sending to", e)
err := s.SendRaw(e, msg)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions protocols/collective_aggregation_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (p *CollectiveAggregationProtocol) Dispatch() error {
}

// 1. Aggregation announcement phase
if !p.IsRoot() {
if p.IsRoot() == false {
err := p.aggregationAnnouncementPhase()
if err != nil {
return err
Expand Down Expand Up @@ -211,7 +211,7 @@ func (p *CollectiveAggregationProtocol) aggregationAnnouncementPhase() error {
func (p *CollectiveAggregationProtocol) ascendingAggregationPhase(cvMap map[libunlynx.GroupingKey][]libunlynx.CipherVector) (*map[libunlynx.GroupingKey]libunlynx.FilteredResponse, error) {
roundTotComput := libunlynx.StartTimer(p.Name() + "_CollectiveAggregation(ascendingAggregation)")

if !p.IsLeaf() {
if p.IsLeaf() == false {
length := make([]cadmbLengthStruct, 0)
for _, v := range <-p.LengthNodeChannel {
length = append(length, v)
Expand Down Expand Up @@ -257,7 +257,7 @@ func (p *CollectiveAggregationProtocol) ascendingAggregationPhase(cvMap map[libu

libunlynx.EndTimer(roundTotComput)

if !p.IsRoot() {
if p.IsRoot() == false {
detAggrResponses := make([]libunlynx.FilteredResponseDet, len(*p.GroupedData))
count := 0
for i, v := range *p.GroupedData {
Expand Down
2 changes: 1 addition & 1 deletion protocols/deterministic_tagging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestDeterministicTagging(t *testing.T) {
present = true
}
}
if !present {
if present == false {
t.Fatal("DP responses changed and shouldn't")
}
}
Expand Down
6 changes: 3 additions & 3 deletions protocols/key_switching_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (p *KeySwitchingProtocol) Dispatch() error {
defer p.Done()

// 1. Key switching announcement phase
if !p.IsRoot() {
if p.IsRoot() == false {
targetPublicKey, rbs, err := p.announcementKSPhase()
if err != nil {
return err
Expand Down Expand Up @@ -253,7 +253,7 @@ func (p *KeySwitchingProtocol) ascendingKSPhase() (*libunlynx.CipherVector, erro

keySwitchingAscendingAggregation := libunlynx.StartTimer(p.Name() + "_KeySwitching(ascendingAggregation)")

if !p.IsLeaf() {
if p.IsLeaf() == false {
length := make([]LengthStruct, 0)
for _, v := range <-p.LengthChannel {
length = append(length, v)
Expand All @@ -278,7 +278,7 @@ func (p *KeySwitchingProtocol) ascendingKSPhase() (*libunlynx.CipherVector, erro
}
libunlynx.EndTimer(keySwitchingAscendingAggregation)

if !p.IsRoot() {
if p.IsRoot() == false {
if err := p.SendToParent(&LengthMessage{Length: libunlynxtools.UnsafeCastIntsToBytes([]int{len(*p.NodeContribution)})}); err != nil {
return nil, fmt.Errorf("Node "+p.ServerIdentity().String()+" failed to broadcast LengthMessage: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion protocols/key_switching_protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestCTKS(t *testing.T) {
res := libunlynx.DecryptIntVector(clientPrivate, &cv1)
log.Lvl2("Received results (attributes) ", res)

if !reflect.DeepEqual(res, append(data1, data2...)) {
if reflect.DeepEqual(res, append(data1, data2...)) == false {
t.Fatal("Wrong results, expected", data1, "but got", res)
} else {
t.Log("Good results")
Expand Down
2 changes: 1 addition & 1 deletion protocols/shuffling_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func (p *ShufflingProtocol) Dispatch() error {
var pi []int
var beta [][]kyber.Scalar

if !p.IsRoot() {
if p.IsRoot() == false {
shufflingDispatchNoProof := libunlynx.StartTimer(p.Name() + "_Shuffling(DISPATCH-noProof)")

shuffledData, pi, beta = libunlynxshuffle.ShuffleSequence(shuffleTarget, libunlynx.SuiTe.Point().Base(), collectiveKey, p.Precomputed)
Expand Down
18 changes: 9 additions & 9 deletions services/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func TestServiceClearAttr(t *testing.T) {
grpTab[ind] = v
}
data, ok := expectedResults[grpTab]
if !ok || !reflect.DeepEqual(data, (*aggr)[i]) {
if ok == false || reflect.DeepEqual(data, (*aggr)[i]) == false {
t.Error("Not expected results, got ", (*aggr)[i], " when expected ", data)
}
}
Expand Down Expand Up @@ -302,7 +302,7 @@ func TestServiceClearGrpEncWhereAttr(t *testing.T) {
grpTab[ind] = v
}
data, ok := expectedResults[grpTab]
if !ok || !reflect.DeepEqual(data, (*aggr)[i]) {
if ok == false || reflect.DeepEqual(data, (*aggr)[i]) == false {
t.Error("Not expected results, got ", (*aggr)[i], " when expected ", data)
}
}
Expand Down Expand Up @@ -407,7 +407,7 @@ func TestServiceEncGrpClearWhereAttr(t *testing.T) {
grpTab[ind] = v
}
data, ok := expectedResults[grpTab]
if !ok || !reflect.DeepEqual(data, (*aggr)[i]) {
if ok == false || reflect.DeepEqual(data, (*aggr)[i]) == false {
t.Error("Not expected results, got ", (*aggr)[i], " when expected ", data)
}
}
Expand Down Expand Up @@ -515,7 +515,7 @@ func TestServiceEncGrpAndWhereAttr(t *testing.T) {
grpTab[ind] = v
}
data, ok := expectedResults[grpTab]
if !ok || !reflect.DeepEqual(data, (*aggr)[i]) {
if ok == false || reflect.DeepEqual(data, (*aggr)[i]) == false {
t.Error("Not expected results, got ", (*aggr)[i], " when expected ", data)
}
}
Expand Down Expand Up @@ -619,7 +619,7 @@ func TestServiceEverything(t *testing.T) {
grpTab[ind] = v
}
data, ok := expectedResults[grpTab]
if !ok || !reflect.DeepEqual(data, (*aggr)[i]) {
if ok == false || reflect.DeepEqual(data, (*aggr)[i]) == false {
t.Error("Not expected results, got ", (*aggr)[i], " when expected ", data)
}
}
Expand Down Expand Up @@ -723,7 +723,7 @@ func TestServiceEncGrpAndWhereAttrWithCount(t *testing.T) {
grpTab[ind] = v
}
data, ok := expectedResults[grpTab]
if !ok || !reflect.DeepEqual(data, (*aggr)[i]) {
if ok == false || reflect.DeepEqual(data, (*aggr)[i]) == false {
t.Error("Not expected results, got ", (*aggr)[i], " when expected ", data)
}
}
Expand Down Expand Up @@ -833,7 +833,7 @@ func TestAllServersNoDPs(t *testing.T) {
grpTab[ind] = v
}
data, ok := expectedResults[grpTab]
if !ok || !reflect.DeepEqual(data, (*aggr)[i]) {
if ok == false || reflect.DeepEqual(data, (*aggr)[i]) == false {
t.Error("Not expected results, got ", (*aggr)[i], " when expected ", data)
}
}
Expand Down Expand Up @@ -947,7 +947,7 @@ func TestAllServersRandomDPs(t *testing.T) {
grpTab[ind] = v
}
data, ok := expectedResults[grpTab]
if !ok || !reflect.DeepEqual(data, (*aggr)[i]) {
if ok == false || reflect.DeepEqual(data, (*aggr)[i]) == false {
t.Error("Not expected results, got ", (*aggr)[i], " when expected ", data)
}
}
Expand Down Expand Up @@ -1072,7 +1072,7 @@ func TestConcurrentSurveys(t *testing.T) {
grpTab[ind] = v
}
data, ok := expectedResults[grpTab]
if !ok || !reflect.DeepEqual(data, (*aggr)[i]) {
if ok == false || reflect.DeepEqual(data, (*aggr)[i]) == false {
t.Error("Not expected results, got ", (*aggr)[i], " when expected ", data)
}
}
Expand Down

0 comments on commit c5dddb8

Please sign in to comment.