if (context.ClientSettings.Certificates == null ||
context.ClientSettings.Certificates.Count == 0)
{
- throw this.Context.CreateException("Client certificate requested by the server and no client certificate specified.");
+ throw new TlsException(
+ AlertDescription.UserCancelled,
+ "Client certificate requested by the server and no client certificate specified.");
}
// Select a valid certificate
if (clientCert == null)
{
- throw this.Context.CreateException("Client certificate requested by the server and no client certificate specified.");
+ throw new TlsException(
+ AlertDescription.UserCancelled,
+ "Client certificate requested by the server and no client certificate specified.");
}
// Update the selected client certificate
protected override void ProcessAsSsl3()
{
- throw new NotSupportedException();
+ AsymmetricAlgorithm privKey = null;
+ ClientContext context = (ClientContext)this.Context;
+
+ privKey = context.SslStream.RaisePrivateKeySelection(
+ context.ClientSettings.ClientCertificate,
+ context.ClientSettings.TargetHost);
+
+ if (privKey == null)
+ {
+ throw new TlsException(
+ AlertDescription.UserCancelled,
+ "Client certificate Private Key unavailable.");
+ }
+ else
+ {
+ SslHandshakeHash hash = new SslHandshakeHash(context.MasterSecret);
+ hash.TransformFinalBlock(
+ context.HandshakeMessages.ToArray(),
+ 0,
+ (int)context.HandshakeMessages.Length);
+
+ // RSAManaged of the selected ClientCertificate
+ // (at this moment the first one)
+ RSA rsa = this.getClientCertRSA((RSA)privKey);
+
+ // Write message
+ this.Write(hash.CreateSignature(rsa));
+ }
}
protected override void ProcessAsTls1()
ClientContext context = (ClientContext)this.Context;
privKey = context.SslStream.RaisePrivateKeySelection(
- this.Context.ClientSettings.ClientCertificate,
- this.Context.ClientSettings.TargetHost);
+ context.ClientSettings.ClientCertificate,
+ context.ClientSettings.TargetHost);
if (privKey == null)
{
- throw this.Context.CreateException("Client certificate Private Key unavailable.");
+ throw new TlsException(
+ AlertDescription.UserCancelled,
+ "Client certificate Private Key unavailable.");
}
else
{
private void validateCertificates(X509CertificateCollection certificates)
{
- ClientContext context = (ClientContext)this.Context;
+ ClientContext context = (ClientContext)this.Context;
+ AlertDescription description = AlertDescription.BadCertificate;
// the leaf is the web server certificate
X509Certificate leaf = certificates [0];
// WinError.h TRUST_E_BASIC_CONSTRAINTS 0x80096019
errors.Add ((int)-2146869223);
break;
+
case X509ChainStatusFlags.NotSignatureValid:
// WinError.h TRUST_E_BAD_DIGEST 0x80096010
errors.Add ((int)-2146869232);
break;
+
case X509ChainStatusFlags.NotTimeNested:
// WinError.h CERT_E_VALIDITYPERIODNESTING 0x800B0102
errors.Add ((int)-2146762494);
break;
+
case X509ChainStatusFlags.NotTimeValid:
// WinError.h CERT_E_EXPIRED 0x800B0101
+ description = AlertDescription.CertificateExpired;
errors.Add ((int)-2146762495);
break;
+
case X509ChainStatusFlags.PartialChain:
// WinError.h CERT_E_CHAINING 0x800B010A
+ description = AlertDescription.UnknownCA;
errors.Add ((int)-2146762486);
break;
+
case X509ChainStatusFlags.UntrustedRoot:
// WinError.h CERT_E_UNTRUSTEDROOT 0x800B0109
+ description = AlertDescription.UnknownCA;
errors.Add ((int)-2146762487);
break;
+
default:
// unknown error
+ description = AlertDescription.CertificateUnknown;
errors.Add ((int)verify.Status);
break;
}
cert,
certificateErrors))
{
- throw context.CreateException("Invalid certificate received form server.");
+ throw new TlsException(
+ description,
+ "Invalid certificate received form server.");
}
}
ClientContext context = (ClientContext)this.Context;
string domainName = String.Empty;
- Regex search = new Regex(@"([\w\s\d]*)\s*=\s*([^,]*)");
+ Regex search = new Regex(@"CN\s*=\s*([^,]*)");
MatchCollection elements = search.Matches(subjectName);
- foreach (Match element in elements)
+ if (elements.Count == 1)
{
- switch (element.Groups[1].Value.Trim().ToUpper())
+ if (elements[0].Success)
{
- case "CN":
- domainName = element.Groups[2].Value;
- break;
+ domainName = elements[0].Groups[1].Value.ToString();
}
}
}
else
{
- throw this.Context.CreateException("Incorrect protocol version received from server");
+ throw new TlsException(
+ AlertDescription.ProtocolVersion,
+ "Incorrect protocol version received from server");
}
}
if (!isValidSignature)
{
- throw this.Context.CreateException("Data was not signed with the server certificate.");
+ throw new TlsException(
+ AlertDescription.DecodeError,
+ "Data was not signed with the server certificate.");
}
}
int length = this.ReadInt24();
this.clientCertificate = new X509Certificate(this.ReadBytes(length));
-#warning "Is client certificate validation needed ??"
+ this.validateCertificate(this.clientCertificate);
+ }
+
+ #endregion
+
+ #region Private Methods
+
+ private void validateCertificate(X509Certificate certificate)
+ {
+ #warning "Validate client certificate"
}
#endregion
#endregion
- #region Methods
-
- public override void Update()
- {
- throw new NotSupportedException();
- }
-
- #endregion
-
#region Protected Methods
protected override void ProcessAsSsl3()
{
- throw new NotSupportedException();
+ ServerContext context = (ServerContext)this.Context;
+ byte[] signature = this.ReadBytes((int)this.Length);
+
+ // Verify signature
+ SslHandshakeHash hash = new SslHandshakeHash(context.MasterSecret);
+ hash.TransformFinalBlock(
+ context.HandshakeMessages.ToArray(),
+ 0,
+ (int)context.HandshakeMessages.Length);
+
+ if (!hash.VerifySignature(
+ context.ClientSettings.CertificateRSA,
+ signature))
+ {
+ throw new TlsException(
+ AlertDescription.HandshakeFailiure,
+ "Handshake Failiure.");
+ }
}
protected override void ProcessAsTls1()
{
- throw new NotSupportedException();
+ ServerContext context = (ServerContext)this.Context;
+ byte[] signature = this.ReadBytes((int)this.Length);
+
+ // Verify signature
+ MD5SHA1 hash = new MD5SHA1();
+ hash.ComputeHash(
+ context.HandshakeMessages.ToArray(),
+ 0,
+ (int)context.HandshakeMessages.Length);
+
+ if (!hash.VerifySignature(
+ context.ClientSettings.CertificateRSA,
+ signature))
+ {
+ throw new TlsException(
+ AlertDescription.HandshakeFailiure,
+ "Handshake Failiure.");
+ }
}
#endregion
if (decryptError)
{
- this.Context.RecordProtocol.SendAlert(AlertDescription.DecryptError);
-
- throw new TlsException("Decrypt error.");
+ throw new TlsException(
+ AlertDescription.DecryptError,
+ "Decrypt error.");
}
}
if (decryptError)
{
- this.Context.RecordProtocol.SendAlert(AlertDescription.DecryptError);
-
- throw new TlsException("Decrypt error.");
+ throw new TlsException(
+ AlertDescription.DecryptError,
+ "Decrypt error.");
}
}
}
else
{
- this.Context.RecordProtocol.SendAlert(AlertDescription.ProtocolVersion);
-
- throw this.Context.CreateException("Incorrect protocol version received from server");
+ throw new TlsException(
+ AlertDescription.ProtocolVersion,
+ "Incorrect protocol version received from server");
}
}
if (this.Context.Cipher == null)
{
- this.Context.RecordProtocol.SendAlert(AlertDescription.InsuficientSecurity);
-
- throw this.Context.CreateException("Insuficient Security");
+ throw new TlsException(
+ AlertDescription.InsuficientSecurity,
+ "Insuficient Security");
}
}
#endregion
- #region Methods
-
- public override void Update()
- {
- throw new NotSupportedException();
- }
-
- #endregion
-
#region Protected Methods
protected override void ProcessAsSsl3()
#endregion
- internal class Alert : TlsStream
+ internal class Alert
{
#region Fields
- private Context context;
private AlertLevel level;
private AlertDescription description;
#endregion
- #region Constructors
+ #region Properties
- public Alert(
- Context context,
- AlertDescription description) : base()
+ public AlertLevel Level
{
- this.context = context;
- this.description = description;
-
- this.inferAlertLevel();
-
- this.fill();
+ get { return this.level; }
}
- public Alert(
- Context context,
- AlertLevel level,
- AlertDescription description) : base()
+ public AlertDescription Description
{
- this.context = context;
- this.level = level;
- this.description = description;
-
- this.fill();
+ get { return this.description; }
}
- #endregion
-
- #region Properties
-
public string Message
{
get { return Alert.GetAlertMessage(this.description); }
public bool IsWarning
{
- get
- {
- return this.level == AlertLevel.Warning ? true : false;
- }
+ get { return this.level == AlertLevel.Warning ? true : false; }
}
public bool IsFatal
{
- get
- {
- return this.level == AlertLevel.Fatal ? true : false;
- }
+ get { return this.level == AlertLevel.Fatal ? true : false; }
}
public bool IsCloseNotify
#endregion
- #region Methods
-
- public void Update()
+ #region Constructors
+
+ public Alert(AlertDescription description)
{
- if ( this.description == AlertDescription.CloseNotify )
- {
- this.context.ConnectionEnd = true;
- }
+ this.inferAlertLevel();
+ this.description = description;
+ }
- if (this.IsFatal)
- {
- this.context.ConnectionEnd = true;
- if (this.context is ServerContext)
- {
- ((ServerContext)this.context).SslStream.Close();
- }
- }
+ public Alert(
+ AlertLevel level,
+ AlertDescription description)
+ {
+ this.level = level;
+ this.description = description;
}
#endregion
#region Private Methods
- private void fill()
- {
- this.Write((byte)level);
- this.Write((byte)description);
- }
-
private void inferAlertLevel()
{
switch (description)
public bool Contains(string name)
{
- return(-1 != IndexOf(name));
+ return (-1 != this.IndexOf(name));
}
public int IndexOf(string name)
{
int index = 0;
+
foreach (CipherSuite suite in this)
{
- if (cultureAwareCompare(suite.Name, name))
+ if (this.cultureAwareCompare(suite.Name, name))
{
return index;
}
index++;
}
+
return -1;
}
public int IndexOf(short code)
{
int index = 0;
+
foreach (CipherSuite suite in this)
{
if (suite.Code == code)
}
index++;
}
+
return -1;
}
public void RemoveAt(string errorMessage)
{
- RemoveAt(IndexOf(errorMessage));
+ this.RemoveAt(this.IndexOf(errorMessage));
}
public CipherSuite Add(
public override void Clear()
{
- this.clientHelloProtocol = 0;
-
+ this.clientHelloProtocol = 0;
base.Clear();
}
return new TlsServerFinished(this.context, buffer);
default:
- throw this.context.CreateException("Unknown server handshake message received ({0})", type.ToString());
+ throw new TlsException(
+ AlertDescription.UnexpectedMessage,
+ String.Format("Unknown server handshake message received ({0})", type.ToString()));
}
}
}
#endregion
-
- #region Exception Methods
-
- public TlsException CreateException(
- AlertLevel alertLevel,
- AlertDescription alertDesc)
- {
- return CreateException(Alert.GetAlertMessage(alertDesc));
- }
-
- public TlsException CreateException(string format, params object[] args)
- {
- StringBuilder message = new StringBuilder();
- message.AppendFormat(format, args);
-
- return CreateException(message.ToString());
- }
-
- public TlsException CreateException(string message)
- {
- return new TlsException(message);
- }
-
- #endregion
}
}
byte[] rgbHash,
byte[] rgbSignature)
{
- if (key == null)
+ if (this.key == null)
{
throw new CryptographicUnexpectedOperationException("The key is a null reference");
}
public override byte[] CreateSignature(byte[] rgbHash)
{
- if (key == null)
+ if (this.key == null)
{
throw new CryptographicUnexpectedOperationException("The key is a null reference");
}
{
if (this.context.ConnectionEnd)
{
- throw this.context.CreateException("The session is finished and it's no longer valid.");
+ throw new TlsException(
+ AlertDescription.InternalError,
+ "The session is finished and it's no longer valid.");
}
// Try to read the Record Content Type
if (protocol != this.context.Protocol &&
this.context.ProtocolNegotiated)
{
- throw this.context.CreateException("Invalid protocol version on message received from server");
+ throw new TlsException(
+ AlertDescription.ProtocolVersion,
+ "Invalid protocol version on message received from server");
}
// Decrypt message contents if needed
break;
default:
- throw this.context.CreateException("Unknown record received from server.");
+ throw new TlsException(
+ AlertDescription.UnexpectedMessage,
+ "Unknown record received from server.");
}
return result;
switch (alertLevel)
{
case AlertLevel.Fatal:
- throw this.context.CreateException(alertLevel, alertDesc);
+ throw new TlsException(alertLevel, alertDesc);
case AlertLevel.Warning:
default:
public void SendAlert(AlertDescription description)
{
- this.SendAlert(new Alert(this.Context, description));
+ this.SendAlert(new Alert(description));
}
public void SendAlert(
AlertLevel level,
AlertDescription description)
{
- this.SendAlert(new Alert(this.Context, level, description));
+ this.SendAlert(new Alert(level, description));
}
public void SendAlert(Alert alert)
{
// Write record
- this.SendRecord(ContentType.Alert, alert.ToArray());
+ this.SendRecord(
+ ContentType.Alert,
+ new byte[]{(byte)alert.Level, (byte)alert.Description});
- // Update session
- alert.Update();
-
- // Reset message contents
- alert.Reset();
+ if (alert.IsCloseNotify)
+ {
+ this.context.ConnectionEnd = true;
+ }
}
#endregion
{
if (this.context.ConnectionEnd)
{
- throw this.context.CreateException("The session is finished and it's no longer valid.");
+ throw new TlsException(
+ AlertDescription.InternalError,
+ "The session is finished and it's no longer valid.");
}
byte[] record = this.EncodeRecord(contentType, recordData);
{
if (this.context.ConnectionEnd)
{
- throw this.context.CreateException("The session is finished and it's no longer valid.");
+ throw new TlsException(
+ AlertDescription.InternalError,
+ "The session is finished and it's no longer valid.");
}
TlsStream record = new TlsStream();
return new TlsClientFinished(this.context, buffer);
default:
- throw this.context.CreateException("Unknown server handshake message received ({0})", type.ToString());
+ throw new TlsException(
+ AlertDescription.UnexpectedMessage,
+ String.Format("Unknown server handshake message received ({0})", type.ToString()));
}
}
/* Pad the key for inner and outer digest */
for (int i = 0; i < padLength; ++i)
{
- pad1[i] = 0x36;
- pad2[i] = 0x5C;
+ this.pad1[i] = 0x36;
+ this.pad2[i] = 0x5C;
}
}
char labelChar = 'A';
int count = 1;
+
while (tmp.Length < this.KeyBlockSize)
{
string label = String.Empty;
}
// Create keyblock
- TlsStream keyBlock = new TlsStream(tmp.ToArray());
-
+ TlsStream keyBlock = new TlsStream(tmp.ToArray());
+
this.Context.ClientWriteMAC = keyBlock.ReadBytes(this.HashSize);
this.Context.ServerWriteMAC = keyBlock.ReadBytes(this.HashSize);
this.Context.ClientWriteKey = keyBlock.ReadBytes(this.KeyMaterialSize);
// Clear Key Info
this.context.ClearKeyInfo();
}
- catch
+ catch (TlsException ex)
{
+ this.protocol.SendAlert(ex.Alert);
+ this.Close();
+
+ throw new IOException("The authentication or decryption has failed.");
+ }
+ catch (Exception)
+ {
+ this.protocol.SendAlert(AlertDescription.InternalError);
+ this.Close();
+
throw new IOException("The authentication or decryption has failed.");
}
}
public override void Initialize()
{
- md5.Initialize();
- sha.Initialize();
- initializePad();
- hashing = false;
+ this.md5.Initialize();
+ this.sha.Initialize();
+ this.initializePad();
+ this.hashing = false;
}
protected override byte[] HashFinal()
{
- if (!hashing)
+ if (!this.hashing)
{
- hashing = true;
+ this.hashing = true;
}
// Finalize the md5 hash
- md5.TransformBlock(this.secret, 0, this.secret.Length, this.secret, 0);
- md5.TransformFinalBlock(this.innerPadMD5, 0, this.innerPadMD5.Length);
+ this.md5.TransformBlock(this.secret, 0, this.secret.Length, this.secret, 0);
+ this.md5.TransformFinalBlock(this.innerPadMD5, 0, this.innerPadMD5.Length);
- byte[] firstResultMD5 = md5.Hash;
+ byte[] firstResultMD5 = this.md5.Hash;
- md5.Initialize();
- md5.TransformBlock(this.secret, 0, this.secret.Length, this.secret, 0);
- md5.TransformBlock(this.outerPadMD5, 0, this.outerPadMD5.Length, this.outerPadMD5, 0);
- md5.TransformFinalBlock(firstResultMD5, 0, firstResultMD5.Length);
+ this.md5.Initialize();
+ this.md5.TransformBlock(this.secret, 0, this.secret.Length, this.secret, 0);
+ this.md5.TransformBlock(this.outerPadMD5, 0, this.outerPadMD5.Length, this.outerPadMD5, 0);
+ this.md5.TransformFinalBlock(firstResultMD5, 0, firstResultMD5.Length);
// Finalize the sha1 hash
- sha.TransformBlock(this.secret, 0, this.secret.Length, this.secret, 0);
- sha.TransformFinalBlock(this.innerPadSHA, 0, this.innerPadSHA.Length);
+ this.sha.TransformBlock(this.secret, 0, this.secret.Length, this.secret, 0);
+ this.sha.TransformFinalBlock(this.innerPadSHA, 0, this.innerPadSHA.Length);
- byte[] firstResultSHA = sha.Hash;
+ byte[] firstResultSHA = this.sha.Hash;
- sha.Initialize();
- sha.TransformBlock(this.secret, 0, this.secret.Length, this.secret, 0);
- sha.TransformBlock(this.outerPadSHA, 0, this.outerPadSHA.Length, this.outerPadSHA, 0);
- sha.TransformFinalBlock(firstResultSHA, 0, firstResultSHA.Length);
+ this.sha.Initialize();
+ this.sha.TransformBlock(this.secret, 0, this.secret.Length, this.secret, 0);
+ this.sha.TransformBlock(this.outerPadSHA, 0, this.outerPadSHA.Length, this.outerPadSHA, 0);
+ this.sha.TransformFinalBlock(firstResultSHA, 0, firstResultSHA.Length);
this.Initialize();
byte[] result = new byte[36];
- Buffer.BlockCopy(md5.Hash, 0, result, 0, 16);
- Buffer.BlockCopy(sha.Hash, 0, result, 16, 20);
+ Buffer.BlockCopy(this.md5.Hash, 0, result, 0, 16);
+ Buffer.BlockCopy(this.sha.Hash, 0, result, 16, 20);
return result;
}
- protected override void HashCore(
- byte[] array,
- int ibStart,
- int cbSize)
+ protected override void HashCore(byte[] array, int ibStart, int cbSize)
{
- if (!hashing)
+ if (!this.hashing)
{
- hashing = true;
+ this.hashing = true;
}
- md5.TransformBlock(array, ibStart, cbSize, array, ibStart);
- sha.TransformBlock(array, ibStart, cbSize, array, ibStart);
+
+ this.md5.TransformBlock(array, ibStart, cbSize, array, ibStart);
+ this.sha.TransformBlock(array, ibStart, cbSize, array, ibStart);
+ }
+
+ public byte[] CreateSignature(RSA rsa)
+ {
+ if (rsa == null)
+ {
+ throw new CryptographicUnexpectedOperationException ("missing key");
+ }
+
+ RSASslSignatureFormatter f = new RSASslSignatureFormatter(rsa);
+ f.SetHashAlgorithm("SslHash");
+
+ return f.CreateSignature(this.Hash);
+ }
+
+ public bool VerifySignature(RSA rsa, byte[] rgbSignature)
+ {
+ if (rsa == null)
+ {
+ throw new CryptographicUnexpectedOperationException ("missing key");
+ }
+ if (rgbSignature == null)
+ {
+ throw new ArgumentNullException ("rgbSignature");
+ }
+
+ RSASslSignatureDeformatter d = new RSASslSignatureDeformatter(rsa);
+ d.SetHashAlgorithm("SslHash");
+
+ return d.VerifySignature(this.Hash, rgbSignature);
}
#endregion
asyncResult = this.inputBuffer.BeginRead(
buffer, offset, count, callback, state);
}
- catch (TlsException)
+ catch (TlsException ex)
{
+ this.protocol.SendAlert(ex.Alert);
+ this.Close();
+
throw new IOException("The authentication or decryption has failed.");
}
catch (Exception)
{
try
{
- // Send the buffer as a TLS record
-
+ // Send the buffer as a TLS record
byte[] record = this.protocol.EncodeRecord(
ContentType.ApplicationData, buffer, offset, count);
asyncResult = this.innerStream.BeginWrite(
record, 0, record.Length, callback, state);
}
- catch (TlsException)
+ catch (TlsException ex)
{
+ this.protocol.SendAlert(ex.Alert);
+ this.Close();
+
throw new IOException("The authentication or decryption has failed.");
}
catch (Exception)
// Clear Key Info
this.context.ClearKeyInfo();
}
- catch
+ catch (TlsException ex)
+ {
+ this.protocol.SendAlert(ex.Alert);
+ this.Close();
+
+ throw new IOException("The authentication or decryption has failed.");
+ }
+ catch (Exception)
{
+ this.protocol.SendAlert(AlertDescription.InternalError);
+ this.Close();
+
throw new IOException("The authentication or decryption has failed.");
}
}
using System;
using System.Text;
using System.Security.Cryptography.X509Certificates;
+using Mono.Security.Cryptography;
+using X509 = Mono.Security.X509;
namespace Mono.Security.Protocol.Tls
{
private X509CertificateCollection certificates;
private SecurityCompressionType compressionMethod;
private X509Certificate clientCertificate;
+ private RSAManaged certificateRSA;
#endregion
public X509Certificate ClientCertificate
{
get { return this.clientCertificate; }
- set { this.clientCertificate = value; }
+ set
+ {
+ this.clientCertificate = value;
+ this.UpdateCertificateRSA();
+ }
}
+ public RSAManaged CertificateRSA
+ {
+ get { return this.certificateRSA; }
+ }
#endregion
}
#endregion
+
+ #region Methods
+
+ public void UpdateCertificateRSA()
+ {
+ if (this.clientCertificate == null)
+ {
+ this.certificateRSA = null;
+ }
+ else
+ {
+ X509.X509Certificate cert = new X509.X509Certificate(this.clientCertificate.GetRawCertData());
+
+ this.certificateRSA = new RSAManaged(
+ cert.RSA.KeySize);
+
+ this.certificateRSA.ImportParameters(
+ cert.RSA.ExportParameters(false));
+ }
+ }
+
+ #endregion
}
}
namespace Mono.Security.Protocol.Tls
{
[Serializable]
- public sealed class TlsException : Exception
+ internal sealed class TlsException : Exception
{
+ #region Fields
+
+ private Alert alert;
+
+ #endregion
+
+ #region Properties
+
+ public Alert Alert
+ {
+ get { return this.alert; }
+ }
+
+ #endregion
+
#region Constructors
internal TlsException(string message) : base(message)
{
}
+ internal TlsException(
+ AlertLevel level,
+ AlertDescription description)
+ : this (level, description, Alert.GetAlertMessage(description))
+ {
+ }
+
+ internal TlsException(
+ AlertLevel level,
+ AlertDescription description,
+ string message) : base (message)
+ {
+ this.alert = new Alert(level, description);
+ }
+
+ internal TlsException(
+ AlertDescription description)
+ : this (description, Alert.GetAlertMessage(description))
+ {
+ }
+
+ internal TlsException(
+ AlertDescription description,
+ string message) : base (message)
+ {
+ this.alert = new Alert(description);
+ }
+
#endregion
}
}
public override bool CanWrite
{
- get { return canWrite; }
+ get { return this.canWrite; }
}
public override bool CanRead
{
- get { return canRead; }
+ get { return this.canRead; }
}
public override bool CanSeek
{
- get { return buffer.CanSeek; }
+ get { return this.buffer.CanSeek; }
}
public override long Position
{
- get { return buffer.Position; }
- set { buffer.Position = value; }
+ get { return this.buffer.Position; }
+ set { this.buffer.Position = value; }
}
public override long Length
{
- get { return buffer.Length; }
+ get { return this.buffer.Length; }
}
#endregion
public void Write(byte value)
{
- WriteByte(value);
+ this.WriteByte(value);
}
public void Write(short value)
{
byte[] bytes = BitConverter.GetBytes((short)IPAddress.HostToNetworkOrder(value));
- Write(bytes);
+ this.Write(bytes);
}
public void WriteInt24(int value)
Buffer.BlockCopy(BitConverter.GetBytes(int24), 1, content, 0, 3);
- Write(content);
+ this.Write(content);
}
public void Write(int value)
{
byte[] bytes = BitConverter.GetBytes((int)IPAddress.HostToNetworkOrder(value));
- Write(bytes);
+ this.Write(bytes);
}
public void Write(long value)
{
byte[] bytes = BitConverter.GetBytes((long)IPAddress.HostToNetworkOrder(value));
- Write(bytes);
+ this.Write(bytes);
}
public void Write(byte[] buffer)
{
- Write(buffer, 0, buffer.Length);
+ this.Write(buffer, 0, buffer.Length);
}
#endregion
public void Reset()
{
- buffer.SetLength(0);
- buffer.Position = 0;
+ this.buffer.SetLength(0);
+ this.buffer.Position = 0;
}
public byte[] ToArray()
{
- return buffer.ToArray();
+ return this.buffer.ToArray();
}
#endregion
public override void Flush()
{
- buffer.Flush();
+ this.buffer.Flush();
}
public override void SetLength(long length)
{
- buffer.SetLength(length);
+ this.buffer.SetLength(length);
}
public override long Seek(long offset, System.IO.SeekOrigin loc)
{
- return buffer.Seek(offset, loc);
+ return this.buffer.Seek(offset, loc);
}
public override int Read(byte[] buffer, int offset, int count)
{
- if (canRead)
+ if (this.canRead)
{
return this.buffer.Read(buffer, offset, count);
}
public override void Write(byte[] buffer, int offset, int count)
{
- if (canWrite)
+ if (this.canWrite)
{
this.buffer.Write(buffer, offset, count);
}