SubtleUtil { public static void putAsUnsigedInt(ByteBuffer buffer, long value) throws GeneralSecurityException { if (!(0 <= value && value < 0x100000000L)) { throw new GeneralSecurityException("Index out of range"); } buffer.putInt((int) value); }  static String toEcdsaAlgo(HashType hash); static String toRsaSsaPkcs1Algo(HashType hash); static String toDigestAlgo(HashType hash); static boolean isAndroid(); static BigInteger bytes2Integer(byte[] bs); static byte[] integer2Bytes(BigInteger num, int intendedLength); static byte[] mgf1(byte[] mgfSeed, int maskLen, HashType mgfHash); static void putAsUnsigedInt(ByteBuffer buffer, long value);  }
@Test public void testPutAsUnsigedInt_smallNumber() throws Exception { ByteBuffer buffer = ByteBuffer.allocate(4); SubtleUtil.putAsUnsigedInt(buffer, 0x1122EEFFL); assertThat(buffer.array()).isEqualTo(new byte[] {0x11, 0x22, (byte) 0xEE, (byte) 0xFF}); }
@Test public void testPutAsUnsigedInt_largeNumber() throws Exception { ByteBuffer buffer = ByteBuffer.allocate(4); SubtleUtil.putAsUnsigedInt(buffer, 0xFFEEDDCCL); assertThat(buffer.array()) .isEqualTo(new byte[] {(byte) 0xFF, (byte) 0xEE, (byte) 0xDD, (byte) 0xCC}); }
@Test public void testPutAsUnsigedInt_max() throws Exception { ByteBuffer buffer = ByteBuffer.allocate(4); SubtleUtil.putAsUnsigedInt(buffer, 0xFFFFFFFFL); assertThat(buffer.array()) .isEqualTo(new byte[] {(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF}); }
@Test public void testPutAsUnsigedInt_tooLargeNumber_throws() throws Exception { ByteBuffer buffer = ByteBuffer.allocate(4); try { SubtleUtil.putAsUnsigedInt(buffer, 0xFFFFFFFFL + 1L); fail(); } catch (GeneralSecurityException e) { } }
@Test public void testPutAsUnsigedInt_minusOne_throws() throws Exception { ByteBuffer buffer = ByteBuffer.allocate(4); try { SubtleUtil.putAsUnsigedInt(buffer, -1); fail(); } catch (GeneralSecurityException e) { } }