From be36da4c2b5268b7a588f1b281c849fb6b2f3aca Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Wed, 9 Nov 2022 21:35:07 +0000 Subject: [PATCH] Fix a couple of regular expressions. Our old NetBSD regex implementation didn't care, but the current NetBSD implementation rejects unquoted `{` and `}`s that aren't actually part of a repetition. glibc shares this behavior. Interestingly, the new NetBSD code was itself an sync with FreeBSD, so although macOS right now allows this (as Android did), they may well switch too. Anyway, this way of writing the regular expressions is strictly correct, so regardless of whether or not we can actually land this change to the regex implementation without causing app compat chaos, we should fix this test. Bug: http://b/258469149 Test: treehugger Change-Id: I85bf5d8f557a4fe5ac5ebeea565892d36da30b55 --- .../vts/functional/KeyMintAidlTestBase.cpp | 48 ++++++++++--------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.cpp b/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.cpp index 54730627cf..80abd920d6 100644 --- a/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.cpp +++ b/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.cpp @@ -1919,30 +1919,32 @@ void check_cose_key(const vector& data, bool testMode) { // The following check assumes that canonical CBOR encoding is used for the COSE_Key. if (testMode) { - EXPECT_THAT(cppbor::prettyPrint(parsedPayload.get()), - MatchesRegex("{\n" - " 1 : 2,\n" // kty: EC2 - " 3 : -7,\n" // alg: ES256 - " -1 : 1,\n" // EC id: P256 - // The regex {(0x[0-9a-f]{2}, ){31}0x[0-9a-f]{2}} matches a - // sequence of 32 hexadecimal bytes, enclosed in braces and - // separated by commas. In this case, some Ed25519 public key. - " -2 : {(0x[0-9a-f]{2}, ){31}0x[0-9a-f]{2}},\n" // pub_x: data - " -3 : {(0x[0-9a-f]{2}, ){31}0x[0-9a-f]{2}},\n" // pub_y: data - " -70000 : null,\n" // test marker - "}")); + EXPECT_THAT( + cppbor::prettyPrint(parsedPayload.get()), + MatchesRegex("\\{\n" + " 1 : 2,\n" // kty: EC2 + " 3 : -7,\n" // alg: ES256 + " -1 : 1,\n" // EC id: P256 + // The regex {(0x[0-9a-f]{2}, ){31}0x[0-9a-f]{2}} matches a + // sequence of 32 hexadecimal bytes, enclosed in braces and + // separated by commas. In this case, some Ed25519 public key. + " -2 : \\{(0x[0-9a-f]{2}, ){31}0x[0-9a-f]{2}\\},\n" // pub_x: data + " -3 : \\{(0x[0-9a-f]{2}, ){31}0x[0-9a-f]{2}\\},\n" // pub_y: data + " -70000 : null,\n" // test marker + "\\}")); } else { - EXPECT_THAT(cppbor::prettyPrint(parsedPayload.get()), - MatchesRegex("{\n" - " 1 : 2,\n" // kty: EC2 - " 3 : -7,\n" // alg: ES256 - " -1 : 1,\n" // EC id: P256 - // The regex {(0x[0-9a-f]{2}, ){31}0x[0-9a-f]{2}} matches a - // sequence of 32 hexadecimal bytes, enclosed in braces and - // separated by commas. In this case, some Ed25519 public key. - " -2 : {(0x[0-9a-f]{2}, ){31}0x[0-9a-f]{2}},\n" // pub_x: data - " -3 : {(0x[0-9a-f]{2}, ){31}0x[0-9a-f]{2}},\n" // pub_y: data - "}")); + EXPECT_THAT( + cppbor::prettyPrint(parsedPayload.get()), + MatchesRegex("\\{\n" + " 1 : 2,\n" // kty: EC2 + " 3 : -7,\n" // alg: ES256 + " -1 : 1,\n" // EC id: P256 + // The regex {(0x[0-9a-f]{2}, ){31}0x[0-9a-f]{2}} matches a + // sequence of 32 hexadecimal bytes, enclosed in braces and + // separated by commas. In this case, some Ed25519 public key. + " -2 : \\{(0x[0-9a-f]{2}, ){31}0x[0-9a-f]{2}\\},\n" // pub_x: data + " -3 : \\{(0x[0-9a-f]{2}, ){31}0x[0-9a-f]{2}\\},\n" // pub_y: data + "\\}")); } }