Search in sources :

Example 11 with BaseEncoding

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));
}
Also used : BaseEncoding(com.google.common.io.BaseEncoding)

Example 12 with BaseEncoding

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);
}
Also used : BaseEncoding(com.google.common.io.BaseEncoding)

Example 13 with BaseEncoding

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.
        }
    }
}
Also used : IOException(java.io.IOException) Artifact(com.google.devtools.build.lib.actions.Artifact) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) BaseEncoding(com.google.common.io.BaseEncoding)

Example 14 with BaseEncoding

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()));
    }
}
Also used : HashFunction(com.google.common.hash.HashFunction) BaseEncoding(com.google.common.io.BaseEncoding)

Example 15 with BaseEncoding

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);
}
Also used : List(java.util.List) BaseEncoding(com.google.common.io.BaseEncoding)

Aggregations

BaseEncoding (com.google.common.io.BaseEncoding)21 HashFunction (com.google.common.hash.HashFunction)3 IOException (java.io.IOException)2 Test (org.junit.Test)2 GoogleJsonError (com.google.api.client.googleapis.json.GoogleJsonError)1 GenericUrl (com.google.api.client.http.GenericUrl)1 HttpHeaders (com.google.api.client.http.HttpHeaders)1 HttpRequest (com.google.api.client.http.HttpRequest)1 HttpRequestFactory (com.google.api.client.http.HttpRequestFactory)1 HttpResponse (com.google.api.client.http.HttpResponse)1 LowLevelHttpResponse (com.google.api.client.http.LowLevelHttpResponse)1 JsonHttpContent (com.google.api.client.http.json.JsonHttpContent)1 JsonFactory (com.google.api.client.json.JsonFactory)1 Insert (com.google.api.services.storage.Storage.Objects.Insert)1 StorageObject (com.google.api.services.storage.model.StorageObject)1 AppIdentityService (com.google.appengine.api.appidentity.AppIdentityService)1 Artifact (com.google.devtools.build.lib.actions.Artifact)1 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)1 Gson (com.google.gson.Gson)1 Salt (edu.stanford.bmir.protege.web.shared.auth.Salt)1