Skip to content

Commit

Permalink
Asset additional data fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
horrorho committed Jun 27, 2017
1 parent 1bc7cea commit b82bb0a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@
*/
@Immutable
public final class Asset extends AbstractRecord {

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

private final AssetID assetID;
private final Optional<Integer> protectionClass;
private final Optional<Long> size;
Expand Down Expand Up @@ -167,6 +168,18 @@ public Optional<byte[]> attributeChecksum() {
return encryptedAttributes.flatMap(AssetEncryptedAttributes::checksum);
}

public Optional<Long> sizeBeforeCopy() {
return encryptedAttributes.flatMap(AssetEncryptedAttributes::sizeBeforeCopy);
}

public Optional<Integer> contentCompressionMethod() {
return encryptedAttributes.flatMap(AssetEncryptedAttributes::contentCompressionMethod);
}

public Optional<Integer> contentEncodingMethod() {
return encryptedAttributes.flatMap(AssetEncryptedAttributes::contentEncodingMethod);
}

public Optional<CloudKit.Asset> asset() {
return asset;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public final class AssetEncryptedAttributes {
private final Optional<Long> size;
private final Optional<byte[]> encryptionKey;
private final Optional<byte[]> checksum; // SHA-256
private final Optional<Long> sizeBeforeCopy;
private final Optional<Integer> contentEncodingMethod;
private final Optional<Integer> contentCompressionMethod;

Expand All @@ -63,6 +64,7 @@ public AssetEncryptedAttributes(
Optional<Long> size,
Optional<byte[]> encryptionKey,
Optional<byte[]> checksum,
Optional<Long> sizeBeforeCopy,
Optional<Integer> contentEncodingMethod,
Optional<Integer> contentCompressionMethod) {
this.domain = Objects.requireNonNull(domain);
Expand All @@ -76,6 +78,7 @@ public AssetEncryptedAttributes(
this.size = Objects.requireNonNull(size);
this.encryptionKey = encryptionKey.map(bs -> Arrays.copyOf(bs, bs.length));
this.checksum = checksum.map(bs -> Arrays.copyOf(bs, bs.length));
this.sizeBeforeCopy = Objects.requireNonNull(sizeBeforeCopy);
this.contentEncodingMethod = Objects.requireNonNull(contentEncodingMethod);
this.contentCompressionMethod = Objects.requireNonNull(contentCompressionMethod);
}
Expand Down Expand Up @@ -124,6 +127,10 @@ public Optional<byte[]> checksum() {
return checksum.map(bs -> Arrays.copyOf(bs, bs.length));
}

public Optional<Long> sizeBeforeCopy() {
return sizeBeforeCopy;
}

public Optional<Integer> contentEncodingMethod() {
return contentEncodingMethod;
}
Expand All @@ -146,6 +153,7 @@ public String toString() {
+ ", size=" + size
+ ", encryptionKey=0x" + encryptionKey.map((Hex::toHexString))
+ ", checksum=0x" + checksum.map((Hex::toHexString))
+ ", sizeBeforeCopy=" + sizeBeforeCopy
+ ", contentEncodingMethod=" + contentEncodingMethod
+ ", contentCompressionMethod=" + contentCompressionMethod
+ '}';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ public static AssetEncryptedAttributes fromProtobuf(CloudKit.EncryptedAttributes
Optional<byte[]> checksum = data.hasSha256Signature()
? Optional.of(data.getSha256Signature().toByteArray())
: Optional.empty();
Optional<Long> sizeBeforeCopy = data.hasSizeBeforeCopy()
? Optional.of(data.getSizeBeforeCopy())
: Optional.empty();
Optional<Integer> contentEncodingMethod = data.hasContentEncodingMethod()
? Optional.of(data.getContentEncodingMethod())
: Optional.empty();
Expand All @@ -154,6 +157,7 @@ public static AssetEncryptedAttributes fromProtobuf(CloudKit.EncryptedAttributes
size,
encryptionKey,
checksum,
sizeBeforeCopy,
contentEncodingMethod,
contentCompressionMethod);
logger.trace(">> fromProtobuf() - encrypted attributes: {}", attributes);
Expand Down Expand Up @@ -192,6 +196,7 @@ public static AssetEncryptedAttributes fromDictionary(NSDictionary data, String
Optional<byte[]> encryptionKey = NSDictionaries.as(data, "encryptionKey", NSData.class)
.map(NSData::bytes);
Optional<byte[]> checksum = Optional.empty(); // not present
Optional<Long> sizeBeforeCopy = Optional.empty(); // not present
Optional<Integer> contentEncodingMethod = Optional.empty(); // not present
Optional<Integer> contentCompressionMethod = Optional.empty(); // not present

Expand All @@ -207,6 +212,7 @@ public static AssetEncryptedAttributes fromDictionary(NSDictionary data, String
size,
encryptionKey,
checksum,
sizeBeforeCopy,
contentEncodingMethod,
contentCompressionMethod);
logger.trace(">> fromDictionary() - encrypted attributes: {}", attributes);
Expand Down

0 comments on commit b82bb0a

Please sign in to comment.