Skip to content

Commit

Permalink
Merge pull request google#189 from divegeek/master
Browse files Browse the repository at this point in the history
Enable custom implementations of KeyczarReader
  • Loading branch information
divegeek committed May 3, 2016
2 parents e6e0696 + 9b8d31c commit c04946b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 39 deletions.
26 changes: 13 additions & 13 deletions java/code/src/org/keyczar/GenericKeyczar.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,29 @@
* @author [email protected] (Arkajit Dey)
*
*/
class GenericKeyczar extends Keyczar {
GenericKeyczar(KeyczarReader reader) throws KeyczarException {
public class GenericKeyczar extends Keyczar {
public GenericKeyczar(KeyczarReader reader) throws KeyczarException {
super(reader);
}

GenericKeyczar(String location) throws KeyczarException {
public GenericKeyczar(String location) throws KeyczarException {
super(location);
}

@Override
boolean isAcceptablePurpose(KeyPurpose purpose) {
public boolean isAcceptablePurpose(KeyPurpose purpose) {
return true;
}

KeyMetadata getMetadata() {
public KeyMetadata getMetadata() {
return this.kmd;
}

Set<KeyVersion> getVersions() {
public Set<KeyVersion> getVersions() {
return Collections.unmodifiableSet(versionMap.keySet());
}

KeyczarKey getKey(KeyVersion v) {
public KeyczarKey getKey(KeyVersion v) {
return versionMap.get(v);
}

Expand All @@ -73,7 +73,7 @@ KeyczarKey getKey(KeyVersion v) {
* @throws KeyczarException if invalid version number or trying to promote
* a primary key.
*/
void promote(int versionNumber) throws KeyczarException {
public void promote(int versionNumber) throws KeyczarException {
KeyVersion version = getVersion(versionNumber);
switch (version.getStatus()) {
case PRIMARY:
Expand All @@ -100,7 +100,7 @@ void promote(int versionNumber) throws KeyczarException {
* @throws KeyczarException if invalid version number or trying to demote
* a key scheduled for revocation.
*/
void demote(int versionNumber) throws KeyczarException {
public void demote(int versionNumber) throws KeyczarException {
KeyVersion version = getVersion(versionNumber);
switch (version.getStatus()) {
case PRIMARY:
Expand All @@ -119,7 +119,7 @@ void demote(int versionNumber) throws KeyczarException {
/**
* Uses default key parameters to add a new key version.
*/
void addVersion(KeyStatus status) throws KeyczarException {
public void addVersion(KeyStatus status) throws KeyczarException {
addVersion(status, kmd.getType().applyDefaultParameters(null));
}

Expand All @@ -132,7 +132,7 @@ void addVersion(KeyStatus status) throws KeyczarException {
* @param keyParams parameters for new key generation.
* @throws KeyczarException if key type is unsupported.
*/
void addVersion(KeyStatus status, KeyParameters keyParams) throws KeyczarException {
public void addVersion(KeyStatus status, KeyParameters keyParams) throws KeyczarException {
KeyType type = kmd.getType();
KeyczarKey key;
do {
Expand Down Expand Up @@ -176,7 +176,7 @@ private int maxVersion() {
* @return KeyVersion if it exists
* @throws KeyczarException if version number doesn't exist
*/
KeyVersion getVersion(int versionNumber) throws KeyczarException {
public KeyVersion getVersion(int versionNumber) throws KeyczarException {
KeyVersion version = kmd.getVersion(versionNumber);
if (version == null) {
throw new KeyczarException(
Expand All @@ -193,7 +193,7 @@ KeyVersion getVersion(int versionNumber) throws KeyczarException {
* @throws KeyczarException if version number nonexistent or key is not
* scheduled for revocation.
*/
void revoke(int versionNumber) throws KeyczarException {
public void revoke(int versionNumber) throws KeyczarException {
KeyVersion version = getVersion(versionNumber);
if (version.getStatus() == KeyStatus.INACTIVE) {
kmd.removeVersion(versionNumber);
Expand Down
24 changes: 12 additions & 12 deletions java/code/src/org/keyczar/KeyMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@
*
*/
public class KeyMetadata {
String name = "";
KeyPurpose purpose = KeyPurpose.TEST;
KeyType type = DefaultKeyType.TEST;
List<KeyVersion> versions = new ArrayList<KeyVersion>();
boolean encrypted = false;
@Expose String name = "";
@Expose KeyPurpose purpose = KeyPurpose.TEST;
@Expose KeyType type = DefaultKeyType.TEST;
@Expose List<KeyVersion> versions = new ArrayList<KeyVersion>();
@Expose boolean encrypted = false;

protected Map<Integer, KeyVersion> versionMap =
new HashMap<Integer, KeyVersion>(); // link version number to version
Expand Down Expand Up @@ -122,7 +122,7 @@ public boolean addVersion(KeyVersion version) {
* @param versionNumber integer version number of key to be removed
* @return true if remove was successful
*/
boolean removeVersion(int versionNumber) {
public boolean removeVersion(int versionNumber) {
if (versionMap.containsKey(versionNumber)) {
KeyVersion version = versionMap.get(versionNumber);
versions.remove(version);
Expand All @@ -132,15 +132,15 @@ boolean removeVersion(int versionNumber) {
return false;
}

String getName() {
public String getName() {
return name;
}

KeyPurpose getPurpose() {
public KeyPurpose getPurpose() {
return purpose;
}

KeyType getType() {
public KeyType getType() {
return type;
}

Expand All @@ -152,7 +152,7 @@ void setEncrypted(boolean encrypted) {
this.encrypted = encrypted;
}

boolean isEncrypted() {
public boolean isEncrypted() {
return encrypted;
}

Expand All @@ -162,11 +162,11 @@ boolean isEncrypted() {
* @param versionNumber
* @return KeyVersion corresponding to given number, or null if nonexistent
*/
KeyVersion getVersion(int versionNumber) {
public KeyVersion getVersion(int versionNumber) {
return versionMap.get(versionNumber);
}

List<KeyVersion> getVersions() {
public List<KeyVersion> getVersions() {
return versions;
}

Expand Down
16 changes: 8 additions & 8 deletions java/code/src/org/keyczar/KeyVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@
*
*/
public class KeyVersion {
private boolean exportable = false;
private KeyStatus status = KeyStatus.ACTIVE;
private int versionNumber = 0;
@Expose private boolean exportable = false;
@Expose private KeyStatus status = KeyStatus.ACTIVE;
@Expose private int versionNumber = 0;

KeyVersion(int v, boolean export) {
public KeyVersion(int v, boolean export) {
this(v, KeyStatus.ACTIVE, export);
}

Expand Down Expand Up @@ -87,27 +87,27 @@ public int hashCode() {
return versionNumber; // identity depends only on version number
}

KeyStatus getStatus() {
public KeyStatus getStatus() {
return status;
}

public int getVersionNumber() {
return versionNumber;
}

boolean isExportable() {
public boolean isExportable() {
return exportable;
}

/**
* Updates the status of this KeyVersion to given status if not null.
* @param status
*/
void setStatus(KeyStatus status) {
public void setStatus(KeyStatus status) {
this.status = (status == null) ? this.status : status;
}

static KeyVersion read(String jsonString) {
public static KeyVersion read(String jsonString) {
try {
return fromJson(new JSONObject(jsonString));
} catch (JSONException e) {
Expand Down
12 changes: 6 additions & 6 deletions java/code/src/org/keyczar/Keyczar.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
*
*/
abstract class Keyczar {
static final String DEFAULT_ENCODING = "UTF-8";
static final byte FORMAT_VERSION = 0;
static final byte[] FORMAT_BYTES = { FORMAT_VERSION };
static final int KEY_HASH_SIZE = 4;
static final int HEADER_SIZE = 1 + KEY_HASH_SIZE;
public static final String DEFAULT_ENCODING = "UTF-8";
public static final byte FORMAT_VERSION = 0;
public static final byte[] FORMAT_BYTES = { FORMAT_VERSION };
public static final int KEY_HASH_SIZE = 4;
public static final int HEADER_SIZE = 1 + KEY_HASH_SIZE;

final KeyMetadata kmd;
KeyVersion primaryVersion;
Expand Down Expand Up @@ -163,4 +163,4 @@ Collection<KeyczarKey> getKey(byte[] hash) {
* @return true if the purpose is acceptable, false otherwise.
*/
abstract boolean isAcceptablePurpose(KeyPurpose purpose);
}
}

0 comments on commit c04946b

Please sign in to comment.