Package codec.asn1

Examples of codec.asn1.ASN1Type


     */
    public List getAVAList() {
  ASN1ObjectIdentifier oid;
  ASN1Sequence ava;
  ArrayList list;
  ASN1Type obj;
  Iterator i;
  boolean sibling;
  ASN1Set rdn;
  String val;
  String key;
  AVA entry;
  int j;
  int n;

  list = new ArrayList(size());

  for (i = iterator(); i.hasNext();) {
      rdn = (ASN1Set) i.next();
      n = rdn.size();

      for (j = 0; j < n; j++) {
    /*
     * We have to mark siblings. An AVA has a sibling if it is not
     * the last AVA in the set.
     */
    sibling = (j < n - 1);

    /*
     * Convert key and value into strings. These values are then put
     * into an AVA instance.
     */
    ava = (ASN1Sequence) rdn.get(j);
    oid = (ASN1ObjectIdentifier) ava.get(0);
    obj = (ASN1Type) ava.get(1);
    key = (String) oid2a_.get(oid);

    if (key == null) {
        key = oid.toString();
    }
    if (obj instanceof ASN1String) {
        val = ((ASN1String) obj).getString();
        entry = new AVA(key, val, sibling);
    } else {
        /*
         * OK, we have to encode the damn ASN.1 object. Outrageous
         * inefficient but hey, what choice do we have, if it is not
         * a string?
         */
        ByteArrayOutputStream out;
        DEREncoder enc;

        try {
      out = new ByteArrayOutputStream();
      enc = new DEREncoder(out);

      obj.encode(enc);

      entry = new AVA(key, out.toByteArray(), sibling);

      enc.close();
        } catch (Exception e) {
View Full Code Here


     */
    public List getReverseAVAList() {
  ASN1ObjectIdentifier oid;
  ASN1Sequence ava;
  ArrayList list;
  ASN1Type obj;
  boolean sibling;
  ASN1Set rdn;
  String val;
  String key;
  AVA entry;
  int i;
  int j;
  int n;

  list = new ArrayList(size());

  for (i = size() - 1; i >= 0; i--) {
      rdn = (ASN1Set) get(i);
      n = rdn.size();

      for (j = 0; j < n; j++) {
    /*
     * We have to mark siblings. An AVA has a sibling if it is not
     * the last AVA in the set.
     */
    sibling = (j < n - 1);

    /*
     * Convert key and value into strings. These values are then put
     * into an AVA instance.
     */
    ava = (ASN1Sequence) rdn.get(j);
    oid = (ASN1ObjectIdentifier) ava.get(0);
    obj = (ASN1Type) ava.get(1);
    key = (String) oid2a_.get(oid);

    if (key == null) {
        key = oid.toString();
    }
    if (obj instanceof ASN1String) {
        val = ((ASN1String) obj).getString();
        entry = new AVA(key, val, sibling);
    } else {
        /*
         * OK, we have to encode the damn ASN.1 object. Outrageous
         * inefficient but hey, what choice do we have, if it is not
         * a string?
         */
        ByteArrayOutputStream out;
        DEREncoder enc;

        try {
      out = new ByteArrayOutputStream();
      enc = new DEREncoder(out);

      obj.encode(enc);

      entry = new AVA(key, out.toByteArray(), sibling);

      enc.close();
        } catch (Exception e) {
View Full Code Here

     *
     * @throws NoSuchElementException
     *                 if the content type is not {@link Data Data}.
     */
    public Data getData() throws NoSuchElementException {
  ASN1Type o;

  o = content_.getContent();

  if (o == null) {
      return null;
View Full Code Here

     * type {@link Data Data} and the content contained in it is not null.
     *
     * @return <code>true</code> if there is a payload.
     */
    public boolean hasData() {
  ASN1Type o;
  byte[] b;

  o = content_.getContent();

  if (o == null) {
View Full Code Here

     *
     * If the content type is <code>Data</code> then there is no problem
     * because we can simply grab the contents octets from it.
     */
    public void update() throws GeneralSecurityException {
  ASN1Type t;
  boolean tagging;

  t = target_.getContent();

  if (t == null) {
      return;
  }
  if (t instanceof Data) {
      update(((Data) t).getByteArray());
      return;
  }
  ByteArrayOutputStream bos;
  DEREncoder enc;

  /*
   * We know it must be EXPLICIT but hey...
   */
  tagging = t.isExplicit();
  bos = new ByteArrayOutputStream();
  enc = new DEREncoder(bos);

  if (this.strict)
      enc.setStrict(true);

  try {
      t.setExplicit(false);
      enc.writeType(t);

      update(bos.toByteArray());
  } catch (Exception e) {
      throw new SignatureException("Exception while re-encoding!");
  } finally {
      t.setExplicit(tagging);

      try {
    enc.close();
      } catch (Exception e) {
      }
View Full Code Here

     */
    public void encode(Encoder encoder) throws IOException, ASN1Exception {
  /*
   * Yet another nail in my coffin...
   */
  ASN1Type t;
  boolean opt;

  t = (ASN1Type) get(3);
  opt = (auth_.size() == 0);
  t.setOptional(opt);

  t = (ASN1Type) get(6);
  opt = (attr_.size() == 0);
  t.setOptional(opt);

  super.encode(encoder);
    }
View Full Code Here

     *
     * If the content type is <code>Data</code> then there is no problem
     * because we can simply grab the contents octets from it.
     */
    public void update() throws GeneralSecurityException {
  ASN1Type t;
  boolean tagging;

  t = target_.getContent();

  if (t == null) {
      return;
  }
  if (t instanceof Data) {
      update(((Data) t).getByteArray());
      return;
  }
  ByteArrayOutputStream bos;
  DEREncoder enc;

  /*
   * We know it must be EXPLICIT but hey...
   */
  tagging = t.isExplicit();
  bos = new ByteArrayOutputStream();
  enc = new DEREncoder(bos);
  if (this.strict)
      enc.setStrict(true);

  try {
      t.setExplicit(false);
      enc.writeType(t);

      update(bos.toByteArray());
  } catch (Exception e) {
      throw new SignatureException("Exception while re-encoding!");
  } finally {
      t.setExplicit(tagging);

      try {
    enc.close();
      } catch (Exception e) {
    /* Ignore */
 
View Full Code Here

    }

    public void decode(Decoder dec) throws ASN1Exception, IOException {
  super.decode(dec);

  ASN1Type inner = (ASN1Type) super.getValue();

  if (!(inner instanceof ASN1Enumerated)) {
      throw new ASN1Exception("unexpected extension value "
        + inner.toString());
  }
  theReason = (ASN1Enumerated) inner;
    }
View Full Code Here

     *
     * @return The <code>content</code> or <code>null</code> if no content
     *         is available.
     */
    public ASN1Type getContent() {
  ASN1Type o;

  if (content_.isOptional()) {
      return null;
  }
  o = content_.getInnerType();
View Full Code Here

     *                The {@link Decoder Decoder} to use.
     */
    public void decode(Decoder decoder) throws ASN1Exception, IOException {
  super.decode(decoder);

  ASN1Type t;
  ASN1OpenType o;

  if (!content_.isOptional()) {
      t = content_.getInnerType();

View Full Code Here

TOP

Related Classes of codec.asn1.ASN1Type

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.