use of com.google.common.annotations.VisibleForTesting in project keywhiz by square.
the class GenerateAesKeyCommand method generate.
@VisibleForTesting
static void generate(char[] password, Path destination, int keySize, String alias, SecureRandom random) throws Exception {
KeyGenerator generator = KeyGenerator.getInstance("AES");
generator.init(keySize, random);
SecretKey key = generator.generateKey();
KeyStore keyStore = KeyStore.getInstance("JCEKS");
// KeyStores must be initialized before use.
keyStore.load(null);
keyStore.setKeyEntry(alias, key, password, null);
try (OutputStream out = Files.newOutputStream(destination)) {
keyStore.store(out, password);
}
}
use of com.google.common.annotations.VisibleForTesting in project keywhiz by square.
the class SecretDAO method createSecret.
@VisibleForTesting
public long createSecret(String name, String encryptedSecret, String hmac, String creator, Map<String, String> metadata, long expiry, String description, @Nullable String type, @Nullable Map<String, String> generationOptions) {
return dslContext.transactionResult(configuration -> {
SecretContentDAO secretContentDAO = secretContentDAOFactory.using(configuration);
SecretSeriesDAO secretSeriesDAO = secretSeriesDAOFactory.using(configuration);
Optional<SecretSeries> secretSeries = secretSeriesDAO.getSecretSeriesByName(name);
long secretId;
if (secretSeries.isPresent()) {
SecretSeries secretSeries1 = secretSeries.get();
if (secretSeries1.currentVersion().isPresent()) {
throw new DataAccessException(format("secret already present: %s", name));
}
secretId = secretSeries1.id();
secretSeriesDAO.updateSecretSeries(secretId, name, creator, description, type, generationOptions);
} else {
secretId = secretSeriesDAO.createSecretSeries(name, creator, description, type, generationOptions);
}
long secretContentId = secretContentDAO.createSecretContent(secretId, encryptedSecret, hmac, creator, metadata, expiry);
secretSeriesDAO.setCurrentVersion(secretId, secretContentId);
return secretId;
});
}
use of com.google.common.annotations.VisibleForTesting in project keywhiz by square.
the class SecretDAO method partialUpdateSecret.
@VisibleForTesting
public long partialUpdateSecret(String name, String creator, PartialUpdateSecretRequestV2 request) {
return dslContext.transactionResult(configuration -> {
SecretContentDAO secretContentDAO = secretContentDAOFactory.using(configuration);
SecretSeriesDAO secretSeriesDAO = secretSeriesDAOFactory.using(configuration);
SecretSeries secretSeries = secretSeriesDAO.getSecretSeriesByName(name).orElseThrow(NotFoundException::new);
Long currentVersion = secretSeries.currentVersion().orElseThrow(NotFoundException::new);
SecretContent secretContent = secretContentDAO.getSecretContentById(currentVersion).orElseThrow(NotFoundException::new);
long secretId = secretSeries.id();
String description = request.descriptionPresent() ? request.description() : secretSeries.description();
String type = request.typePresent() ? request.type() : secretSeries.type().orElse("");
ImmutableMap<String, String> metadata = request.metadataPresent() ? request.metadata() : secretContent.metadata();
Long expiry = request.expiryPresent() ? request.expiry() : secretContent.expiry();
String encryptedContent = secretContent.encryptedContent();
String hmac = secretContent.hmac();
if (request.contentPresent()) {
hmac = cryptographer.computeHmac(request.content().getBytes(UTF_8));
if (hmac == null) {
throw new ContentEncodingException("Error encoding content for SecretBuilder!");
}
encryptedContent = cryptographer.encryptionKeyDerivedFrom(name).encrypt(request.content());
}
secretSeriesDAO.updateSecretSeries(secretId, name, creator, description, type, secretSeries.generationOptions());
long secretContentId = secretContentDAO.createSecretContent(secretId, encryptedContent, hmac, creator, metadata, expiry);
secretSeriesDAO.setCurrentVersion(secretId, secretContentId);
return secretId;
});
}
use of com.google.common.annotations.VisibleForTesting in project bazel by bazelbuild.
the class SkyframeExecutor method maybeInjectEmbeddedArtifacts.
@VisibleForTesting
void maybeInjectEmbeddedArtifacts() throws AbruptExitException {
if (!needToInjectEmbeddedArtifacts) {
return;
}
Preconditions.checkNotNull(artifactFactory.get());
Preconditions.checkNotNull(binTools);
Map<SkyKey, SkyValue> values = Maps.newHashMap();
// Blaze separately handles the symlinks that target these binaries. See BinTools#setupTool.
for (Artifact artifact : binTools.getAllEmbeddedArtifacts(artifactFactory.get())) {
FileArtifactValue fileArtifactValue;
try {
fileArtifactValue = FileArtifactValue.create(artifact);
} catch (IOException e) {
// See ExtractData in blaze.cc.
String message = "Error: corrupt installation: file " + artifact.getPath() + " missing. " + "Please remove '" + directories.getInstallBase() + "' and try again.";
throw new AbruptExitException(message, ExitCode.LOCAL_ENVIRONMENTAL_ERROR, e);
}
values.put(ArtifactSkyKey.key(artifact, /*isMandatory=*/
true), fileArtifactValue);
}
injectable().inject(values);
needToInjectEmbeddedArtifacts = false;
}
use of com.google.common.annotations.VisibleForTesting in project bazel by bazelbuild.
the class RepositoryDelegatorFunction method unescape.
// Unescape a value from the marker file
@VisibleForTesting
static String unescape(String str) {
if (str.equals("\\0")) {
// \0 == null string
return null;
}
StringBuffer result = new StringBuffer();
boolean escaped = false;
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if (escaped) {
if (c == 'n') {
// n means new line
result.append("\n");
} else if (c == 's') {
// s means space
result.append(" ");
} else {
// Any other escaped characters are just un-escaped
result.append(c);
}
escaped = false;
} else if (c == '\\') {
escaped = true;
} else {
result.append(c);
}
}
return result.toString();
}
Aggregations