diff options
author | bleichen <bleichen@google.com> | 2023-02-20 08:30:58 -0800 |
---|---|---|
committer | Charles Lee <ckl@google.com> | 2023-02-27 16:44:39 -0800 |
commit | d22747720d98d28ba8209f9fe729eda68a96ab64 (patch) | |
tree | 98aaf97a0ff615256833bc5b01c78661e32c9d07 | |
parent | f38fca6eae15455e829e7defa6259e3145a56832 (diff) | |
download | wycheproof-d22747720d98d28ba8209f9fe729eda68a96ab64.tar.gz |
Replacing test vector with JSON serialization.
All other test vectors use compact form.
For testing libraries that accepts forms other than the compact form
we would add new test vector files.
This simplifies the tests using these test vectors.
NOKEYCHECK=True
PiperOrigin-RevId: 511000783
-rw-r--r-- | java/com/google/security/wycheproof/jose4j/JsonWebEncryptionTest.java | 13 | ||||
-rw-r--r-- | testvectors/json_web_encryption_test.json | 14 |
2 files changed, 2 insertions, 25 deletions
diff --git a/java/com/google/security/wycheproof/jose4j/JsonWebEncryptionTest.java b/java/com/google/security/wycheproof/jose4j/JsonWebEncryptionTest.java index aacf3bb..a869be3 100644 --- a/java/com/google/security/wycheproof/jose4j/JsonWebEncryptionTest.java +++ b/java/com/google/security/wycheproof/jose4j/JsonWebEncryptionTest.java @@ -188,7 +188,7 @@ public class JsonWebEncryptionTest { assertThat(allTestNames).containsAtLeastElementsIn(getSuppressedTests()); String privateJwk = testGroup.getAsJsonObject("private").toString(); - String jwe = getFlattenedString(testCase, "jwe"); + String jwe = testCase.get("jwe").getAsString(); boolean expectedResult = testCase.get("result").getAsString().equals("valid"); String expectedPlaintextHex = expectedResult ? testCase.get("pt").getAsString() : ""; @@ -203,17 +203,6 @@ public class JsonWebEncryptionTest { } } - /** Reads the JWS/JWE field either in compact or JSON serialization form. */ - private static String getFlattenedString(JsonObject jsonObject, String fieldName) { - JsonElement element = jsonObject.get(fieldName); - if (element.isJsonPrimitive()) { - // This is a compact representation of the JWE/JWS. - return element.getAsString(); - } - // This is a JSON representation of the JWE/JWS. - return element.toString(); - } - private static boolean containsFlag(JsonObject testCase, String flag) { for (var flagTestCase : testCase.getAsJsonArray("flags")) { if (flag.equals(flagTestCase.getAsString())) { diff --git a/testvectors/json_web_encryption_test.json b/testvectors/json_web_encryption_test.json index 5a3b294..130dd6f 100644 --- a/testvectors/json_web_encryption_test.json +++ b/testvectors/json_web_encryption_test.json @@ -198,19 +198,7 @@ "tcId": 22, "comment": "rejectsValidJsonSerialization", "enc": "A256GCM", - "jwe": { - "protected": "eyJhbGciOiJBMjU2S1ciLCJraWQiOiJraWQtYWVzLWVuY3J5cHQiLCJlbmMiOiJBMjU2Q0JDLUhTNTEyIn0", - "unprotected": { - "unknown": "untrustworthy" - }, - "header": { - "unknown2": "untrustworthy" - }, - "encrypted_key": "LuAAkW6Y609GBgbxDM5V-es3SUNL-rdFVhFNIrLpe1o0f2ldS6sI1SGftpRSmy1PFW58DJaRPwVE7mGsChY6x68-GZB4T1-r", - "iv": "La_y01ijrXjd1d4sY761og", - "ciphertext": "8QQpwqfEv-4h80BWn40xaw", - "tag": "f6dsHvd-MIqQAyu5D6-ZdptbF0ettEHFGcAvmNgu7jo" - }, + "jwe": "{\"protected\":\"eyJhbGciOiJBMjU2S1ciLCJraWQiOiJraWQtYWVzLWVuY3J5cHQiLCJlbmMiOiJBMjU2Q0JDLUhTNTEyIn0\",\"unprotected\":{\"unknown\": \"untrustworthy\"},\"header\":{\"unknown2\": \"untrustworthy\"},\"encrypted_key\": \"LuAAkW6Y609GBgbxDM5V-es3SUNL-rdFVhFNIrLpe1o0f2ldS6sI1SGftpRSmy1PFW58DJaRPwVE7mGsChY6x68-GZB4T1-r\",\"iv\": \"La_y01ijrXjd1d4sY761og\",\"ciphertext\": \"8QQpwqfEv-4h80BWn40xaw\",\"tag\": \"f6dsHvd-MIqQAyu5D6-ZdptbF0ettEHFGcAvmNgu7jo\"}", "result": "invalid", "flags": [ "JsonSerialization" |