You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by ga...@apache.org on 2014/06/18 03:56:20 UTC
git commit: Store hashes as HashCode for type-safety
Repository: jclouds-labs-aws
Updated Branches:
refs/heads/master f8e5892a6 -> 09b23def1
Store hashes as HashCode for type-safety
Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs-aws/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs-aws/commit/09b23def
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs-aws/tree/09b23def
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs-aws/diff/09b23def
Branch: refs/heads/master
Commit: 09b23def1aa8eb8f5268d621a70914f8f9456757
Parents: f8e5892
Author: Andrew Gaul <ga...@apache.org>
Authored: Mon Jun 16 16:46:56 2014 -0700
Committer: Andrew Gaul <ga...@apache.org>
Committed: Tue Jun 17 18:55:32 2014 -0700
----------------------------------------------------------------------
.../jclouds/glacier/util/AWSRequestSignerV4.java | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds-labs-aws/blob/09b23def/glacier/src/main/java/org/jclouds/glacier/util/AWSRequestSignerV4.java
----------------------------------------------------------------------
diff --git a/glacier/src/main/java/org/jclouds/glacier/util/AWSRequestSignerV4.java b/glacier/src/main/java/org/jclouds/glacier/util/AWSRequestSignerV4.java
index 50dda64..3b9b2ba 100644
--- a/glacier/src/main/java/org/jclouds/glacier/util/AWSRequestSignerV4.java
+++ b/glacier/src/main/java/org/jclouds/glacier/util/AWSRequestSignerV4.java
@@ -36,6 +36,7 @@ import com.google.common.collect.Iterables;
import com.google.common.collect.Multimap;
import com.google.common.collect.SortedSetMultimap;
import com.google.common.collect.TreeMultimap;
+import com.google.common.hash.HashCode;
import com.google.common.hash.Hashing;
import com.google.common.hash.HashingInputStream;
import com.google.common.io.BaseEncoding;
@@ -70,7 +71,7 @@ public final class AWSRequestSignerV4 {
this.credential = checkNotNull(credential, "credential");
}
- private static String buildHashedCanonicalRequest(String method, String endpoint, String hashedPayload,
+ private static HashCode buildHashedCanonicalRequest(String method, String endpoint, HashCode hashedPayload,
String canonicalizedHeadersString, String signedHeaders) {
return Hashing.sha256().newHasher()
.putString(method, UTF_8)
@@ -82,12 +83,12 @@ public final class AWSRequestSignerV4 {
.putString("\n", UTF_8)
.putString(signedHeaders, UTF_8)
.putString("\n", UTF_8)
- .putString(hashedPayload, UTF_8)
- .hash().toString();
+ .putString(hashedPayload.toString(), UTF_8)
+ .hash();
}
- private static String createStringToSign(String date, String credentialScope, String hashedCanonicalRequest) {
- return ALGORITHM + "\n" + date + "\n" + credentialScope + "\n" + hashedCanonicalRequest;
+ private static String createStringToSign(String date, String credentialScope, HashCode hashedCanonicalRequest) {
+ return ALGORITHM + "\n" + date + "\n" + credentialScope + "\n" + hashedCanonicalRequest.toString();
}
private static String formatDateWithoutTimestamp(String date) {
@@ -133,13 +134,13 @@ public final class AWSRequestSignerV4 {
}));
}
- private static String buildHashedPayload(HttpRequest request) {
+ private static HashCode buildHashedPayload(HttpRequest request) {
HashingInputStream his = null;
try {
his = new HashingInputStream(Hashing.sha256(),
request.getPayload() == null ? ByteSource.empty().openStream() : request.getPayload().openStream());
ByteStreams.copy(his, ByteStreams.nullOutputStream());
- return his.hash().toString();
+ return his.hash();
} catch (IOException e) {
throw new HttpException("Error signing request", e);
} finally {
@@ -181,10 +182,10 @@ public final class AWSRequestSignerV4 {
String method = request.getMethod();
String endpoint = request.getEndpoint().getRawPath();
String credentialScope = buildCredentialScope(dateWithoutTimestamp);
- String hashedPayload = buildHashedPayload(request);
+ HashCode hashedPayload = buildHashedPayload(request);
// Task 1: Create a Canonical Request For Signature Version 4.
- String hashedCanonicalRequest = buildHashedCanonicalRequest(method, endpoint, hashedPayload,
+ HashCode hashedCanonicalRequest = buildHashedCanonicalRequest(method, endpoint, hashedPayload,
canonicalizedHeadersString, signedHeaders);
// Task 2: Create a String to Sign for Signature Version 4.