Skip to content
This repository has been archived by the owner on Feb 8, 2019. It is now read-only.

Commit

Permalink
PIRK-79 Allow json serialization to deserialize a queryInfo object th…
Browse files Browse the repository at this point in the history
…at has only the name of a query schema. - closes #115
  • Loading branch information
raydulany authored and wraydulany committed Nov 1, 2016
1 parent c3508af commit 2c92885
Show file tree
Hide file tree
Showing 15 changed files with 346 additions and 260 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@
<version>3.6.1</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.7</version>
</dependency>

<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/org/apache/pirk/encryption/Paillier.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import java.io.Serializable;
import java.math.BigInteger;
import java.util.Objects;

/**
* Implementation of the Paillier cryptosystem.
Expand Down Expand Up @@ -72,9 +73,11 @@ public final class Paillier implements Serializable

private static final Logger logger = LoggerFactory.getLogger(Paillier.class);

@Expose
private BigInteger p; // large prime
@Expose
private BigInteger q; // large prime

private BigInteger N; // N=pq, RSA modulus

private BigInteger NSquared; // NSquared = N^2
Expand Down Expand Up @@ -340,4 +343,34 @@ private String parametersToString()
return "p = " + p.intValue() + " q = " + q.intValue() + " N = " + N.intValue() + " NSquared = " + NSquared.intValue() + " lambdaN = " + lambdaN.intValue()
+ " bitLength = " + bitLength;
}

@Override public boolean equals(Object o)
{
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;

Paillier paillier = (Paillier) o;

if (bitLength != paillier.bitLength)
return false;
if (!p.equals(paillier.p))
return false;
if (!q.equals(paillier.q))
return false;
if (!N.equals(paillier.N))
return false;
if (!NSquared.equals(paillier.NSquared))
return false;
if (!lambdaN.equals(paillier.lambdaN))
return false;
return w.equals(paillier.w);

}

@Override public int hashCode()
{
return Objects.hash(p, q, N, NSquared, lambdaN, w, bitLength);
}
}
25 changes: 25 additions & 0 deletions src/main/java/org/apache/pirk/querier/wideskies/Querier.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import com.google.gson.annotations.Expose;
import org.apache.pirk.encryption.Paillier;
Expand Down Expand Up @@ -54,6 +55,30 @@ public class Querier implements Serializable, Storable
@Expose
private Map<Integer,String> embedSelectorMap = null;

@Override public boolean equals(Object o)
{
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;

Querier querier = (Querier) o;

if (!query.equals(querier.query))
return false;
if (!paillier.equals(querier.paillier))
return false;
if (!selectors.equals(querier.selectors))
return false;
return embedSelectorMap != null ? embedSelectorMap.equals(querier.embedSelectorMap) : querier.embedSelectorMap == null;

}

@Override public int hashCode()
{
return Objects.hash(query, paillier, selectors, embedSelectorMap);
}

public Querier(List<String> selectorsInput, Paillier paillierInput, Query queryInput, Map<Integer,String> embedSelectorMapInput)
{
selectors = selectorsInput;
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/org/apache/pirk/query/wideskies/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.SortedMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;
Expand Down Expand Up @@ -56,6 +57,7 @@ public class Query implements Serializable, Storable

// lookup table for exponentiation of query vectors - based on dataPartitionBitSize
// element -> <power, element^power mod N^2>
@Expose
private Map<BigInteger,Map<Integer,BigInteger>> expTable = new ConcurrentHashMap<>();

// File based lookup table for modular exponentiation
Expand Down Expand Up @@ -152,4 +154,32 @@ public BigInteger getExp(BigInteger value, int power)
Map<Integer,BigInteger> powerMap = expTable.get(value);
return (powerMap == null) ? null : powerMap.get(power);
}

@Override public boolean equals(Object o)
{
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;

Query query = (Query) o;

if (!queryInfo.equals(query.queryInfo))
return false;
if (!queryElements.equals(query.queryElements))
return false;
if (expTable != null ? !expTable.equals(query.expTable) : query.expTable != null)
return false;
if (expFileBasedLookup != null ? !expFileBasedLookup.equals(query.expFileBasedLookup) : query.expFileBasedLookup != null)
return false;
if (!N.equals(query.N))
return false;
return NSquared.equals(query.NSquared);

}

@Override public int hashCode()
{
return Objects.hash(queryInfo, queryElements, expTable, expFileBasedLookup, N, NSquared);
}
}
165 changes: 0 additions & 165 deletions src/main/java/org/apache/pirk/query/wideskies/QueryDeserializer.java

This file was deleted.

42 changes: 42 additions & 0 deletions src/main/java/org/apache/pirk/query/wideskies/QueryInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;

/**
Expand Down Expand Up @@ -286,4 +287,45 @@ public QueryInfo clone()
throw new RuntimeException(e);
}
}

@Override public boolean equals(Object o)
{
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;

QueryInfo queryInfo = (QueryInfo) o;

if (numSelectors != queryInfo.numSelectors)
return false;
if (hashBitSize != queryInfo.hashBitSize)
return false;
if (numBitsPerDataElement != queryInfo.numBitsPerDataElement)
return false;
if (dataPartitionBitSize != queryInfo.dataPartitionBitSize)
return false;
if (numPartitionsPerDataElement != queryInfo.numPartitionsPerDataElement)
return false;
if (useExpLookupTable != queryInfo.useExpLookupTable)
return false;
if (useHDFSExpLookupTable != queryInfo.useHDFSExpLookupTable)
return false;
if (embedSelector != queryInfo.embedSelector)
return false;
if (!identifier.equals(queryInfo.identifier))
return false;
if (!queryType.equals(queryInfo.queryType))
return false;
if (!hashKey.equals(queryInfo.hashKey))
return false;
return qSchema != null ? qSchema.equals(queryInfo.qSchema) : queryInfo.qSchema == null;

}

@Override public int hashCode()
{
return Objects.hash(identifier, numSelectors, queryType, hashBitSize, hashKey, numBitsPerDataElement, useExpLookupTable, useHDFSExpLookupTable,
embedSelector, qSchema);
}
}

0 comments on commit 2c92885

Please sign in to comment.