/** convert a vector of octet strings into a single byte string */
  @DSComment("Private Method")
  @DSBan(DSCat.PRIVATE_METHOD)
  @DSGenerator(
      tool_name = "Doppelganger",
      tool_version = "2.0",
      generated_on = "2013-12-30 13:00:13.221 -0500",
      hash_original_method = "4664D1B75E47F4959701A1C01649EB42",
      hash_generated_method = "742B75D7CF6C93094988DF6E137F66E2")
  private static byte[] toBytes(Vector octs) {
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();

    for (int i = 0; i != octs.size(); i++) {
      try {
        DEROctetString o = (DEROctetString) octs.elementAt(i);

        bOut.write(o.getOctets());
      } catch (ClassCastException e) {
        throw new IllegalArgumentException(
            octs.elementAt(i).getClass().getName()
                + " found in input should only contain DEROctetString");
      } catch (IOException e) {
        throw new IllegalArgumentException("exception converting octets " + e.toString());
      }
    }

    return bOut.toByteArray();
  }
  @DSGenerator(
      tool_name = "Doppelganger",
      tool_version = "2.0",
      generated_on = "2013-12-30 13:00:13.244 -0500",
      hash_original_method = "D3D7CE50527B3D09D53342883B1EBD33",
      hash_generated_method = "F90FE6D021EA51EE61FD714A879B9874")
  public void encode(DEROutputStream out) throws IOException {
    if (out instanceof ASN1OutputStream || out instanceof BEROutputStream) {
      out.write(CONSTRUCTED | OCTET_STRING);

      out.write(0x80);

      //
      // write out the octet array
      //
      Enumeration e = getObjects();
      while (e.hasMoreElements()) {
        out.writeObject(e.nextElement());
      }

      out.write(0x00);
      out.write(0x00);
    } else {
      super.encode(out);
    }
  }
Пример #3
0
    public void write(int b) throws IOException {
      _buf[_off++] = (byte) b;

      if (_off == _buf.length) {
        DEROctetString.encode(_derOut, _buf);
        _off = 0;
      }
    }
Пример #4
0
  /** convert a vector of octet strings into a single byte string */
  private static byte[] toBytes(Vector octs) {
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();

    for (int i = 0; i != octs.size(); i++) {
      try {
        DEROctetString o = (DEROctetString) octs.elementAt(i);

        bOut.write(o.getOctets());
      } catch (ClassCastException e) {
        throw new IllegalArgumentException(
            octs.elementAt(i).getClass().getName()
                + " found in input should only contain DEROctetString");
      } catch (IOException e) {
        throw new IllegalArgumentException("exception converting octets " + e.toString());
      }
    }

    return bOut.toByteArray();
  }
Пример #5
0
    public void close() throws IOException {
      if (_off != 0) {
        byte[] bytes = new byte[_off];
        System.arraycopy(_buf, 0, bytes, 0, _off);

        DEROctetString.encode(_derOut, bytes);
      }

      writeBEREnd();
    }
Пример #6
0
    public void write(byte[] b, int off, int len) throws IOException {
      while (len > 0) {
        int numToCopy = Math.min(len, _buf.length - _off);
        System.arraycopy(b, off, _buf, _off, numToCopy);

        _off += numToCopy;
        if (_off < _buf.length) {
          break;
        }

        DEROctetString.encode(_derOut, _buf);
        _off = 0;

        off += numToCopy;
        len -= numToCopy;
      }
    }
  public void encode(DEROutputStream out) throws IOException {
    if (out instanceof ASN1OutputStream || out instanceof BEROutputStream) {
      out.write(CONSTRUCTED | OCTET_STRING);

      out.write(0x80);

      //
      // write out the octet array
      //
      Enumeration e = getObjects();
      while (e.hasMoreElements()) {
        out.writeObject(e.nextElement());
      }

      out.write(0x00);
      out.write(0x00);
    } else {
      super.encode(out);
    }
  }
Пример #8
0
  public void encode(DEROutputStream out) throws IOException {
    if (out instanceof ASN1OutputStream || out instanceof BEROutputStream) {
      out.write(CONSTRUCTED | OCTET_STRING);

      out.write(0x80);

      //
      // write out the octet array
      //
      if (octs != null) {
        for (int i = 0; i != octs.size(); i++) {
          out.writeObject(octs.elementAt(i));
        }
      } else {
        for (int i = 0; i < string.length; i += MAX_LENGTH) {
          int end;

          if (i + MAX_LENGTH > string.length) {
            end = string.length;
          } else {
            end = i + MAX_LENGTH;
          }

          byte[] nStr = new byte[end - i];

          System.arraycopy(string, i, nStr, 0, nStr.length);

          out.writeObject(new DEROctetString(nStr));
        }
      }

      out.write(0x00);
      out.write(0x00);
    } else {
      super.encode(out);
    }
  }