derobjectidentifier.java

来自「《移动Agent技术》一书的所有章节源代码。」· Java 代码 · 共 78 行

JAVA
78
字号
package org.bouncycastle.asn1;import java.io.*;public class DERObjectIdentifier    extends DERObject{    String      identifier;    public DERObjectIdentifier(        String  identifier)    {        this.identifier = identifier;    }    public String getId()    {        return identifier;    }    void encode(        DEROutputStream out)        throws IOException    {        OIDTokenizer            tok = new OIDTokenizer(identifier);        ByteArrayOutputStream   bOut = new ByteArrayOutputStream();        DEROutputStream         dOut = new DEROutputStream(bOut);                                    // space for 5 7 bit numbers in an int        byte[]                  iBuf = new byte[5];                    dOut.write(                    Integer.parseInt(tok.nextToken()) * 40                    + Integer.parseInt(tok.nextToken()));        while (tok.hasMoreTokens())        {            //            // translate into base 128            //            int value = Integer.parseInt(tok.nextToken());            int count = iBuf.length - 1;                        iBuf[count--] = (byte)(value % 128);            value /= 128;            while (value != 0)            {                iBuf[count--] = (byte)((value % 128) | 0x80);                value /= 128;            }            dOut.write(iBuf, count + 1, iBuf.length - (count + 1));        }        dOut.close();        byte[]  bytes = bOut.toByteArray();        out.writeEncoded(OBJECT_IDENTIFIER, bytes);    }    public int hashCode()    {        return identifier.hashCode();    }    public boolean equals(        Object  o)    {        if ((o == null) || !(o instanceof DERObjectIdentifier))        {            return false;        }        return identifier.equals(((DERObjectIdentifier)o).identifier);    }}

⌨️ 快捷键说明

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