From e497bdac19519962e71eadc30c1ade9da5e364e0 Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Tue, 2 Mar 2021 22:49:01 +0530 Subject: [PATCH] Fixed random Message id, added test for the same --- lib/src/main/java/io/ably/lib/util/Crypto.java | 2 +- lib/src/test/java/io/ably/lib/util/CryptoTest.java | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/src/main/java/io/ably/lib/util/Crypto.java b/lib/src/main/java/io/ably/lib/util/Crypto.java index b20915b02..56ea62fb9 100644 --- a/lib/src/main/java/io/ably/lib/util/Crypto.java +++ b/lib/src/main/java/io/ably/lib/util/Crypto.java @@ -321,7 +321,7 @@ private static int getPaddedLength(int plaintextLength) { public static String getRandomMessageId() { byte[] entropy = new byte[9]; secureRandom.nextBytes(entropy); - return Base64Coder.encode(entropy).toString(); + return Base64Coder.encodeToString(entropy); } /** diff --git a/lib/src/test/java/io/ably/lib/util/CryptoTest.java b/lib/src/test/java/io/ably/lib/util/CryptoTest.java index a9fec56de..f89541be3 100644 --- a/lib/src/test/java/io/ably/lib/util/CryptoTest.java +++ b/lib/src/test/java/io/ably/lib/util/CryptoTest.java @@ -199,4 +199,10 @@ private static byte[] msgPacked(final String name, final byte[] data, final Stri return out.toByteArray(); } + + @Test + public void getRandomId() { + String randomId = Crypto.getRandomMessageId(); + assertEquals(12, randomId.length()); + } }