use of com.google.common.io.BaseEncoding in project graylog2-server by Graylog2.
the class Base64UrlEncode method getEncodedValue.
@Override
protected String getEncodedValue(String value, boolean omitPadding) {
BaseEncoding encoding = BaseEncoding.base64Url();
encoding = omitPadding ? encoding.omitPadding() : encoding;
return encoding.encode(value.getBytes(StandardCharsets.UTF_8));
}
use of com.google.common.io.BaseEncoding in project graylog2-server by Graylog2.
the class Base32Decode method getEncodedValue.
@Override
protected String getEncodedValue(String value, boolean omitPadding) {
BaseEncoding encoding = BaseEncoding.base32Hex();
encoding = omitPadding ? encoding.omitPadding() : encoding;
return new String(encoding.decode(value), StandardCharsets.UTF_8);
}
use of com.google.common.io.BaseEncoding in project bazel by bazelbuild.
the class ActionMetadataHandler method injectDigest.
@Override
public void injectDigest(ActionInput output, FileStatus statNoFollow, byte[] digest) {
// Assumption: any non-Artifact output is 'virtual' and should be ignored here.
if (output instanceof Artifact) {
final Artifact artifact = (Artifact) output;
Preconditions.checkState(injectedFiles.add(artifact), artifact);
FileValue fileValue;
try {
// This call may do an unnecessary call to Path#getFastDigest to see if the digest is
// readily available. We cannot pass the digest in, though, because if it is not available
// from the filesystem, this FileValue will not compare equal to another one created for the
// same file, because the other one will be missing its digest.
fileValue = fileValueFromArtifact(artifact, FileStatusWithDigestAdapter.adapt(statNoFollow), getTimestampGranularityMonitor(artifact));
// Ensure the digest supplied matches the actual digest if it exists.
byte[] fileDigest = fileValue.getDigest();
if (fileDigest != null && !Arrays.equals(digest, fileDigest)) {
BaseEncoding base16 = BaseEncoding.base16();
String digestString = (digest != null) ? base16.encode(digest) : "null";
String fileDigestString = base16.encode(fileDigest);
throw new IllegalStateException("Expected digest " + digestString + " for artifact " + artifact + ", but got " + fileDigestString + " (" + fileValue + ")");
}
outputArtifactData.put(artifact, fileValue);
} catch (IOException e) {
// when somebody will try to access that file.
return;
}
// running with a filesystem that supports fast digests, this is fairly unlikely.
try {
maybeStoreAdditionalData(artifact, fileValue, digest);
} catch (IOException e) {
if (fileValue.getSize() != 0) {
// should throw, since all filesystem access has already been done.
throw new IllegalStateException("Filesystem should not have been accessed while injecting data for " + artifact.prettyPrint(), e);
}
// Ignore exceptions for empty files, as above.
}
}
}
use of com.google.common.io.BaseEncoding in project google-cloud-java by GoogleCloudPlatform.
the class HttpStorageRpc method setEncryptionHeaders.
private static void setEncryptionHeaders(HttpHeaders headers, String headerPrefix, Map<Option, ?> options) {
String key = Option.CUSTOMER_SUPPLIED_KEY.getString(options);
if (key != null) {
BaseEncoding base64 = BaseEncoding.base64();
HashFunction hashFunction = Hashing.sha256();
headers.set(headerPrefix + "algorithm", "AES256");
headers.set(headerPrefix + "key", key);
headers.set(headerPrefix + "key-sha256", base64.encode(hashFunction.hashBytes(base64.decode(key)).asBytes()));
}
}
use of com.google.common.io.BaseEncoding in project controller by opendaylight.
the class SimpleBinaryAttributeWritingStrategy method preprocess.
@Override
protected Object preprocess(final Object value) {
Util.checkType(value, List.class);
BaseEncoding en = BaseEncoding.base64();
List<?> list = (List<?>) value;
byte[] decoded = new byte[list.size()];
int index = 0;
for (Object basStr : list) {
Preconditions.checkArgument(basStr instanceof String, "Unexpected inner value for %s, expected string", value);
decoded[index++] = Byte.parseByte((String) basStr);
}
return en.encode(decoded);
}
Aggregations