From a36e6c750f13f973f6d7268a93afb7dfbe74c0c4 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Wed, 7 Nov 2012 10:43:56 -0300 Subject: [PATCH] renamed syntax of base64 url-safe to be consistent with guava 14 + fixed bad import from prior PR --- .../org/jclouds/crypto/CryptoStreams.java | 6 +++++- .../org/jclouds/crypto/CryptoStreamsTest.java | 20 +++++++++---------- .../test/java/org/jclouds/io/CryptoTest.java | 3 +-- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/org/jclouds/crypto/CryptoStreams.java b/core/src/main/java/org/jclouds/crypto/CryptoStreams.java index 750299bcfa..8ea6c0d933 100644 --- a/core/src/main/java/org/jclouds/crypto/CryptoStreams.java +++ b/core/src/main/java/org/jclouds/crypto/CryptoStreams.java @@ -83,11 +83,15 @@ public class CryptoStreams { * encodes value substituting {@code '-' and '_'} for {@code '+' and '/'}, * and without adding trailing {@code '='} padding. * + *

Note

+ * This utility will be replaced with Guava 14+ BaseEncoding.base64Url() + * * @see url-safe * encoding */ - public static String base64URLSafe(byte[] in) { + @Beta + public static String base64Url(byte[] in) { String provisional = base64(in); int length = provisional.length(); if (length == 0) diff --git a/core/src/test/java/org/jclouds/crypto/CryptoStreamsTest.java b/core/src/test/java/org/jclouds/crypto/CryptoStreamsTest.java index d4914d06fc..3255a64d50 100644 --- a/core/src/test/java/org/jclouds/crypto/CryptoStreamsTest.java +++ b/core/src/test/java/org/jclouds/crypto/CryptoStreamsTest.java @@ -48,13 +48,13 @@ public class CryptoStreamsTest { } @Test - public void testBase64DecodeURLSafeJson() throws IOException { + public void testBase64DecodeUrlJson() throws IOException { byte[] decoded = CryptoStreams.base64("eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9"); assertEquals(new String(decoded, Charsets.UTF_8), "{\"alg\":\"RS256\",\"typ\":\"JWT\"}"); } @Test - public void testBase64DecodeURLSafeNoPadding() throws IOException { + public void testBase64DecodeUrlNoPadding() throws IOException { byte[] decoded = CryptoStreams .base64("eyJpc3MiOiI3NjEzMjY3OTgwNjktcjVtbGpsbG4xcmQ0bHJiaGc3NWVmZ2lncDM2bTc4ajVAZGV2ZWxvcGVyLmdzZXJ2aWNlYWNjb3VudC5jb20iLCJzY29wZSI6Imh0dHBzOi8vd3d3Lmdvb2dsZWFwaXMuY29tL2F1dGgvcHJlZGljdGlvbiIsImF1ZCI6Imh0dHBzOi8vYWNjb3VudHMuZ29vZ2xlLmNvbS9vL29hdXRoMi90b2tlbiIsImV4cCI6MTMyODU1NDM4NSwiaWF0IjoxMzI4NTUwNzg1fQ"); @@ -67,27 +67,27 @@ public class CryptoStreamsTest { } @Test - public void testBase64EncodeURLSafeNoSinglePad() { + public void testBase64EncodeUrlNoSinglePad() { assertEquals(CryptoStreams.base64("any carnal pleasu".getBytes(Charsets.UTF_8)), "YW55IGNhcm5hbCBwbGVhc3U="); - assertEquals(CryptoStreams.base64URLSafe("any carnal pleasu".getBytes(Charsets.UTF_8)), "YW55IGNhcm5hbCBwbGVhc3U"); + assertEquals(CryptoStreams.base64Url("any carnal pleasu".getBytes(Charsets.UTF_8)), "YW55IGNhcm5hbCBwbGVhc3U"); } @Test - public void testBase64EncodeURLSafeNoDoublePad() { + public void testBase64EncodeUrlNoDoublePad() { assertEquals(CryptoStreams.base64("any carnal pleas".getBytes(Charsets.UTF_8)), "YW55IGNhcm5hbCBwbGVhcw=="); - assertEquals(CryptoStreams.base64URLSafe("any carnal pleas".getBytes(Charsets.UTF_8)), "YW55IGNhcm5hbCBwbGVhcw"); + assertEquals(CryptoStreams.base64Url("any carnal pleas".getBytes(Charsets.UTF_8)), "YW55IGNhcm5hbCBwbGVhcw"); } @Test - public void testBase64EncodeURLSafeHyphenNotPlus() { + public void testBase64EncodeUrlHyphenNotPlus() { assertEquals(CryptoStreams.base64("i?>".getBytes(Charsets.UTF_8)), "aT8+"); - assertEquals(CryptoStreams.base64URLSafe("i?>".getBytes(Charsets.UTF_8)), "aT8-"); + assertEquals(CryptoStreams.base64Url("i?>".getBytes(Charsets.UTF_8)), "aT8-"); } @Test - public void testBase64EncodeURLSafeUnderscoreNotSlash() { + public void testBase64EncodeUrlUnderscoreNotSlash() { assertEquals(CryptoStreams.base64("i??".getBytes(Charsets.UTF_8)), "aT8/"); - assertEquals(CryptoStreams.base64URLSafe("i??".getBytes(Charsets.UTF_8)), "aT8_"); + assertEquals(CryptoStreams.base64Url("i??".getBytes(Charsets.UTF_8)), "aT8_"); } @Test diff --git a/core/src/test/java/org/jclouds/io/CryptoTest.java b/core/src/test/java/org/jclouds/io/CryptoTest.java index 3097885962..5a7dacf184 100644 --- a/core/src/test/java/org/jclouds/io/CryptoTest.java +++ b/core/src/test/java/org/jclouds/io/CryptoTest.java @@ -18,6 +18,7 @@ */ package org.jclouds.io; +import static javax.xml.bind.DatatypeConverter.parseBase64Binary; import static org.testng.Assert.assertEquals; import java.io.IOException; @@ -29,8 +30,6 @@ import java.util.concurrent.CompletionService; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorCompletionService; -import static javax.xml.bind.DatatypeConverter.*; - import org.jclouds.PerformanceTest; import org.jclouds.crypto.Crypto; import org.jclouds.crypto.CryptoStreams;