亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? ber.java.svn-base

?? snmp hibernate 源碼, 類似hibernate的映射.
?? SVN-BASE
?? 第 1 頁 / 共 2 頁
字號:
/*_############################################################################
  _##
  _##  SNMP4J - BER.java
  _##
  _##  Copyright 2003-2006  Frank Fock and Jochen Katz (SNMP4J.org)
  _##
  _##  Licensed under the Apache License, Version 2.0 (the "License");
  _##  you may not use this file except in compliance with the License.
  _##  You may obtain a copy of the License at
  _##
  _##      http://www.apache.org/licenses/LICENSE-2.0
  _##
  _##  Unless required by applicable law or agreed to in writing, software
  _##  distributed under the License is distributed on an "AS IS" BASIS,
  _##  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  _##  See the License for the specific language governing permissions and
  _##  limitations under the License.
  _##
  _##########################################################################*/





package org.snmp4j.asn1;

import java.io.OutputStream;
import java.io.IOException;

/**
 * The BER class provides utility methods for the BER encoding and decoding.
 *
 * @author Jochen Katz & Frank Fock
 * @version 1.7.4
 */
public class BER {

  public static final byte ASN_BOOLEAN = 0x01;
  public static final byte ASN_INTEGER = 0x02;
  public static final byte ASN_BIT_STR = 0x03;
  public static final byte ASN_OCTET_STR = 0x04;
  public static final byte ASN_NULL = 0x05;
  public static final byte ASN_OBJECT_ID = 0x06;
  public static final byte ASN_SEQUENCE = 0x10;
  public static final byte ASN_SET = 0x11;
  public static final byte ASN_UNIVERSAL = 0x00;
  public static final byte ASN_APPLICATION = 0x40;
  public static final byte ASN_CONTEXT = (byte)0x80;
  public static final byte ASN_PRIVATE = (byte)0xC0;
  public static final byte ASN_PRIMITIVE = (byte)0x00;
  public static final byte ASN_CONSTRUCTOR = (byte)0x20;

  public static final byte ASN_LONG_LEN = (byte)0x80;
  public static final byte ASN_EXTENSION_ID = (byte)0x1F;
  public static final byte ASN_BIT8 = (byte)0x80;

  public static final byte INTEGER = ASN_UNIVERSAL | 0x02;
  public static final byte INTEGER32 = ASN_UNIVERSAL | 0x02;
  public static final byte BITSTRING = ASN_UNIVERSAL | 0x03;
  public static final byte OCTETSTRING = ASN_UNIVERSAL | 0x04;
  public static final byte NULL = ASN_UNIVERSAL | 0x05;
  public static final byte OID = ASN_UNIVERSAL | 0x06;
  public static final byte SEQUENCE = ASN_CONSTRUCTOR | 0x10;

  public static final byte IPADDRESS = ASN_APPLICATION | 0x00;
  public static final byte COUNTER = ASN_APPLICATION | 0x01;
  public static final byte COUNTER32 = ASN_APPLICATION | 0x01;
  public static final byte GAUGE = ASN_APPLICATION | 0x02;
  public static final byte GAUGE32 = ASN_APPLICATION | 0x02;
  public static final byte TIMETICKS = ASN_APPLICATION | 0x03;
  public static final byte OPAQUE = ASN_APPLICATION | 0x04;
  public static final byte COUNTER64 = ASN_APPLICATION | 0x06;

  public static final int NOSUCHOBJECT = 0x80;
  public static final int NOSUCHINSTANCE = 0x81;
  public static final int ENDOFMIBVIEW = 0x82;

  private static final int LENMASK = 0x0ff;
  public static final int MAX_OID_LENGTH = 127;

  private static boolean checkSequenceLength = true;
  private static boolean checkValueLength = true;

  /**
   * The <code>MutableByte</code> class serves for exchanging type information
   * from the various decode* methods.
   *
   * @author Frank Fock
   * @version 1.0
   */
  public static class MutableByte {
    byte value = 0;

    public MutableByte() { }

    public MutableByte(byte value) {
      setValue(value);
    }

    public void setValue(byte value) {
      this.value = value;
    }

    public byte getValue() {
      return value;
    }
  }

  /**
   * Encodes an ASN.1 header for an object with the ID and
   * length specified.
   * @param os
   *    an <code>OutputStream</code> to which the header is encoded.
   * @param type
   *    the type of the ASN.1 object. Must be < 30, i.e. no extension octets.
   * @param length
   *    the length of the object. The maximum length is 0xFFFFFFFF;
   * @throws IOException
   */
  public static final void encodeHeader(OutputStream os, int type, int length)
      throws IOException
  {
    os.write(type);
    encodeLength(os, length);
  }

  /**
   * Encodes an ASN.1 header for an object with the ID and
   * length specified with a fixed length of the encoded length as supplied.
   * @param os
   *    an <code>OutputStream</code> to which the header is encoded.
   * @param type
   *    the type of the ASN.1 object. Must be < 30, i.e. no extension octets.
   * @param length
   *    the length of the object. The maximum length is 0xFFFFFFFF;
   * @param numBytesLength
   *    the number of bytes used to encode the length of the length.
   * @throws IOException
   */
  public static final void encodeHeader(OutputStream os, int type, int length,
                                        int numBytesLength)
      throws IOException
  {
    os.write(type);
    encodeLength(os, length, numBytesLength);
  }

  /**
   * Compute the space needed to encode the length.
   *
   * @param length
   *    Length to encode
   * @return
   *    the count of bytes needed to encode the value <code>length</code>
   */
  public static final int getBERLengthOfLength(int length) {
    if (length < 0) {
      return 5;
    }
    else if (length < 0x80){
      return 1;
    }
    else if (length <= 0xFF){
      return 2;
    }
    else if (length <= 0xFFFF) { /* 0xFF < length <= 0xFFFF */
      return 3;
    }
    else if (length <= 0xFFFFFF) { /* 0xFFFF < length <= 0xFFFFFF */
      return 4;
    }
    return 5;
  }

  /**
   * Encodes the length of an ASN.1 object.
   * @param os
   *   an <code>OutputStream</code> to which the length is encoded.
   * @param length
   *    the length of the object. The maximum length is 0xFFFFFFFF;
   * @throws IOException
   */
  public static final void encodeLength(OutputStream os, int length)
      throws IOException
  {
    if (length < 0) {
      os.write(0x04 | ASN_LONG_LEN);
      os.write((length >> 24) & 0xFF);
      os.write((length >> 16) & 0xFF);
      os.write((length >> 8) & 0xFF);
      os.write(length & 0xFF);
    }
    else if (length < 0x80){
      os.write(length);
    }
    else if (length <= 0xFF){
      os.write((0x01 | ASN_LONG_LEN));
      os.write(length);
    }
    else if (length <= 0xFFFF) { /* 0xFF < length <= 0xFFFF */
      os.write(0x02 | ASN_LONG_LEN);
      os.write((length >> 8) & 0xFF);
      os.write(length & 0xFF);
    }
    else if (length <= 0xFFFFFF) { /* 0xFFFF < length <= 0xFFFFFF */
      os.write(0x03 | ASN_LONG_LEN);
      os.write((length >> 16) & 0xFF);
      os.write((length >> 8) & 0xFF);
      os.write(length & 0xFF);
    }
    else {
      os.write(0x04 | ASN_LONG_LEN);
      os.write((length >> 24) & 0xFF);
      os.write((length >> 16) & 0xFF);
      os.write((length >> 8) & 0xFF);
      os.write(length & 0xFF);
    }
  }

  /**
   * Encodes the length of an ASN.1 object.
   * @param os
   *   an <code>OutputStream</code> to which the length is encoded.
   * @param length
   *    the length of the object. The maximum length is 0xFFFFFFFF;
   * @param numLengthBytes
   *    the number of bytes to be used to encode the length using the long
   *    form.
   * @throws IOException
   */
  public static final void encodeLength(OutputStream os, int length,
                                        int numLengthBytes)
      throws IOException
  {
    os.write((numLengthBytes | ASN_LONG_LEN));
    for (int i=(numLengthBytes-1)*8; i>=0; i-=8) {
      os.write(((length >> i) & 0xFF));
    }
  }

  /**
   * Encode a signed integer.
   * @param os
   *    an <code>OutputStream</code> to which the length is encoded.
   * @param type
   *    the tag type for the integer (typically 0x02)
   * @param value
   *    the integer value to encode.
   * @throws IOException
   */
  public static final void encodeInteger(OutputStream os, byte type, int value)
      throws IOException
  {
    int integer = value;
    int mask;
    int intsize = 4;

    /*
     * Truncate "unnecessary" bytes off of the most significant end of this
     * 2's complement integer.  There should be no sequence of 9
     * consecutive 1's or 0's at the most significant end of the
     * integer.
     */
    mask = 0x1FF << ((8 * 3) - 1);
    /* mask is 0xFF800000 on a big-endian machine */
    while((((integer & mask) == 0) || ((integer & mask) == mask))
          && intsize > 1){
      intsize--;
      integer <<= 8;
    }
    encodeHeader(os, type, intsize);
    mask = 0xFF << (8 * 3);
    /* mask is 0xFF000000 on a big-endian machine */
    while ((intsize--) > 0){
      os.write(((integer & mask) >> (8 * 3)));
      integer <<= 8;
    }
  }

  /**
   * Encode an unsigned integer.
   * ASN.1 integer ::= 0x02 asnlength byte {byte}*
   * @param os
   *    an <code>OutputStream</code> to which the length is encoded.
   * @param type
   *    the tag type for the integer (typically 0x02)
   * @param value
   *    the integer value to encode.
   * @throws IOException
   */
  public static final void encodeUnsignedInteger(OutputStream os, byte type, long value)
      throws IOException
  {
    // figure out the len
    int len = 1;
    if ((( value >> 24) & LENMASK) != 0) {
      len = 4;
    }
    else if ((( value >> 16) & LENMASK) !=0) {
      len = 3;
    }
    else if ((( value >> 8) & LENMASK) !=0) {
      len = 2;
    }
    // check for 5 byte len where first byte will be
    // a null
    if ((( value >> (8 * (len -1))) & 0x080) !=0)	{
      len++;
    }

    // build up the header
    encodeHeader(os, type, len);  // length of BER encoded item

    // special case, add a null byte for len of 5
    if (len == 5) {
      os.write(0);
      for (int x=1; x<len; x++) {
        os.write((int) (value >> (8 * (4 - x) & LENMASK)));
      }
    }
    else
    {
      for (int x=0; x<len; x++) {
        os.write((int) (value >> (8 * ((len - 1) - x) & LENMASK)));
      }
    }
  }

  /**
   * Encode an ASN.1 octet string filled with the supplied input string.
   * @param os
   *    an <code>OutputStream</code> to which the length is encoded.
   * @param type
   *    the tag type for the integer (typically 0x02)
   * @param string
   *    the <code>byte</code> array containing the octet string value.
   * @throws IOException
   */
  public static final void encodeString(OutputStream os, byte type, byte[] string)
      throws IOException
  {
    /*
    * ASN.1 octet string ::= primstring | cmpdstring
    * primstring ::= 0x04 asnlength byte {byte}*
    * cmpdstring ::= 0x24 asnlength string {string}*
    * This code will never send a compound string.
    */
    encodeHeader(os, type, string.length);
    // fixed
    os.write(string);
  }

  /**
   * Encode an ASN.1 header for a sequence with the ID and length specified.
   * This only works on data types < 30, i.e. no extension octets.
   * The maximum length is 0xFFFF;
   *
   * @param os
   *    an <code>OutputStream</code> to which the length is encoded.
   * @param type
   *    the tag type for the integer (typically 0x02)
   * @param length
   *    the length of the sequence to encode.
   * @throws IOException
   */
  public static final void encodeSequence(OutputStream os, byte type, int length)
      throws IOException
  {
    os.write(type);
    encodeLength(os, length);
  }

  /**
   * Gets the payload length in bytes of the BER encoded OID value.
   * @param value
   *    an array of unsigned integer values representing an object identifier.
   * @return
   *    the BER encoded length of the OID without header and length.
   */
  public static final int getOIDLength(int[] value) {
    int length = 1; // for first 2 subids
    for (int i = 2; i < value.length; i++) {
      long v = value[i] & 0xFFFFFFFFL;
      if (v < 0x80) { //  7 bits long subid
        length += 1;
      }
      else if (v < 0x4000) {  // 14 bits long subid
        length += 2;
      }
      else if (v < 0x200000) { // 21 bits long subid
        length += 3;
      }
      else if (v < 0x10000000) { // 28 bits long subid
        length += 4;
      }
      else {                     // 32 bits long subid
        length += 5;
      }
    }
    return length;
  }

 /**
  * Encode an ASN.1 oid filled with the supplied oid value.
  *
  * @param os
  *    an <code>OutputStream</code> to which the length is encoded.
  * @param type
  *    the tag type for the integer (typically 0x06)
  * @param oid
  *    the <code>int</code> array containing the OID value.
  * @throws IOException
  */
  public static final void encodeOID(OutputStream os, byte type, int[] oid)
      throws IOException
  {
    /*
     * ASN.1 objid ::= 0x06 asnlength subidentifier {subidentifier}*
     * subidentifier ::= {leadingbyte}* lastbyte
     * leadingbyte ::= 1 7bitvalue
     * lastbyte ::= 0 7bitvalue
     */
    encodeHeader(os, type, getOIDLength(oid));

    int encodedLength = oid.length;
    int rpos = 0;

    if (oid.length < 2){
      os.write(0);
      encodedLength = 0;
    }
    else {
      os.write(((oid[1] + (oid[0] * 40)) & 0xFF));
      encodedLength -= 2;
      rpos = 2;
    }

    while (encodedLength-- > 0){
      long subid = (oid[rpos++] & 0xFFFFFFFFL);
      if (subid < 127) {
        os.write((int)subid & 0xFF);
      }
      else {
        long mask = 0x7F; /* handle subid == 0 case */
        long bits = 0;

        /* testmask *MUST* !!!! be of an unsigned type */
        for (long testmask = 0x7F, testbits = 0; testmask != 0;
             testmask <<= 7, testbits += 7) {
          if ((subid & testmask) > 0) {	/* if any bits set */
            mask = testmask;
            bits = testbits;
          }
        }
        /* mask can't be zero here */
        for (; mask != 0x7F; mask >>= 7, bits -= 7){
          /* fix a mask that got truncated above */
          if (mask == 0x1E00000) {
            mask = 0xFE00000;
          }
          os.write((int)(((subid & mask) >> bits) | ASN_BIT8));
        }
        os.write((int)(subid & mask));

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
精品久久人人做人人爰| 日韩一二三区视频| 蜜芽一区二区三区| 国产精品美女久久久久aⅴ| 欧美欧美午夜aⅴ在线观看| 懂色av一区二区三区蜜臀| 亚洲不卡av一区二区三区| 国产精品三级电影| 精品国产91乱码一区二区三区 | 欧美日韩在线亚洲一区蜜芽| 狠狠网亚洲精品| 午夜精品久久久久久久久久| 国产精品区一区二区三区 | 国产精品久久网站| 日韩一区二区麻豆国产| 欧美午夜精品一区| aaa国产一区| 国产精品一区二区免费不卡| 日韩影院免费视频| 亚洲综合自拍偷拍| 综合久久久久久久| 欧美激情一区三区| 2022国产精品视频| 日韩午夜av一区| 欧美日韩国产综合一区二区 | 成人性生交大合| 国产麻豆午夜三级精品| 青青草原综合久久大伊人精品| 亚洲精品高清在线| 综合久久综合久久| 亚洲视频一二区| 中文字幕一区av| 国产精品女同互慰在线看| 久久久精品免费免费| www国产成人免费观看视频 深夜成人网| 欧美精品777| 3atv一区二区三区| 91麻豆精品国产91久久久久久| 欧美日韩在线一区二区| 中文字幕在线观看不卡| wwwwxxxxx欧美| 久久久影院官网| 国产亚洲女人久久久久毛片| 久久久久久久网| 久久精品亚洲乱码伦伦中文| 久久久一区二区三区| 日本一区二区三区四区在线视频| 久久精品水蜜桃av综合天堂| 国产欧美一区二区精品性色超碰| 国产欧美一区二区精品婷婷| 国产精品久久久久久久久免费樱桃 | 色婷婷综合久久久中文一区二区| 色综合夜色一区| 色呦呦一区二区三区| 欧美无乱码久久久免费午夜一区| 欧美日韩精品三区| 欧美xxxxxxxxx| 亚洲国产精品二十页| 一区二区中文字幕在线| 亚洲黄色尤物视频| 日日夜夜精品视频天天综合网| 蜜臀av一区二区在线观看| 国产在线视频一区二区三区| 成人网男人的天堂| 国产精一品亚洲二区在线视频| 国产剧情一区二区三区| 成人黄色a**站在线观看| 成人免费看黄yyy456| 成人黄色电影在线| 欧美三级三级三级爽爽爽| 欧美电影免费观看高清完整版在线观看| 欧美精品一区二区三区蜜桃视频| 日本一区二区不卡视频| 亚洲国产精品久久久久婷婷884| 日本最新不卡在线| 粗大黑人巨茎大战欧美成人| 欧美性xxxxxxxx| 欧美精品一区二区精品网| 综合分类小说区另类春色亚洲小说欧美 | 亚洲成在人线免费| 久久成人精品无人区| 99久久国产综合精品女不卡| 欧美日韩一二三区| 国产亚洲一区字幕| 午夜精品在线视频一区| 国产精品亚洲一区二区三区妖精 | 制服丝袜亚洲网站| 日本一区二区免费在线| 午夜精品久久久久久久蜜桃app| 国产精品影视在线观看| 欧美性猛交xxxx乱大交退制版 | 欧美亚洲综合网| 精品国产一区二区三区四区四| 亚洲图片你懂的| 另类小说欧美激情| 91成人免费在线视频| 精品国产免费视频| 亚洲一区二区视频| 成人综合婷婷国产精品久久蜜臀| 欧美又粗又大又爽| 国产三级欧美三级日产三级99| 亚洲图片欧美视频| 成人97人人超碰人人99| 2021国产精品久久精品| 丝袜诱惑亚洲看片| 不卡的电影网站| 精品处破学生在线二十三| 亚洲国产精品人人做人人爽| 成人久久久精品乱码一区二区三区| 欧美精品粉嫩高潮一区二区| 亚洲免费观看视频| 成人午夜视频免费看| 精品国内二区三区| 亚洲123区在线观看| 91免费版在线| 中文一区一区三区高中清不卡| 免费观看一级欧美片| 欧美日本一区二区在线观看| 亚洲欧美日韩系列| 福利电影一区二区三区| 精品捆绑美女sm三区| 日韩黄色在线观看| 欧美亚洲国产一卡| 亚洲精品成a人| 97se亚洲国产综合自在线| 国产欧美精品一区二区色综合朱莉| 黄页网站大全一区二区| 欧美第一区第二区| 精品在线免费观看| 欧美不卡一区二区三区四区| 日韩 欧美一区二区三区| 欧美电影在线免费观看| 婷婷丁香激情综合| 3d动漫精品啪啪一区二区竹菊| 亚洲第一综合色| 欧美巨大另类极品videosbest| 亚洲小少妇裸体bbw| 91国产丝袜在线播放| 亚洲综合图片区| 欧美日韩二区三区| 日韩成人免费看| 日韩欧美久久久| 久草热8精品视频在线观看| 精品国产乱子伦一区| 国产一区二区免费看| 国产婷婷一区二区| 成人理论电影网| 中文字幕日韩精品一区| 一本久道久久综合中文字幕| 亚洲精品伦理在线| 精品视频一区二区三区免费| 日本在线播放一区二区三区| 日韩一区二区免费高清| 国产福利一区二区| 亚洲欧洲在线观看av| 色婷婷亚洲婷婷| 午夜久久久久久电影| 欧美成人午夜电影| 成人妖精视频yjsp地址| 亚洲精品你懂的| 欧美一区二区三区思思人| 国内精品嫩模私拍在线| 中文字幕亚洲综合久久菠萝蜜| 在线国产电影不卡| 欧美日韩高清在线播放| 久久精品国产秦先生| 中文字幕高清不卡| 欧美在线免费播放| 精品一区二区三区av| 国产精品理论在线观看| 欧美日韩一区不卡| 国产另类ts人妖一区二区| 亚洲人xxxx| 日韩你懂的电影在线观看| 懂色av一区二区三区免费观看| 亚洲午夜精品在线| 2020国产精品| 欧美在线观看一区| 国产老妇另类xxxxx| 亚洲一区二区三区自拍| 久久久99精品免费观看不卡| 日本黄色一区二区| 精品在线播放免费| 一区二区三区视频在线观看| 欧美www视频| 91福利国产成人精品照片| 激情图区综合网| 夜夜操天天操亚洲| 国产视频一区二区三区在线观看 | 欧美中文字幕不卡| 国产精品一区二区三区99| 亚洲第一精品在线| 中文字幕欧美日本乱码一线二线 | 中文字幕一区二区三区四区不卡| 91精品国产综合久久久蜜臀粉嫩 | 91成人在线观看喷潮| 国产91丝袜在线18| 男男视频亚洲欧美| 一区二区三区视频在线看| 国产女同互慰高潮91漫画|