예제 #1
0
 /// <summary>Wraps a byte array.</summary>
 /// <param name="bytes">The array containing the bytes to wrap.</param>
 /// <param name="off">The starting position at the array</param>
 /// <param name="len">The number of bytes to wrap</param>
 /// <returns>byte[] wrapped bytes</returns>
 /// <exception cref="Javax.Security.Sasl.SaslException">if the bytes cannot be successfully wrapped
 ///     </exception>
 public virtual byte[] Wrap(byte[] bytes, int off, int len)
 {
     if (saslClient != null)
     {
         return(saslClient.Wrap(bytes, off, len));
     }
     else
     {
         return(saslServer.Wrap(bytes, off, len));
     }
 }
예제 #2
0
 /// <summary>
 /// Writes <code>len</code> bytes from the specified byte array starting at
 /// offset <code>off</code> to this output stream.
 /// </summary>
 /// <param name="inBuf">the data.</param>
 /// <param name="off">the start offset in the data.</param>
 /// <param name="len">the number of bytes to write.</param>
 /// <exception>
 /// IOException
 /// if an I/O error occurs.
 /// </exception>
 /// <exception cref="System.IO.IOException"/>
 public override void Write(byte[] inBuf, int off, int len)
 {
     if (!useWrap)
     {
         outStream.Write(inBuf, off, len);
         return;
     }
     try
     {
         if (saslServer != null)
         {
             // using saslServer
             saslToken = saslServer.Wrap(inBuf, off, len);
         }
         else
         {
             // using saslClient
             saslToken = saslClient.Wrap(inBuf, off, len);
         }
     }
     catch (SaslException se)
     {
         try
         {
             DisposeSasl();
         }
         catch (SaslException)
         {
         }
         throw;
     }
     if (saslToken != null)
     {
         ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
         DataOutputStream      dout    = new DataOutputStream(byteOut);
         dout.WriteInt(saslToken.Length);
         outStream.Write(byteOut.ToByteArray());
         outStream.Write(saslToken, 0, saslToken.Length);
         saslToken = null;
     }
 }