⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dercoder.java

📁 JAVA开源LDAP浏览器jxplorer的源码!
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                               int length) throws ASN1Exception
    {
        if (length != 1)
        {
            throw new ASN1Exception("Wrong data (BOOLEAN) length");
        }
        boolean v = (stream[offset[0]] == 0) ? false : true;
        o.setValue(new Boolean(v));
        offset[0]++;
    }
    
    /**
     * Decodes INTEGER. Definite-length only.
     */
    private void decodeINTEGER(ASN1Object o, byte [] stream, int [] offset,
                               int length) throws ASN1Exception
    {
        if (length < 1)
        {
            throw new ASN1Exception("Wrong data (INTEGER) length");
        }
        byte [] content = new byte[length];
        System.arraycopy(stream, offset[0], content, 0, length);
        BigInteger v = new BigInteger(content);
        o.setValue(v);
        offset[0] += length;
    }
    
    /**
     * Decodes ENUMERATED. Definite-length only.
     */
    private void decodeENUMERATED(ASN1Object o, byte [] stream, int [] offset,
                                  int length) throws ASN1Exception
    {
        if (length < 1)
        {
            throw new ASN1Exception("Wrong data (INTEGER) length");
        }
        byte [] content = new byte[length];
        System.arraycopy(stream, offset[0], content, 0, length);
        BigInteger v = new BigInteger(content);
        o.setValue(v);
        offset[0] += length;
    }
    
    /**
     * Decodes SEQUENCE.
     */
    private void decodeSEQUENCE(ASN1Object o, byte [] stream, int [] offset,
                                int length) throws ASN1Exception
    {
        int start = offset[0];
        if (length == -1)
        { // indefinite length
            while (true)
            {
                if (stream[offset[0]] == 0
                        && stream[offset[0]+1] == 0)
                {
                    offset[0] += 2;
                    break;
                }
                o.addComponent(decode(stream, offset));
            }
        }
        else
        {
            while (offset[0] < start + length)
            {
                o.addComponent(decode(stream, offset));
            }
            if (offset[0] != start + length)
            {
                throw new ASN1Exception("Wrong data (SEQUENCE) length");
            }
        }
    }
    
    /**
     * Decodes BITSTRING. Assume definite-length only.
     */
    private void decodeBITSTRING(ASN1Object o, byte [] stream, int [] offset,
                                 int length) throws ASN1Exception
    {
        if (length == -1)
        {
            // not implemented
        }
        else
        {
            if (length < 1)
            {
                throw new ASN1Exception("Wrong data (BIT STRING) length");
            }
            byte [] content = new byte[length];
            System.arraycopy(stream, offset[0], content, 0, length);
            o.setValue(content);
            offset[0] += length;
        }
    }
    
    /**
     * Decodes OCTETSTRING. Assume definite-length only.
     */
    private void decodeOCTETSTRING(ASN1Object o, byte [] stream,
                                   int [] offset, int length)
    {
        if (length == -1)
        {
            // not implemented
        }
        else
        {
            byte [] content = new byte[length];
            System.arraycopy(stream, offset[0], content, 0, length);
            o.setValue(content);
            offset[0] += length;
        }
    }
    
    /**
    * Decodes UniversalSTRING. Assume definite-length only.
    */
    private void decodeUniversalString(ASN1Object o, byte [] stream,
                                       int [] offset, int length)
    {
        if (length == -1)
        {
            // not implemented
        }
        else
        {
            byte [] content = new byte[length];
            System.arraycopy(stream, offset[0], content, 0, length);
            o.setValue(content);
            offset[0] += length;
        }
    }
    
    /**
    * Decodes BMPSTRING. Assume definite-length only.
    */
    private void decodeBMPSTRING(ASN1Object o, byte [] stream,
                                 int [] offset, int length)
    {
        if (length == -1)
        {
            // not implemented
        }
        else
        {
            byte [] content = new byte[length];
            System.arraycopy(stream, offset[0], content, 0, length);
            o.setValue(content);
            offset[0] += length;
        }
    }
    
    /**
     * Decodes OBJECT IDENTIFIER. Definite-length only.
     */
    private void decodeOBJECTID(ASN1Object o, byte [] stream, int [] offset,
                                int length) throws ASN1Exception
    {
        if (length < 1)
        {	// at least two components
            throw new ASN1Exception("Wrong data (OBJECT ID) length");
        }
        int end = offset[0] + length;
        int v = stream[offset[0]++];
        String content = Integer.toString(v/40) + " ";
        content += Integer.toString(v%40) + " ";
        
        while (offset[0] < end)
        {
            long l =  0;
            while ((stream[offset[0]] & 0x80) != 0)
            {
                l |= 0x7f & stream[offset[0]++];
                l <<= 7;
            }
            l |= 0x7f & stream[offset[0]++];
            content += Long.toString(l) + " ";
        }
        if (offset[0] != end)
        {
            throw new ASN1Exception("Wrong data (OBJECT ID) length");
        }
        o.setValue(content.trim());
    }
    
    /**
     * Decodes UTCTime. Assume definite-length only.
     */
    private void decodeUTCTime(ASN1Object o, byte [] stream, int [] offset,
                               int length) throws ASN1Exception
    {
        if (length == -1)
        {
            // not implemented
        }
        else
        {
            if (length < 11)
            {		// at least 11 ASCII characters
                throw new ASN1Exception("Wrong data (UTCTime) length");
            }
            o.setValue(new String(stream, offset[0], length));
            offset[0] += length;
        }
    }
    
    /**
     * Decodes GeneralizedTime. Assume definite-length only.
     */
    private void decodeGeneralizedTime(ASN1Object o, byte [] stream, int [] offset,
                                       int length) throws ASN1Exception
    {
        if (length == -1)
        {
            // not implemented
        }
        else
        {
            if (length < 11)
            {		// at least 13 ASCII characters
                throw new ASN1Exception("Wrong data (UTCTime) length");
            }
            o.setValue(new String(stream, offset[0], length));
            offset[0] += length;
        }
    }
    
    /**
     * Decodes PrintableString. Assume definite-length only.
     */
    private void decodePrintableString(ASN1Object o, byte [] stream,
                                       int [] offset, int length)
    {
        if (length == -1)
        {
            // not implemented
        }
        else
        {
            o.setValue(new String(stream, offset[0], length));
            offset[0] += length;
        }
    }
    
    /**
     * Decodes IA5String. Assume definite-length only.
     */
    private void decodeIA5String(ASN1Object o, byte [] stream,
                                 int [] offset, int length)
    {
        if (length == -1)
        {
            // not implemented
        }
        else
        {
            o.setValue(new String(stream, offset[0], length));
            offset[0] += length;
        }
    }
    
    /**
     * Decodes NULL. Definite-length only.
     */
    private void decodeNULL(ASN1Object o, byte [] stream, int [] offset,
                            int length) throws ASN1Exception
    {
        if (length != 0)
        {
            throw new ASN1Exception("Wrong data (NULL) length");
        }
        o.setValue("");
    }
    
    /**
     * Decodes ContextSpecific.
     */
    private void decodeCONTEXT(ASN1Object o, byte [] stream, int [] offset,
                               int length, int tag) throws ASN1Exception
    {
        Context obj = null;
        int start = offset[0];
        tag = tag & 0x3f;
        
        if ((tag & 0x20) == 0)
        { //primitive type
            if (length < 0)
            {
                throw new ASN1Exception("Wrong length(ContextSpecific)");
            }
            byte [] data = new byte[length];
            System.arraycopy(stream, offset[0], data, 0, length);
            obj = new Context(tag, true,
                              ASN1Object.create(ASN1Type.OCTET_STRING, data));
            offset[0] += length;
        }
        else
        {
            try
            {
                ASN1Object v = decode(stream, offset);
                if (length == -1)
                {
                    if (stream[offset[0]] == 0
                            && stream[offset[0]+1] == 0)
                    {
                        offset[0] += 2;
                    }
                    else
                    {
                        //	System.out.println(offset[0]);
                        throw new ASN1Exception(
                            "wrong indefinite-length decoding");
                    }
                }
                else
                {
                    if (offset[0] != start + length)
                    {
                        throw new ASN1Exception(
                            "wrong definite-length decoding");
                    }
                }
                obj = new Context(tag, false, v);
            }
            catch(ASN1Exception e)
            {
                //	e.printStackTrace(System.out);
                offset[0] = start;
                ASN1Object v = ASN1Object.create(ASN1Type.SEQUENCE);
                decodeSEQUENCE(v, stream, offset, length);
                obj = new Context(tag, true, v);
            }
        }
        o.setValue(obj);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -