public static CryptoKeyPathName parse(String formattedString) { if (formattedString.isEmpty()) { return null; } Map<String, String> matchMap = PATH_TEMPLATE.validatedMatch( formattedString, "CryptoKeyPathName.parse: formattedString not in valid format"); return of( matchMap.get("project"), matchMap.get("location"), matchMap.get("key_ring"), matchMap.get("crypto_key_path")); }
public static List<CryptoKeyPathName> parseList(List<String> formattedStrings) { List<CryptoKeyPathName> list = new ArrayList<>(formattedStrings.size()); for (String formattedString : formattedStrings) { list.add(parse(formattedString)); } return list; }
public static String format( String project, String location, String keyRing, String cryptoKeyPath) { return newBuilder() .setProject(project) .setLocation(location) .setKeyRing(keyRing) .setCryptoKeyPath(cryptoKeyPath) .build() .toString(); }
@Test @SuppressWarnings("all") public void encryptTest() { String name2 = "name2-1052831874"; ByteString ciphertext = ByteString.copyFromUtf8("-72"); EncryptResponse expectedResponse = EncryptResponse.newBuilder().setName(name2).setCiphertext(ciphertext).build(); mockKeyManagementService.addResponse(expectedResponse); CryptoKeyPathName name = CryptoKeyPathName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY_PATH]"); ByteString plaintext = ByteString.copyFromUtf8("-9"); EncryptResponse actualResponse = client.encrypt(name, plaintext); Assert.assertEquals(expectedResponse, actualResponse); List<GeneratedMessageV3> actualRequests = mockKeyManagementService.getRequests(); Assert.assertEquals(1, actualRequests.size()); EncryptRequest actualRequest = (EncryptRequest) actualRequests.get(0); Assert.assertEquals(name, CryptoKeyPathName.parse(actualRequest.getName())); Assert.assertEquals(plaintext, actualRequest.getPlaintext()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
public static List<String> toStringList(List<CryptoKeyPathName> values) { List<String> list = new ArrayList<String>(values.size()); for (CryptoKeyPathName value : values) { if (value == null) { list.add(""); } else { list.add(value.toString()); } } return list; }
public static CryptoKeyPathName of( String project, String location, String keyRing, String cryptoKeyPath) { return newBuilder() .setProject(project) .setLocation(location) .setKeyRing(keyRing) .setCryptoKeyPath(cryptoKeyPath) .build(); }
public CryptoKeyPathName build() { return new CryptoKeyPathName(this); } }
public String getFieldValue(String fieldName) { return getFieldValuesMap().get(fieldName); }
.setName(name == null ? null : name.toString()) .setPlaintext(plaintext) .build();
public static CryptoKeyPathName of( String project, String location, String keyRing, String cryptoKeyPath) { return newBuilder() .setProject(project) .setLocation(location) .setKeyRing(keyRing) .setCryptoKeyPath(cryptoKeyPath) .build(); }
public CryptoKeyPathName build() { return new CryptoKeyPathName(this); } }
public String getFieldValue(String fieldName) { return getFieldValuesMap().get(fieldName); }
public static String format( String project, String location, String keyRing, String cryptoKeyPath) { return newBuilder() .setProject(project) .setLocation(location) .setKeyRing(keyRing) .setCryptoKeyPath(cryptoKeyPath) .build() .toString(); }
public static List<String> toStringList(List<CryptoKeyPathName> values) { List<String> list = new ArrayList<String>(values.size()); for (CryptoKeyPathName value : values) { if (value == null) { list.add(""); } else { list.add(value.toString()); } } return list; }
@Test @SuppressWarnings("all") public void encryptExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockKeyManagementService.addException(exception); try { CryptoKeyPathName name = CryptoKeyPathName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY_PATH]"); ByteString plaintext = ByteString.copyFromUtf8("-9"); client.encrypt(name, plaintext); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception } }
public static List<CryptoKeyPathName> parseList(List<String> formattedStrings) { List<CryptoKeyPathName> list = new ArrayList<>(formattedStrings.size()); for (String formattedString : formattedStrings) { list.add(parse(formattedString)); } return list; }
.setName(name == null ? null : name.toString()) .setPlaintext(plaintext) .build();
public static CryptoKeyPathName parse(String formattedString) { if (formattedString.isEmpty()) { return null; } Map<String, String> matchMap = PATH_TEMPLATE.validatedMatch( formattedString, "CryptoKeyPathName.parse: formattedString not in valid format"); return of( matchMap.get("project"), matchMap.get("location"), matchMap.get("key_ring"), matchMap.get("crypto_key_path")); }