Buf
Inheritance: FanObj
Exemple #1
0
 public Buf readBufFully(Buf buf, long n)
 {
     return m_in.readBufFully(buf, n);
 }
Exemple #2
0
 public virtual Buf hmac(String algorithm, Buf key)
 {
     throw UnsupportedErr.make(@typeof()+".hmac").val;
 }
Exemple #3
0
 public Long readBuf(Buf other, long n)
 {
     return m_in.readBuf(other, n);
 }
Exemple #4
0
 public virtual OutStream writeBuf(Buf buf)
 {
     return writeBuf(buf, buf.remaining());
 }
Exemple #5
0
 public virtual OutStream writeBuf(Buf buf, long n)
 {
     try
       {
     m_out.writeBuf(buf, n);
     return this;
       }
       catch (System.NullReferenceException e)
       {
     if (m_out == null)
       throw UnsupportedErr.make(@typeof().qname() + " wraps null OutStream").val;
     else
       throw e;
       }
 }
Exemple #6
0
 public override Long readBuf(Buf buf, long n)
 {
     try
       {
     long read = buf.pipeFrom(inStream, n);
     if (read <= 0) return null;
     return Long.valueOf(read);
       }
       catch (IOException e)
       {
     throw IOErr.make(e).val;
       }
 }
Exemple #7
0
        public virtual Buf readBufFully(Buf buf, long n)
        {
            if (buf == null) buf = Buf.make(n);

              long total = n;
              long got = 0;
              while (got < total)
              {
            Long r = readBuf(buf, total-got);
            if (r == null || r.longValue() == 0) throw IOErr.make("Unexpected end of stream").val;
            got += r.longValue();
              }

              buf.flip();
              return buf;
        }
Exemple #8
0
 public override OutStream writeBuf(Buf other, long n)
 {
     int len = (int)n;
     p.grow(p.m_pos+len);
     other.pipeTo(p.m_buf, p.m_pos, len);
     p.m_pos += len;
     if (p.m_pos > p.m_size) p.m_size = p.m_pos;
     return this;
 }
Exemple #9
0
 public override OutStream writeBuf(Buf buf)
 {
     return writeBuf(buf, buf.remaining());
 }
Exemple #10
0
        public override Buf hmac(string algorithm, Buf keyBuf)
        {
            // get digest algorthim
              string alg = algorithm;
              if (alg == "SHA-1") alg = "SHA1";  // to make .NET happy
              HashAlgorithm ha = HashAlgorithm.Create(alg);
              if (ha == null)
            throw ArgErr.make("Unknown digest algorthm: " + algorithm).val;

              // get secret key bytes
              int blockSize = 64;
              byte[] keyBytes = null;
              int keySize = 0;
              try
              {
            // get key bytes
            MemBuf keyMemBuf = (MemBuf)keyBuf;
            keyBytes = keyMemBuf.m_buf;
            keySize  = keyMemBuf.m_size;

            // key is greater than block size we hash it first
            if (keySize > blockSize)
            {
              keyBytes = ha.ComputeHash(keyBytes, 0, keySize);
              keySize = keyBytes.Length;
            }
              }
              catch (System.InvalidCastException)
              {
            throw UnsupportedErr.make("key parameter must be memory buffer").val;
              }

              // RFC 2104:
              //   ipad = the byte 0x36 repeated B times
              //   opad = the byte 0x5C repeated B times
              //   H(K XOR opad, H(K XOR ipad, text))

              MemBuf acc = new MemBuf(1024);

              // inner digest: H(K XOR ipad, text)
              for (int i=0; i<blockSize; ++i)
              {
            if (i < keySize)
              acc.write((byte)(keyBytes[i] ^ 0x36));
            else
              acc.write((byte)0x36);
              }
              acc.pipeFrom(m_buf, 0, m_size);
              byte[] innerDigest = ha.ComputeHash(acc.m_buf, 0, acc.m_size);

              // outer digest: H(K XOR opad, innerDigest)
              acc.clear();
              for (int i=0; i<blockSize; ++i)
              {
            if (i < keySize)
              acc.write((byte)(keyBytes[i] ^ 0x5C));
            else
              acc.write((byte)0x5C);
              }
              acc.pipeFrom(innerDigest, 0, innerDigest.Length);

              // return result
              return new MemBuf(ha.ComputeHash(acc.m_buf, 0, acc.m_size));
        }
Exemple #11
0
 public override Long readBuf(Buf other, long n)
 {
     if (p.m_pos >= p.m_size) return null;
     int len = Math.Min(p.m_size-p.m_pos, (int)n);
     other.pipeFrom(p.m_buf, p.m_pos, len);
     p.m_pos += len;
     return Long.valueOf(len);
 }
Exemple #12
0
 public override OutStream writeBuf(Buf buf, long n)
 {
     throw UnsupportedErr.make("binary write on StrBuf output").val;
 }
Exemple #13
0
 public override OutStream writeBuf(Buf other, long n)
 {
     try
     {
       other.pipeTo(p.m_stream, n);
       return this;
     }
     catch (IOException e) { throw IOErr.make(e).val; }
     catch (System.NotSupportedException e) { throw IOErr.make(e.Message, e).val; }
 }
Exemple #14
0
 public override Long readBuf(Buf other, long n)
 {
     try
     {
       long read = other.pipeFrom(p.m_stream, n);
       if (read < 0) return null;
       return Long.valueOf(read);
     }
     catch (IOException e)
     {
       throw IOErr.make(e).val;
     }
 }
Exemple #15
0
 public Buf writeBuf(Buf other)
 {
     m_out.writeBuf(other); return this;
 }
Exemple #16
0
 public override OutStream writeBuf(Buf buf, long n)
 {
     try
       {
     buf.pipeTo(outStream, n);
     return this;
       }
       catch (IOException e)
       {
     throw IOErr.make(e).val;
       }
 }
Exemple #17
0
 public Buf writeBuf(Buf other, long n)
 {
     m_out.writeBuf(other, n); return this;
 }
Exemple #18
0
 public static IpAddr makeBytes(Buf bytes)
 {
     try
       {
     MemBuf mb = bytes as MemBuf;
     IPAddress dotnet = new IPAddress(mb.bytes());
     return make(dotnet.ToString(), dotnet);
       }
       catch (SocketException e)
       {
     throw ArgErr.make(e.Message).val;
       }
 }
Exemple #19
0
 public override OutStream writeBuf(Buf buf, long n)
 {
     throw UnsupportedErr.make("binary write on StrBuf output").val;
 }
Exemple #20
0
 public virtual Long readBuf(Buf buf, long n)
 {
     try
       {
     return m_in.readBuf(buf, n);
       }
       catch (System.NullReferenceException e)
       {
     if (m_in == null)
       throw UnsupportedErr.make(@typeof().qname() + " wraps null InStream").val;
     else
       throw e;
       }
 }