harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r410179 - in /incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security: asn1/ x501/
Date Tue, 30 May 2006 03:17:00 GMT
Author: smishura
Date: Mon May 29 20:16:59 2006
New Revision: 410179

URL: http://svn.apache.org/viewvc?rev=410179&view=rev
Log:
Reducing number of identifier vars: tagClass, isConstructed, tagNumber, tag were replaced
with id, constrId. Methods checkTag, encodeASN are abstract now in ASN1Type base class.

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/ASN1Constructured.java
  (contents, props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/ASN1Explicit.java
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/ASN1Implicit.java
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/ASN1Primitive.java
  (contents, props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/ASN1StringType.java
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/ASN1Type.java
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x501/AttributeValue.java
  (contents, props changed)

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/ASN1Constructured.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/ASN1Constructured.java?rev=410179&r1=410178&r2=410179&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/ASN1Constructured.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/ASN1Constructured.java
Mon May 29 20:16:59 2006
@@ -31,10 +31,29 @@
 public abstract class ASN1Constructured extends ASN1Type {
 
     public ASN1Constructured(int tagNumber) {
-        super(CLASS_UNIVERSAL, true, tagNumber);
+        super(CLASS_UNIVERSAL, tagNumber);
     }
 
     public ASN1Constructured(int tagClass, int tagNumber) {
-        super(tagClass, true, tagNumber);
+        super(tagClass, tagNumber);
+    }
+    
+    /**
+     * Tests provided identifier.
+     *
+     * @param identifier - identifier to be verified
+     * @return - true if identifier correspond to constructed identifier of
+     *           this ASN.1 type, otherwise false
+     */
+    public final boolean checkTag(int identifier) {
+        return this.constrId == identifier;
+    }
+    
+    /**
+     *
+     */
+    public void encodeASN(BerOutputStream out) {
+        out.encodeTag(constrId);
+        encodeContent(out);
     }
 }

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/ASN1Constructured.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/ASN1Explicit.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/ASN1Explicit.java?rev=410179&r1=410178&r2=410179&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/ASN1Explicit.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/ASN1Explicit.java
Mon May 29 20:16:59 2006
@@ -70,11 +70,11 @@
     //
 
     public Object decode(BerInputStream in) throws IOException {
-        if (tag != in.tag) {
+        if (constrId != in.tag) {
             throw new ASN1Exception(
                     "ASN.1 explicitly tagged type is expected at ["
                             + in.tagOffset + "]. Expected tag: "
-                            + Integer.toHexString(tag)
+                            + Integer.toHexString(constrId)
                             + ", but encountered tag "
                             + Integer.toHexString(in.tag));
         }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/ASN1Implicit.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/ASN1Implicit.java?rev=410179&r1=410178&r2=410179&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/ASN1Implicit.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/ASN1Implicit.java
Mon May 29 20:16:59 2006
@@ -31,9 +31,23 @@
  */
 public class ASN1Implicit extends ASN1Type {
 
+    // primitive type of tagging
+    private static final int TAGGING_PRIMITIVE = 0;
+
+    // constructed type of tagging
+    private static final int TAGGING_CONSTRUCTED = 1;
+
+    // string type of tagging
+    private static final int TAGGING_STRING = 2;
+
+    // tagged ASN.1 type
     private final ASN1Type type;
 
-    private final int strTag;
+    // type of tagging. There are three of them
+    // 1) primitive: only primitive identifier is valid
+    // 2) constructed: only constructed identifier is valid
+    // 3) string: both identifiers are valid
+    private final int taggingType;
 
     /**
      * Constructs implicitly tagged ASN.1 type
@@ -56,7 +70,7 @@
      * @throws IllegalArgumentException - if tagNumber, tagClass or type is invalid
      */
     public ASN1Implicit(int tagClass, int tagNumber, ASN1Type type) {
-        super(tagClass, (type.tag & PC_CONSTRUCTED) > 0, tagNumber);
+        super(tagClass, tagNumber);
 
         if ((type instanceof ASN1Choice) || (type instanceof ASN1Any)) {
             // According to X.680:
@@ -67,10 +81,21 @@
                     "Implicit tagging can not be used for ASN.1 ANY or CHOICE type");
         }
 
-        strTag = (type instanceof ASN1StringType) ? tagClass | PC_CONSTRUCTED
-                | tagNumber : -1;
-
         this.type = type;
+
+        if (type.checkTag(type.id)) {
+            if (type.checkTag(type.constrId)) {
+                // the base encoding can be primitive ot constructed
+                // use both encodings
+                taggingType = TAGGING_STRING;
+            } else {
+                // if the base encoding is primitive use primitive encoding
+                taggingType = TAGGING_PRIMITIVE;
+            }
+        } else {
+            // if the base encoding is constructed use constructed encoding
+            taggingType = TAGGING_CONSTRUCTED;
+        }
     }
 
     //
@@ -79,29 +104,40 @@
     //
     //
 
-    public boolean checkTag(int tag) {
-        if (strTag > 0) {
-            return super.checkTag(tag) || tag == strTag;
+    /**
+     * TODO
+     */
+    public final boolean checkTag(int identifier) {
+        switch (taggingType) {
+        case TAGGING_PRIMITIVE:
+            return id == identifier;
+        case TAGGING_CONSTRUCTED:
+            return constrId == identifier;
+        default: // TAGGING_STRING
+            return id == identifier || constrId == identifier;
         }
-        return super.checkTag(tag);
     }
 
+    /**
+     * TODO
+     */
     public Object decode(BerInputStream in) throws IOException {
         if (!checkTag(in.tag)) {
+            // FIXME need look for tagging type
             throw new ASN1Exception(
                     "ASN.1 implicitly tagged type is expected at ["
                             + in.tagOffset + "]. Expected tag: "
-                            + Integer.toHexString(tag)
+                            + Integer.toHexString(id)
                             + ", but encountered tag "
                             + Integer.toHexString(in.tag));
         }
 
-        if (strTag > 0 && (in.tag & ASN1Constants.PC_CONSTRUCTED) != 0) {
-            in.tag = strTag;
+        // substitute indentifier for further decoding
+        if (id == in.tag) {
+            in.tag = type.id;
         } else {
-            in.tag = type.tag;
+            in.tag = type.constrId;
         }
-
         in.content = type.decode(in);
 
         if (in.isVerify) {
@@ -122,6 +158,16 @@
     // Encode
     //
     //
+
+    public void encodeASN(BerOutputStream out) {
+        //FIXME need another way for specifying identifier to be encoded
+        if (taggingType == TAGGING_CONSTRUCTED) {
+            out.encodeTag(constrId);
+        } else {
+            out.encodeTag(id);
+        }
+        encodeContent(out);
+    }
 
     public void encodeContent(BerOutputStream out) {
         type.encodeContent(out);

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/ASN1Primitive.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/ASN1Primitive.java?rev=410179&r1=410178&r2=410179&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/ASN1Primitive.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/ASN1Primitive.java
Mon May 29 20:16:59 2006
@@ -33,4 +33,24 @@
     public ASN1Primitive(int tagNumber) {
         super(tagNumber);
     }
+    
+    /**
+     * Tests provided identifier.
+     * 
+     * @param identifier -
+     *            identifier to be verified
+     * @return - true if identifier correspond to primitive identifier of this
+     *         ASN.1 type, otherwise false
+     */
+    public final boolean checkTag(int identifier) {
+        return this.id == identifier;
+    }
+    
+    /**
+     * TODO
+     */
+    public void encodeASN(BerOutputStream out) {
+        out.encodeTag(id);
+        encodeContent(out);
+    }
 }

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/ASN1Primitive.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/ASN1StringType.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/ASN1StringType.java?rev=410179&r1=410178&r2=410179&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/ASN1StringType.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/ASN1StringType.java
Mon May 29 20:16:59 2006
@@ -92,15 +92,24 @@
     //
     //
 
-    public final boolean checkTag(int tag) {
-        return super.checkTag(tag) || tag == constructedTag;
+    /**
+     * Tests provided identifier.
+     * 
+     * @param identifier -
+     *            identifier to be verified
+     * @return - true if identifier correspond to primitive or constructed
+     *         identifier of this ASN.1 string type, otherwise false
+     */
+    public final boolean checkTag(int identifier) {
+        return this.id == identifier || this.constructedTag == identifier;
     }
+
     public Object decode(BerInputStream in) throws IOException {
         if (!checkTag(in.tag)) {
             //FIXME message: what about constr tag?
             throw new ASN1Exception("ASN.1 String is expected at ["
                     + in.tagOffset + "]. Expected tag: "
-                    + Integer.toHexString(tag) + " but encountered tag "
+                    + Integer.toHexString(id) + " but encountered tag "
                     + Integer.toHexString(in.tag));
         }
         in.readString();
@@ -126,6 +135,11 @@
     // Encode
     //
     //
+    
+    public void encodeASN(BerOutputStream out) {
+        out.encodeTag(id);
+        encodeContent(out);
+    }
 
     public void encodeContent(BerOutputStream out) {
         out.encodeString();

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/ASN1Type.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/ASN1Type.java?rev=410179&r1=410178&r2=410179&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/ASN1Type.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/ASN1Type.java
Mon May 29 20:16:59 2006
@@ -33,16 +33,15 @@
 
 public abstract class ASN1Type implements ASN1Constants {
 
-    public final int tagClass;
-
-    public final boolean isConstructed;
-
-    public final int tagNumber;
+    /**
+     * Integer representation of primitive identifier.
+     */
+    public final int id;
 
     /**
-     * int representation of encoded ASN.1 tag (class + P/C + number)
+     * Integer representation of constructed identifier.
      */
-    public final int tag;
+    public final int constrId;
 
     /**
      * Constructs a primitive, universal ASN.1 type.
@@ -51,7 +50,7 @@
      * @throws IllegalArgumentException - if tagNumber is invalid
      */
     public ASN1Type(int tagNumber) {
-        this(CLASS_UNIVERSAL, false, tagNumber);
+        this(CLASS_UNIVERSAL, tagNumber);
     }
 
     /**
@@ -63,7 +62,7 @@
      * @param tagNumber - ASN.1 tag number.
      * @throws IllegalArgumentException - if tagClass or tagNumber is invalid
      */
-    public ASN1Type(int tagClass, boolean isConstructed, int tagNumber) {
+    public ASN1Type(int tagClass, int tagNumber) {
 
         if (tagNumber < 0) {
             throw new IllegalArgumentException("Negative tag number");
@@ -74,22 +73,16 @@
                 && tagClass != CLASS_PRIVATE) {
             throw new IllegalArgumentException("Wrong tag class");
         }
-        this.tagClass = tagClass;
-        this.isConstructed = isConstructed;
-        this.tagNumber = tagNumber;
 
         if (tagNumber < 31) {
             // short form
-            if (isConstructed) {
-                tag = tagClass | PC_CONSTRUCTED | tagNumber;
-            } else {
-                tag = tagClass | tagNumber;
-            }
+            this.id = tagClass + tagNumber;
         } else {
             // long form
             throw new IllegalArgumentException(
                     "Tag long form is not implemented");
         }
+        this.constrId = this.id + PC_CONSTRUCTED;
     }
 
     /**
@@ -107,7 +100,7 @@
                 return false;
             }
 
-            int curTag = type[i].tag;
+            int curTag = type[i].id;
             for (int j = i + 1; j < type.length; j++) {
                 if (type[j].checkTag(curTag)) {
                     return false;
@@ -116,7 +109,7 @@
         }
 
         if (type[0] instanceof ASN1StringType) {
-            int curTag = type[0].tag | PC_CONSTRUCTED;
+            int curTag = type[0].constrId;
             for (int j = 1; j < type.length; j++) {
                 if (type[j].checkTag(curTag)) {
                     return false;
@@ -172,21 +165,23 @@
 
     /**
      * Decodes ASN.1 type.
-     *
-     * @param in - BER input stream
-     * @throws IOException - if an I/O error occurs or the end of the stream is reached
+     * 
+     * @param in -
+     *            BER input stream
+     * @throws IOException -
+     *             if an I/O error occurs or the end of the stream is reached
      */
     public abstract Object decode(BerInputStream in) throws IOException;
 
     /**
-     * Tests whether provided tag is equal to ASN.1 type tag.
-     *
-     * @param tag - ASN.1 tag to be verified
-     * @return - true if tags are equals, otherwise false
+     * Tests provided identifier.
+     * 
+     * @param identifier -
+     *            identifier to be verified
+     * @return - true if identifier is associated with this ASN.1 type,
+     *         otherwise false
      */
-    public boolean checkTag(int tag) {
-        return this.tag == tag;
-    }
+    public abstract boolean checkTag(int identifier);
 
     //FIXME make me public
     protected abstract Object getDecodedObject(BerInputStream in)
@@ -198,11 +193,12 @@
     //
     //
 
-    public void encodeASN(BerOutputStream out) {
-
-        out.encodeTag(tag);
-        encodeContent(out);
-    }
+    /**
+     * Encodes ASN.1 type.
+     *
+     * @param out - BER output stream
+     */
+    public abstract void encodeASN(BerOutputStream out);
 
     public abstract void encodeContent(BerOutputStream out);
 
@@ -232,6 +228,6 @@
         // TODO decide whether this method is necessary
         //FIXME fix performance
         return this.getClass().getName() + "(tag: 0x"
-                + Integer.toHexString(0xff & this.tag) + ")";
+                + Integer.toHexString(0xff & this.id) + ")";
     }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x501/AttributeValue.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x501/AttributeValue.java?rev=410179&r1=410178&r2=410179&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x501/AttributeValue.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x501/AttributeValue.java
Mon May 29 20:16:59 2006
@@ -129,9 +129,9 @@
     public int getTag() {
         if (tag == -1) {
             if (Utils.isPrintableString(rawString)) {
-                tag = ASN1StringType.PRINTABLESTRING.tag;
+                tag = ASN1StringType.PRINTABLESTRING.id;
             } else {
-                tag = ASN1StringType.UTF8STRING.tag;
+                tag = ASN1StringType.UTF8STRING.id;
             }
         }
         return tag;

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x501/AttributeValue.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message