Пример #1
0
 public void testSamples() throws IOException {
   assertTrue(Arrays.areEqual(sample1Bytes, UrlBase64.decode(sample1)));
   assertTrue(Arrays.areEqual(sample1Bytes, UrlBase64.decode(Strings.toByteArray(sample1))));
   assertTrue(Arrays.areEqual(sample2Bytes, UrlBase64.decode(sample2)));
   assertTrue(Arrays.areEqual(sample2Bytes, UrlBase64.decode(Strings.toByteArray(sample2))));
   assertTrue(Arrays.areEqual(sample3Bytes, UrlBase64.decode(sample3)));
   assertTrue(Arrays.areEqual(sample3Bytes, UrlBase64.decode(Strings.toByteArray(sample3))));
 }
Пример #2
0
  public void testInvalidInput() throws IOException {
    String[] invalid =
        new String[] {
          invalid1, invalid2, invalid3, invalid4, invalid5, invalid6, invalid7, invalid8, invalid9,
          invalida, invalidb, invalidc, invalidd
        };

    for (int i = 0; i != invalid.length; i++) {
      invalidTest(invalid[i]);
      invalidTest(Strings.toByteArray(invalid[i]));
    }
  }
  /**
   * Convert an inline encoded hex string rendition of an ASN.1 object back into its corresponding
   * ASN.1 object.
   *
   * @param str the hex encoded object
   * @param off the index at which the encoding starts
   * @return the decoded object
   */
  protected ASN1Primitive convertHexEncoded(String str, int off) throws IOException {
    str = Strings.toLowerCase(str);
    byte[] data = new byte[(str.length() - off) / 2];
    for (int index = 0; index != data.length; index++) {
      char left = str.charAt((index * 2) + off);
      char right = str.charAt((index * 2) + off + 1);

      if (left < 'a') {
        data[index] = (byte) ((left - '0') << 4);
      } else {
        data[index] = (byte) ((left - 'a' + 10) << 4);
      }
      if (right < 'a') {
        data[index] |= (byte) (right - '0');
      } else {
        data[index] |= (byte) (right - 'a' + 10);
      }
    }

    ASN1InputStream aIn = new ASN1InputStream(data);

    return aIn.readObject();
  }