public final Pdu read() throws IOException {
   Pdu pdu = new Pdu();
   pdu.id = readUInt2();
   int length = readUInt3();
   pdu.version = readUInt2();
   pdu.payload = cipher.encrypt(readBytes(length));
   return pdu;
 }
 /**
  * Adds an pdu. This method adds the Pdu and checks if discovery is needed depending on the
  * parameter <code>checkDiscovery</code>. If discovery is needed this method will block until it
  * have done so. Discovery is only needed if the stack is non authoritative.
  *
  * @param pdu the pdu
  * @param checkDiscovery check if discovery is needed
  * @return pdu is succesful added
  * @see AbstractSnmpContext#addPdu(Pdu)
  * @see #addDiscoveryPdu(DiscoveryPdu)
  * @see #addPdu(Pdu)
  */
 protected boolean addPdu(Pdu pdu, boolean checkDiscovery)
     throws java.io.IOException, PduException {
   boolean added = super.addPdu(pdu);
   if (checkDiscovery == true && isAuthoritative(pdu.getMsgType()) == false) {
     discoverIfNeeded();
   }
   return added;
 }
  /** Processes an incoming SNMP v3 message. */
  protected void ProcessIncomingMessage(AsnDecoder rpdu, ByteArrayInputStream in)
      throws DecodingException, IOException {
    byte[] bu = null;
    // need to duplicate the message for V3 to rewrite
    int nb = in.available();
    bu = new byte[nb];
    in.read(bu);
    in = new ByteArrayInputStream(bu);

    AsnSequence asnTopSeq = rpdu.DecodeSNMPv3(in);
    int msgId = rpdu.getMsgId(asnTopSeq);
    Integer rid = (Integer) msgIdHash.get(new Integer(msgId));
    if (rid != null) {
      if (AsnObject.debug > 6) {
        System.out.println(
            "SnmpContextv3.ProcessIncomingMessage(): msgId=" + msgId + ", Pdu reqId=" + rid);
      }
      Pdu pdu = getPdu(rid);
      try {
        AsnPduSequence pduSeq = rpdu.processSNMPv3(this, asnTopSeq, bu);
        if (pduSeq != null) {
          // got a message
          Integer rid2 = new Integer(pduSeq.getReqId());
          if (AsnObject.debug > 6) {
            System.out.println("SnmpContextv3.ProcessIncomingMessage():" + " rid2=" + rid2);
          }

          Pdu newPdu = null;
          if (rid2.intValue() != rid.intValue()) {
            newPdu = getPdu(rid2);
            if (AsnObject.debug > 3) {
              System.out.println(
                  "ProcessIncomingMessage(): "
                      + "pduReqId of msgId ("
                      + rid.intValue()
                      + ") != pduReqId of Pdu ("
                      + rid2.intValue()
                      + ")");
            }
            if (newPdu == null) {
              if (AsnObject.debug > 3) {
                System.out.println(
                    "ProcessIncomingMessage(): "
                        + "Using pduReqId of msgId ("
                        + rid.intValue()
                        + ")");
              }
            }
          }

          if (newPdu != null) {
            pdu = newPdu;
          }
        } else {
          if (AsnObject.debug > 6) {
            System.out.println("SnmpContextv3.ProcessIncomingMessage():" + " pduSeq is null.");
          }
        }

        if (pdu != null) {
          pdu.fillin(pduSeq);
        } else {
          if (AsnObject.debug > 6) {
            System.out.println("ProcessIncomingMessage(): No Pdu with reqid " + rid.intValue());
          }
        }
      } catch (DecodingException exc) {
        if (pdu != null) {
          pdu.setErrorStatus(AsnObject.SNMP_ERR_DECODING_EXC, exc);
          pdu.fillin(null);
        } else {
          throw exc;
        }
      }
    } else {
      if (AsnObject.debug > 3) {
        System.out.println("Pdu of msgId " + msgId + " is already answered");
      }
      rid = new Integer(-1);
    }
  }