OpenSSL.Core.BIO.ReadBytes C# (CSharp) Méthode

ReadBytes() public méthode

Calls BIO_read()
public ReadBytes ( int count ) : ArraySegment
count int
Résultat ArraySegment
		public ArraySegment<byte> ReadBytes(int count)
		{
			byte[] buf = new byte[count];
			int ret = Native.BIO_read(this.ptr, buf, buf.Length);
			if (ret < 0)
				throw new Exception("Expected " + count + " bytes but received " + ret);

			return new ArraySegment<byte>(buf, 0, ret);
		}

Usage Example

 public void Bug3524222()
 {
     byte[] pattern = { 1, 2, 3 };
     byte[] buf = (byte[])pattern.Clone();
     using(BIO bio = new BIO(buf)) {
         buf[1] = 1;
         Assert.AreEqual(pattern, bio.ReadBytes(3).Array);
     }
 }