diff options
author | Magdalena GrodziĆska <mag.grodzinska@gmail.com> | 2020-01-14 22:53:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-14 22:53:45 +0100 |
commit | 47ff68f0535f90eb4b09cb8c9c88555abd900cc8 (patch) | |
tree | 4ed4b28dc3d97a74646c977c4efbf6471e7f6f67 /src/main/java/pl/edu/mimuw/cloudatlas/model | |
parent | 50924560e8829914a4b8d315752c693890210c88 (diff) | |
parent | 42abac9eda30ba47ef6e710d0af22969f657a0cd (diff) |
Merge pull request #118 from m-chrzan/query_signer
Query signer
Diffstat (limited to 'src/main/java/pl/edu/mimuw/cloudatlas/model')
-rw-r--r-- | src/main/java/pl/edu/mimuw/cloudatlas/model/ValueQuery.java | 64 |
1 files changed, 61 insertions, 3 deletions
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueQuery.java b/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueQuery.java index 6d233ea..95f826a 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueQuery.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueQuery.java @@ -6,6 +6,7 @@ import pl.edu.mimuw.cloudatlas.interpreter.query.Absyn.Program; import pl.edu.mimuw.cloudatlas.interpreter.query.parser; import pl.edu.mimuw.cloudatlas.interpreter.query.Yylex; import pl.edu.mimuw.cloudatlas.model.Value; +import pl.edu.mimuw.cloudatlas.querysigner.QueryData; /** * A class that holds a CloudAtlas query. @@ -15,21 +16,68 @@ public class ValueQuery extends Value { private String code; // Parsed query private Program query; + // Query signature + private byte[] signature; + // Query signing timestamp + private long timestamp; + // Query installation status + private boolean installed; + /** * Constructs a new <code>ValueQuery</code> object. * - * @param name the name of the query * @param query the code of the query */ public ValueQuery(String query) throws Exception { this.code = query; - Yylex lex = new Yylex(new ByteArrayInputStream(query.getBytes())); - this.query = (new parser(lex)).pProgram(); + if (!query.isEmpty()) { + Yylex lex = new Yylex(new ByteArrayInputStream(query.getBytes())); + this.query = (new parser(lex)).pProgram(); + } + this.signature = null; + this.timestamp = System.currentTimeMillis(); + this.installed = true; + } + + public ValueQuery(String query, byte[] querySignature) throws Exception { + this.code = query; + if (!query.isEmpty()) { + Yylex lex = new Yylex(new ByteArrayInputStream(query.getBytes())); + this.query = (new parser(lex)).pProgram(); + } + this.signature = querySignature; + this.timestamp = System.currentTimeMillis(); + this.installed = true; + } + + public ValueQuery(QueryData queryData) throws Exception { + this.code = queryData.getCode(); + if (!queryData.getCode().isEmpty()) { + Yylex lex = new Yylex(new ByteArrayInputStream(queryData.getCode().getBytes())); + this.query = (new parser(lex)).pProgram(); + } + this.signature = queryData.getSignature(); + this.timestamp = System.currentTimeMillis(); + this.installed = queryData.isInstalled(); + } + + public ValueQuery(String query, long timestamp) throws Exception { + this.code = query; + if (!query.isEmpty()) { + Yylex lex = new Yylex(new ByteArrayInputStream(query.getBytes())); + this.query = (new parser(lex)).pProgram(); + } + this.signature = null; + this.timestamp = timestamp; + this.installed = true; } private ValueQuery() { this.code = null; this.query = null; + this.signature = null; + this.timestamp = System.currentTimeMillis(); + this.installed = true; } public String getCode() { return code; } @@ -38,6 +86,16 @@ public class ValueQuery extends Value { return query; } + public byte[] getSignature() { return signature; } + + public long getTimestamp() { return timestamp; } + + public void setTimestamp(long timestamp) { this.timestamp = timestamp; } + + public boolean isInstalled() { return installed; } + + public void setInstalled(boolean installed) { this.installed = installed; } + @Override public Type getType() { return TypePrimitive.QUERY; |