encryption properties are not mutable except during creation requests

This commit is contained in:
Adrian Cole 2010-11-21 18:37:47 +01:00
parent 6ee0b3548d
commit 0ca3a686f5
7 changed files with 82 additions and 46 deletions

View File

@ -36,8 +36,12 @@ import com.google.common.collect.ImmutableSet;
*/
public class CreateDriveRequest extends BaseDrive {
public static class Builder extends BaseDrive.Builder {
private Set<String> avoid = ImmutableSet.of();
@Nullable
private String encryptionCipher;
public Builder avoid(Iterable<String> avoid) {
this.avoid = ImmutableSet.copyOf(checkNotNull(avoid, "avoid"));
return this;
@ -51,12 +55,9 @@ public class CreateDriveRequest extends BaseDrive {
return Builder.class.cast(super.claimType(claimType));
}
/**
* {@inheritDoc}
*/
@Override
public Builder encryptionCipher(String encryptionCipher) {
return Builder.class.cast(super.encryptionCipher(encryptionCipher));
this.encryptionCipher = encryptionCipher;
return this;
}
/**
@ -105,11 +106,14 @@ public class CreateDriveRequest extends BaseDrive {
}
private final Set<String> avoid;
@Nullable
private final String encryptionCipher;
public CreateDriveRequest(String name, long size, @Nullable ClaimType claimType, Iterable<String> readers,
Iterable<String> tags, Map<String, String> userMetadata, @Nullable String encryptionCipher,
Iterable<String> avoid) {
super(name, size, claimType, readers, tags, userMetadata, encryptionCipher);
super(name, size, claimType, readers, tags, userMetadata);
this.encryptionCipher = encryptionCipher;
this.avoid = ImmutableSet.copyOf(checkNotNull(avoid, "avoid"));
}
@ -122,4 +126,51 @@ public class CreateDriveRequest extends BaseDrive {
return avoid;
}
/**
*
* @return either 'none' or 'aes-xts-plain' (the default)
*/
@Nullable
public String getEncryptionCipher() {
return encryptionCipher;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((avoid == null) ? 0 : avoid.hashCode());
result = prime * result + ((encryptionCipher == null) ? 0 : encryptionCipher.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
CreateDriveRequest other = (CreateDriveRequest) obj;
if (avoid == null) {
if (other.avoid != null)
return false;
} else if (!avoid.equals(other.avoid))
return false;
if (encryptionCipher == null) {
if (other.encryptionCipher != null)
return false;
} else if (!encryptionCipher.equals(other.encryptionCipher))
return false;
return true;
}
@Override
public String toString() {
return "[name=" + name + ", size=" + size + ", claimType=" + claimType + ", readers=" + readers + ", tags="
+ tags + ", userMetadata=" + userMetadata + ", avoid=" + avoid + ", encryptionCipher=" + encryptionCipher
+ "]";
}
}

View File

@ -42,6 +42,7 @@ public class DriveInfo extends BaseDrive {
private Boolean autoexpanding;
private Integer bits;
private Set<String> claimed = ImmutableSet.of();
private String encryptionCipher;
private String description;
private String uuid;
private Set<String> driveType = ImmutableSet.of();
@ -166,12 +167,9 @@ public class DriveInfo extends BaseDrive {
return Builder.class.cast(super.claimType(claimType));
}
/**
* {@inheritDoc}
*/
@Override
public Builder encryptionCipher(String encryptionCipher) {
return Builder.class.cast(super.encryptionCipher(encryptionCipher));
this.encryptionCipher = encryptionCipher;
return this;
}
/**
@ -239,6 +237,8 @@ public class DriveInfo extends BaseDrive {
@Nullable
private final Set<String> driveType;
@Nullable
private final String encryptionCipher;
@Nullable
private final String encryptionKey;
@Nullable
private final Boolean free;
@ -268,7 +268,7 @@ public class DriveInfo extends BaseDrive {
String encryptionKey, Boolean free, String imaging, String installNotes, String name, String os,
Iterable<String> readers, Long readBytes, Long readRequests, Long size, Iterable<String> tags, DriveType type,
URI url, Iterable<String> use, Map<String, String> userMetadata, Long writeBytes, Long writeRequests) {
super(name, size, claimType, readers, tags, userMetadata, encryptionCipher);
super(name, size, claimType, readers, tags, userMetadata);
this.status = status;
this.user = user;
this.autoexpanding = autoexpanding;
@ -277,6 +277,7 @@ public class DriveInfo extends BaseDrive {
this.description = description;
this.uuid = drive;
this.driveType = ImmutableSet.copyOf(driveType);
this.encryptionCipher = encryptionCipher;
this.encryptionKey = encryptionKey;
this.free = free;
this.imaging = imaging;
@ -343,6 +344,15 @@ public class DriveInfo extends BaseDrive {
return driveType;
}
/**
*
* @return either 'none' or 'aes-xts-plain' (the default)
*/
@Nullable
public String getEncryptionCipher() {
return encryptionCipher;
}
// TODO
public String getEncryptionKey() {
return encryptionKey;

View File

@ -43,19 +43,12 @@ public class BaseDrive {
protected Set<String> readers = ImmutableSet.of();
protected Set<String> tags = ImmutableSet.of();
protected Map<String, String> userMetadata = ImmutableMap.of();
@Nullable
protected String encryptionCipher;
public Builder claimType(ClaimType claimType) {
this.claimType = claimType;
return this;
}
public Builder encryptionCipher(String encryptionCipher) {
this.encryptionCipher = encryptionCipher;
return this;
}
public Builder name(String name) {
this.name = name;
return this;
@ -82,7 +75,7 @@ public class BaseDrive {
}
public BaseDrive build() {
return new BaseDrive(name, size, claimType, readers, tags, userMetadata, encryptionCipher);
return new BaseDrive(name, size, claimType, readers, tags, userMetadata);
}
}
@ -92,18 +85,15 @@ public class BaseDrive {
protected final Set<String> readers;
protected final Set<String> tags;
protected final Map<String, String> userMetadata;
@Nullable
protected final String encryptionCipher;
public BaseDrive(String name, long size, @Nullable ClaimType claimType, Iterable<String> readers,
Iterable<String> tags, Map<String, String> userMetadata, @Nullable String encryptionCipher) {
Iterable<String> tags, Map<String, String> userMetadata) {
this.name = checkNotNull(name, "name");
this.size = size;
this.claimType = checkNotNull(claimType, "set claimType to exclusive, not null");
this.readers = ImmutableSet.copyOf(checkNotNull(readers, "readers"));
this.tags = ImmutableSet.copyOf(checkNotNull(tags, "tags"));
this.userMetadata = ImmutableMap.copyOf(checkNotNull(userMetadata, "userMetadata"));
this.encryptionCipher = encryptionCipher;
}
/**
@ -116,15 +106,6 @@ public class BaseDrive {
return claimType;
}
/**
*
* @return either 'none' or 'aes-xts-plain' (the default)
*/
@Nullable
public String getEncryptionCipher() {
return encryptionCipher;
}
/**
*
* @return Drive name
@ -171,7 +152,6 @@ public class BaseDrive {
final int prime = 31;
int result = 1;
result = prime * result + ((claimType == null) ? 0 : claimType.hashCode());
result = prime * result + ((encryptionCipher == null) ? 0 : encryptionCipher.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((readers == null) ? 0 : readers.hashCode());
result = prime * result + (int) (size ^ (size >>> 32));
@ -191,11 +171,6 @@ public class BaseDrive {
BaseDrive other = (BaseDrive) obj;
if (claimType != other.claimType)
return false;
if (encryptionCipher == null) {
if (other.encryptionCipher != null)
return false;
} else if (!encryptionCipher.equals(other.encryptionCipher))
return false;
if (name == null) {
if (other.name != null)
return false;
@ -224,7 +199,7 @@ public class BaseDrive {
@Override
public String toString() {
return "[name=" + name + ", size=" + size + ", claimType=" + claimType + ", readers=" + readers + ", tags="
+ tags + ", userMetadata=" + userMetadata + ", encryptionCipher=" + encryptionCipher + "]";
+ tags + ", userMetadata=" + userMetadata + "]";
}
}

View File

@ -53,8 +53,6 @@ public class BaseDriveToMap implements Function<BaseDrive, Map<String, String>>
builder.put("tags", Joiner.on(' ').join(from.getTags()));
for (Entry<String, String> entry : from.getUserMetadata().entrySet())
builder.put("user:" + entry.getKey(), entry.getValue());
if (from.getEncryptionCipher() != null)
builder.put("encryption:cipher", from.getEncryptionCipher());
return builder.build();
}
}

View File

@ -49,6 +49,8 @@ public class CreateDriveRequestToMap implements Function<CreateDriveRequest, Map
builder.putAll(baseDriveToMap.apply(from));
if (from.getAvoid().size() != 0)
builder.put("avoid", Joiner.on(' ').join(from.getAvoid()));
if (from.getEncryptionCipher() != null)
builder.put("encryption:cipher", from.getEncryptionCipher());
return builder.build();
}
}

View File

@ -51,13 +51,13 @@ public class BaseDriveToMapTest {
.claimType(ClaimType.SHARED)//
.readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"))//
.tags(ImmutableSet.of("tag1", "tag2")).userMetadata(ImmutableMap.of("foo", "bar", "baz", "raz"))//
.encryptionCipher("aes-xts-plain").build();
.build();
assertEquals(
BASEDRIVE_TO_MAP.apply(one),
ImmutableMap.builder().put("name", "Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System")
.put("size", "8589934592").put("claim:type", "shared")
.put("readers", "ffffffff-ffff-ffff-ffff-ffffffffffff").put("tags", "tag1 tag2")
.put("user:foo", "bar").put("user:baz", "raz").put("encryption:cipher", "aes-xts-plain").build()
.put("user:foo", "bar").put("user:baz", "raz").build()
);

View File

@ -5,5 +5,5 @@ readers ffffffff-ffff-ffff-ffff-ffffffffffff
tags tag1 tag2
user:foo bar
user:baz raz
encryption:cipher aes-xts-plain
avoid avoid1
encryption:cipher aes-xts-plain