MessageToken_v2(int tokenId,Krb5Context context,InputStream is,MessageProp prop) throws GSSException {
  init(tokenId,context);
  try {
    if (!confState) {
      prop.setPrivacy(false);
    }
    tokenHeader=new MessageTokenHeader(is,prop,tokenId);
    if (tokenId == Krb5Token.WRAP_ID_v2) {
      key_usage=(!initiator ? KG_USAGE_INITIATOR_SEAL : KG_USAGE_ACCEPTOR_SEAL);
    }
 else     if (tokenId == Krb5Token.MIC_ID_v2) {
      key_usage=(!initiator ? KG_USAGE_INITIATOR_SIGN : KG_USAGE_ACCEPTOR_SIGN);
    }
    int minSize=0;
    if (tokenId == Krb5Token.WRAP_ID_v2 && prop.getPrivacy()) {
      minSize=CONFOUNDER_SIZE + TOKEN_HEADER_SIZE + cipherHelper.getChecksumLength();
    }
 else {
      minSize=cipherHelper.getChecksumLength();
    }
    if (tokenId == Krb5Token.MIC_ID_v2) {
      tokenDataLen=minSize;
      tokenData=new byte[minSize];
      readFully(is,tokenData);
    }
 else {
      tokenDataLen=is.available();
      if (tokenDataLen >= minSize) {
        tokenData=new byte[tokenDataLen];
        readFully(is,tokenData);
      }
 else {
        byte[] tmp=new byte[minSize];
        readFully(is,tmp);
        int more=is.available();
        tokenDataLen=minSize + more;
        tokenData=Arrays.copyOf(tmp,tokenDataLen);
        readFully(is,tokenData,minSize,more);
      }
    }
    if (tokenId == Krb5Token.WRAP_ID_v2) {
      rotate();
    }
    if (tokenId == Krb5Token.MIC_ID_v2 || (tokenId == Krb5Token.WRAP_ID_v2 && !prop.getPrivacy())) {
      int chkLen=cipherHelper.getChecksumLength();
      checksum=new byte[chkLen];
      System.arraycopy(tokenData,tokenDataLen - chkLen,checksum,0,chkLen);
      if (tokenId == Krb5Token.WRAP_ID_v2 && !prop.getPrivacy()) {
        if (chkLen != ec) {
          throw new GSSException(GSSException.DEFECTIVE_TOKEN,-1,getTokenName(tokenId) + ":" + "EC incorrect!");
        }
      }
    }
  }
 catch (  IOException e) {
    throw new GSSException(GSSException.DEFECTIVE_TOKEN,-1,getTokenName(tokenId) + ":" + e.getMessage());
  }
}

MessageToken_v2 ( int tokenId , Krb5Context context , InputStream is , MessageProp prop ) throws GSSException { init ( tokenId , context ) ; try { if ( ! confState ) { prop . setPrivacy ( false ) ; } tokenHeader = new MessageTokenHeader ( is , prop , tokenId ) ; if ( tokenId == Krb5Token . WRAP_ID_v2 ) { key_usage = ( ! initiator ? KG_USAGE_INITIATOR_SEAL : KG_USAGE_ACCEPTOR_SEAL ) ; } else if ( tokenId == Krb5Token . MIC_ID_v2 ) { key_usage = ( ! initiator ? KG_USAGE_INITIATOR_SIGN : KG_USAGE_ACCEPTOR_SIGN ) ; } int minSize = 0 ; if ( tokenId == Krb5Token . WRAP_ID_v2 && prop . getPrivacy ( ) ) { minSize = CONFOUNDER_SIZE + TOKEN_HEADER_SIZE + cipherHelper . getChecksumLength ( ) ; } else { minSize = cipherHelper . getChecksumLength ( ) ; } if ( tokenId == Krb5Token . MIC_ID_v2 ) { tokenDataLen = minSize ; tokenData = new byte [ minSize ] ; readFully ( is , tokenData ) ; } else { tokenDataLen = is . available ( ) ; if ( tokenDataLen >= minSize ) { tokenData = new byte [ tokenDataLen ] ; readFully ( is , tokenData ) ; } else { byte [ ] tmp = new byte [ minSize ] ; readFully ( is , tmp ) ; int more = is . available ( ) ; tokenDataLen = minSize + more ; tokenData = Arrays . copyOf ( tmp , tokenDataLen ) ; readFully ( is , tokenData , minSize , more ) ; } } if ( tokenId == Krb5Token . WRAP_ID_v2 ) { rotate ( ) ; } if ( tokenId == Krb5Token . MIC_ID_v2 || ( tokenId == Krb5Token . WRAP_ID_v2 && ! prop . getPrivacy ( ) ) ) { int chkLen = cipherHelper . getChecksumLength ( ) ; checksum = new byte [ chkLen ] ; System . arraycopy ( tokenData , tokenDataLen - chkLen , checksum , 0 , chkLen ) ; if ( tokenId == Krb5Token . WRAP_ID_v2 && ! prop . getPrivacy ( ) ) { if ( chkLen != ec ) { throw new GSSException ( GSSException . DEFECTIVE_TOKEN , - 1 , getTokenName ( tokenId ) + ":" + "EC incorrect!" ) ; } } } } catch ( IOException e ) { throw new GSSException ( GSSException . DEFECTIVE_TOKEN , - 1 , getTokenName ( tokenId ) + ":" + e . getMessage ( ) ) ; } }
constructs a messagetoken from an inputstream . bytes will be read on demand and the thread might block if there are not enough bytes to complete the token . please note there is no accurate way to find out the size of a token , but we try our best to make sure there is enough bytes to construct one .
