From c1f3e637421c7d5d71a092fd4812aa435639c3da Mon Sep 17 00:00:00 2001 From: Ben Farley <47006790+farleyb-amazon@users.noreply.github.com> Date: Tue, 26 Oct 2021 17:15:22 -0600 Subject: [PATCH] chore: Add back removed CiphertextHeaders.deserialize method (#382) --- .../model/CiphertextHeaders.java | 27 ++++++++++++++++++- .../model/CiphertextHeadersTest.java | 26 ++++++++++++++++-- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/amazonaws/encryptionsdk/model/CiphertextHeaders.java b/src/main/java/com/amazonaws/encryptionsdk/model/CiphertextHeaders.java index 94a35cc21..7015e8cc4 100644 --- a/src/main/java/com/amazonaws/encryptionsdk/model/CiphertextHeaders.java +++ b/src/main/java/com/amazonaws/encryptionsdk/model/CiphertextHeaders.java @@ -503,11 +503,27 @@ private int parseComplete(final byte[] b, final int off) throws ParseException { return 0; } + /** + * Deserialize the provided bytes starting at the specified offset to construct an instance of + * this class. Uses the default value for maxEncryptedDataKeys, which results in no limit. + * + *
This method parses the provided bytes for the individual fields in this class. This method + * also supports partial parsing where not all the bytes required for parsing the fields + * successfully are available. + * + * @param b the byte array to deserialize. + * @param off the offset in the byte array to use for deserialization. + * @return the number of bytes consumed in deserialization. + */ + public int deserialize(final byte[] b, final int off) throws ParseException { + return deserialize(b, off, NO_MAX_ENCRYPTED_DATA_KEYS); + } + /** * Deserialize the provided bytes starting at the specified offset to construct an instance of * this class. * - *
This method parses the provided bytes for the individual fields in this class. This methods + *
This method parses the provided bytes for the individual fields in this class. This method
* also supports partial parsing where not all the bytes required for parsing the fields
* successfully are available.
*
@@ -835,6 +851,15 @@ public void setSuiteData(byte[] suiteData) {
suiteData_ = suiteData.clone();
}
+ /**
+ * Return max encrypted data keys. Package scope for unit testing.
+ *
+ * @return int
+ */
+ int getMaxEncryptedDataKeys() {
+ return maxEncryptedDataKeys_;
+ }
+
private static class PartialParseException extends Exception {
private static final long serialVersionUID = 1L;
final int bytesParsed_;
diff --git a/src/test/java/com/amazonaws/encryptionsdk/model/CiphertextHeadersTest.java b/src/test/java/com/amazonaws/encryptionsdk/model/CiphertextHeadersTest.java
index 8dc1cac5d..58ef933c4 100644
--- a/src/test/java/com/amazonaws/encryptionsdk/model/CiphertextHeadersTest.java
+++ b/src/test/java/com/amazonaws/encryptionsdk/model/CiphertextHeadersTest.java
@@ -51,6 +51,8 @@ public class CiphertextHeadersTest {
@Test
public void serializeDeserialize() {
+ int maxEncryptedDataKeys = 42;
+
Map