本文整理汇总了C#中Stream.ReadNextByte方法的典型用法代码示例。如果您正苦于以下问题:C# Stream.ReadNextByte方法的具体用法?C# Stream.ReadNextByte怎么用?C# Stream.ReadNextByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stream
的用法示例。
在下文中一共展示了Stream.ReadNextByte方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EnumMatchingFlags
public EnumMatchingFlags(Stream stream)
{
switch (stream.ReadNextByte())
{
case 1:
m_matchMode = (EnumMatchingFlagsMode)stream.ReadNextByte();
m_value = stream.ReadInt32();
m_description = stream.ReadString();
break;
default:
throw new VersionNotFoundException();
}
}
示例2: TimestampMatching
public TimestampMatching(Stream stream)
{
byte version = stream.ReadNextByte();
switch (version)
{
case 1:
m_mode = (TimestampMatchingMode)stream.ReadNextByte();
m_first = stream.ReadDateTime();
m_second = stream.ReadDateTime();
break;
default:
throw new VersionNotFoundException();
}
}
示例3: StringMatching
public StringMatching(Stream stream)
{
switch (stream.ReadNextByte())
{
case 1:
MatchMode = (StringMatchingMode)stream.ReadNextByte();
MatchText = stream.ReadString();
if (MatchMode == StringMatchingMode.Regex)
m_matchRegex = new Regex(MatchText);
break;
default:
throw new VersionNotFoundException();
}
}
示例4: TryAuthenticate
/// <summary>
/// Attempts to authenticate the provided stream.
/// </summary>
/// <param name="stream">the stream to authenticate</param>
/// <returns>True if successful, false otherwise</returns>
public bool TryAuthenticate(Stream stream, byte[] additionalChallenge)
{
// Header
// C => S
// byte Mode = (1: New, 2: Resume)
byte mode = stream.ReadNextByte();
Sha512Digest hash = new Sha512Digest();
switch (mode)
{
case 1:
return StandardAuthentication(hash, stream, additionalChallenge);
case 2: //resume ticket
return ResumeTicket(hash, stream, additionalChallenge);
default:
return false;
}
}
示例5: ReadUInt64
/// <summary>
/// Reads a 7-bit encoded ulong.
/// </summary>
/// <param name="stream">A stream to read from.</param>
/// <returns>the value</returns>
/// <remarks>
/// This method will check for the end of the stream
/// </remarks>
/// <exception cref="EndOfStreamException">Occurs if the end of the stream was reached.</exception>
public static ulong ReadUInt64(Stream stream)
{
ulong value11;
value11 = stream.ReadNextByte();
if (value11 < 128)
{
return value11;
}
value11 ^= ((ulong)stream.ReadNextByte() << (7));
if (value11 < 128 * 128)
{
return value11 ^ 0x80;
}
value11 ^= ((ulong)stream.ReadNextByte() << (7 + 7));
if (value11 < 128 * 128 * 128)
{
return value11 ^ 0x4080;
}
value11 ^= ((ulong)stream.ReadNextByte() << (7 + 7 + 7));
if (value11 < 128 * 128 * 128 * 128)
{
return value11 ^ 0x204080;
}
value11 ^= ((ulong)stream.ReadNextByte() << (7 + 7 + 7 + 7));
if (value11 < 128L * 128 * 128 * 128 * 128)
{
return value11 ^ 0x10204080L;
}
value11 ^= ((ulong)stream.ReadNextByte() << (7 + 7 + 7 + 7 + 7));
if (value11 < 128L * 128 * 128 * 128 * 128 * 128)
{
return value11 ^ 0x810204080L;
}
value11 ^= ((ulong)stream.ReadNextByte() << (7 + 7 + 7 + 7 + 7 + 7));
if (value11 < 128L * 128 * 128 * 128 * 128 * 128 * 128)
{
return value11 ^ 0x40810204080L;
}
value11 ^= ((ulong)stream.ReadNextByte() << (7 + 7 + 7 + 7 + 7 + 7 + 7));
if (value11 < 128L * 128 * 128 * 128 * 128 * 128 * 128 * 128)
{
return value11 ^ 0x2040810204080L;
}
value11 ^= ((ulong)stream.ReadNextByte() << (7 + 7 + 7 + 7 + 7 + 7 + 7 + 7));
return value11 ^ 0x102040810204080L;
}
示例6: ResumeTicket
private bool ResumeTicket(IDigest hash, Stream stream, byte[] additionalChallenge)
{
// Successful Resume Session (If mode = 1)
// C => S
// byte ChallengeLength
// byte[] A = Challenge
// int16 TicketLength
// byte[] Ticket
// C <= S
// bool IsSuccess = true
// byte HashMethod
// byte ChallengeLength
// byte[] B = Challenge
// C => S
// byte[] M1 = H(A | B | SessionKey)
// Bool Success (if false, done)
// C <= S
// byte[] M2 = H(B | A | SessionKey)
// Failed Resume Session
// C => S
// byte ChallengeLength
// byte[] A = Challenge
// int16 TicketLength
// byte[] Ticket
// C <= S
// bool IsSuccess = false
// Goto Authenticate Code
byte[] a = stream.ReadBytes(stream.ReadNextByte());
int ticketLength = stream.ReadInt16();
if (ticketLength < 0 || ticketLength > 10000)
return false;
byte[] ticket = stream.ReadBytes(ticketLength);
if (TryLoadTicket(ticket, m_user, out SessionSecret))
{
stream.Write(true);
stream.WriteByte((byte)SrpHashMethod);
byte[] b = SaltGenerator.Create(16);
stream.WriteByte(16);
stream.Write(b);
stream.Flush();
byte[] clientProofCheck = hash.ComputeHash(a, b, SessionSecret, additionalChallenge);
byte[] serverProof = hash.ComputeHash(b, a, SessionSecret, additionalChallenge);
byte[] clientProof = stream.ReadBytes(hash.GetDigestSize());
if (clientProof.SecureEquals(clientProofCheck))
{
stream.Write(true);
stream.Write(serverProof);
stream.Flush();
return true;
}
stream.Write(false);
return false;
}
stream.Write(false);
return StandardAuthentication(hash, stream, additionalChallenge);
}
示例7: LogMessage
/// <summary>
/// Loads a log messages from the supplied stream
/// </summary>
/// <param name="stream">the stream to load the log message from.</param>
/// <param name="saveHelper">A save helper that will condense objects</param>
internal LogMessage(Stream stream, LogMessageSaveHelper saveHelper = null)
{
if (saveHelper == null)
saveHelper = LogMessageSaveHelper.Create(true);
byte version = stream.ReadNextByte();
switch (version)
{
case 1:
EventPublisherDetails = saveHelper.LoadEventPublisherDetails(stream);
InitialStackMessages = saveHelper.LoadStackMessages(stream);
InitialStackTrace = saveHelper.LoadStackTrace(stream);
CurrentStackMessages = saveHelper.LoadStackMessages(stream);
CurrentStackTrace = saveHelper.LoadStackTrace(stream);
UtcTime = stream.ReadDateTime();
LogMessageAttributes = new LogMessageAttributes(stream);
Message = stream.ReadString();
Details = stream.ReadString();
Exception = null;
ExceptionString = stream.ReadString();
ManagedThreadID = -1;
PreviousFirstChanceExceptionSequenceNumber = -1;
break;
case 2:
EventPublisherDetails = saveHelper.LoadEventPublisherDetails(stream);
InitialStackMessages = saveHelper.LoadStackMessages(stream);
InitialStackTrace = saveHelper.LoadStackTrace(stream);
CurrentStackMessages = saveHelper.LoadStackMessages(stream);
CurrentStackTrace = saveHelper.LoadStackTrace(stream);
UtcTime = stream.ReadDateTime();
LogMessageAttributes = new LogMessageAttributes(stream);
Message = stream.ReadString();
Details = stream.ReadString();
Exception = null;
ExceptionString = stream.ReadString();
ManagedThreadID = stream.ReadInt32();
PreviousFirstChanceExceptionSequenceNumber = -1;
break;
case 3:
EventPublisherDetails = saveHelper.LoadEventPublisherDetails(stream);
InitialStackMessages = saveHelper.LoadStackMessages(stream);
InitialStackTrace = saveHelper.LoadStackTrace(stream);
CurrentStackMessages = saveHelper.LoadStackMessages(stream);
CurrentStackTrace = saveHelper.LoadStackTrace(stream);
UtcTime = stream.ReadDateTime();
LogMessageAttributes = new LogMessageAttributes(stream);
Message = saveHelper.LoadString(stream);
Details = saveHelper.LoadString(stream);
Exception = null;
ExceptionString = saveHelper.LoadString(stream);
ManagedThreadID = stream.ReadInt32();
PreviousFirstChanceExceptionSequenceNumber = -1;
break;
case 4:
EventPublisherDetails = saveHelper.LoadEventPublisherDetails(stream);
InitialStackMessages = saveHelper.LoadStackMessages(stream);
InitialStackTrace = saveHelper.LoadStackTrace(stream);
CurrentStackMessages = saveHelper.LoadStackMessages(stream);
CurrentStackTrace = saveHelper.LoadStackTrace(stream);
UtcTime = stream.ReadDateTime();
LogMessageAttributes = new LogMessageAttributes(stream);
Message = saveHelper.LoadString(stream);
Details = saveHelper.LoadString(stream);
Exception = null;
ExceptionString = saveHelper.LoadString(stream);
ManagedThreadID = stream.ReadInt32();
PreviousFirstChanceExceptionSequenceNumber = stream.ReadInt32();
break;
default:
throw new VersionNotFoundException();
}
}
示例8: Load
/// <summary>
/// Loads from the supplied stream.
/// </summary>
/// <param name="stream"></param>
public void Load(Stream stream)
{
byte version = stream.ReadNextByte();
switch (version)
{
case 1:
Users.Load(stream);
return;
default:
throw new VersionNotFoundException("Unknown encoding method");
}
}
示例9: ResumeSession
private bool ResumeSession(Stream stream, byte[] additionalChallenge)
{
stream.Write((byte)16);
byte[] aChallenge = SaltGenerator.Create(16);
stream.Write(aChallenge);
stream.Write((short)m_resumeTicket.Length);
stream.Write(m_resumeTicket);
stream.Flush();
if (stream.ReadBoolean())
{
SetHashMethod((HashMethod)stream.ReadNextByte());
byte[] bChallenge = stream.ReadBytes(stream.ReadNextByte());
byte[] clientProof = m_hash.ComputeHash(aChallenge, bChallenge, m_sessionSecret, additionalChallenge);
stream.Write(clientProof);
stream.Flush();
if (stream.ReadBoolean())
{
byte[] serverProof = m_hash.ComputeHash(bChallenge, aChallenge, m_sessionSecret, additionalChallenge);
byte[] serverProofCheck = stream.ReadBytes(m_hash.GetDigestSize());
return serverProof.SecureEquals(serverProofCheck);
}
}
m_sessionSecret = null;
m_resumeTicket = null;
return Authenticate(stream, additionalChallenge);
}
示例10: Load
/// <summary>
/// Loads from the supplied stream.
/// </summary>
/// <param name="stream"></param>
public void Load(Stream stream)
{
byte version = stream.ReadNextByte();
switch (version)
{
case 1:
Username = stream.ReadString();
UserID = stream.ReadString();
UserToken = stream.ReadGuid();
return;
default:
throw new VersionNotFoundException("Unknown encoding method");
}
}
示例11: TryResumeSession
private bool TryResumeSession(ref Stream secureStream, Stream stream2, byte[] certSignatures)
{
#if SQLCLR
return false;
#else
if (m_resumeTicket != null && m_sessionSecret != null)
{
//Resume Session:
// C => S
// byte ResumeSession
// byte TicketLength
// byte[] Ticket
// byte ClientChallengeLength
// byte[] ClientChallenge
byte[] clientChallenge = SaltGenerator.Create(16);
stream2.WriteByte((byte)AuthenticationMode.ResumeSession);
stream2.WriteByte((byte)m_resumeTicket.Length);
stream2.Write(m_resumeTicket);
stream2.WriteByte((byte)clientChallenge.Length);
stream2.Write(clientChallenge);
stream2.Flush();
// S <= C
// byte HashMethod
// byte ServerChallengeLength
// byte[] ServerChallenge
HashMethod hashMethod = (HashMethod)stream2.ReadNextByte();
IDigest hash = Scram.CreateDigest(hashMethod);
byte[] serverChallenge = stream2.ReadBytes(stream2.ReadNextByte());
// C => S
// byte ClientResponseLength
// byte[] ClientChallenge
byte[] clientResponse = hash.ComputeHash(serverChallenge, clientChallenge, m_sessionSecret, certSignatures);
byte[] serverResponse = hash.ComputeHash(clientChallenge, serverChallenge, m_sessionSecret, certSignatures);
stream2.WriteByte((byte)clientResponse.Length);
stream2.Write(clientResponse);
stream2.Flush();
// S => C
// bool IsSuccessful
// byte ServerResponseLength
// byte[] ServerResponse
if (stream2.ReadBoolean())
{
byte[] serverResponseCheck = stream2.ReadBytes(stream2.ReadNextByte());
// C => S
// bool IsSuccessful
if (serverResponse.SecureEquals(serverResponseCheck))
{
stream2.Write(true);
stream2.Flush();
secureStream = stream2;
return true;
}
stream2.Write(false);
stream2.Flush();
}
m_resumeTicket = null;
m_sessionSecret = null;
}
return false;
#endif
}
示例12: LoadString
public string LoadString(Stream stream)
{
byte version = stream.ReadNextByte();
switch (version)
{
case 0:
return stream.ReadString();
case 1:
{
if (m_isSimple)
throw new Exception("Cannot load without a LogMessageSaveHelper");
int id = stream.ReadInt32();
return m_stringLoadLookup[id];
}
case 2:
{
if (m_isSimple)
throw new Exception("Cannot load without a LogMessageSaveHelper");
int id = stream.ReadInt32();
var value = stream.ReadString();
m_stringLoadLookup.Add(value);
return value;
}
case 3:
{
return string.Empty;
}
case 4:
{
if (m_isSimple)
throw new Exception("Cannot load without a LogMessageSaveHelper");
var value = stream.ReadString();
m_stringLoadLookup.Add(value);
return value;
}
default:
throw new VersionNotFoundException();
}
}
示例13: LoadStackTrace
public LogStackTrace LoadStackTrace(Stream stream)
{
byte version = stream.ReadNextByte();
switch (version)
{
case 0:
return LogStackTrace.Empty;
case 1:
return new LogStackTrace(stream);
case 2:
{
if (m_isSimple)
throw new Exception("Cannot load without a LogMessageSaveHelper");
int id = stream.ReadInt32();
return m_stackTraceLoadLookup[id];
}
case 3:
{
if (m_isSimple)
throw new Exception("Cannot load without a LogMessageSaveHelper");
int id = stream.ReadInt32();
var trace = new LogStackTrace(stream);
m_stackTraceLoadLookup.Add(trace);
return trace;
}
case 4:
{
if (m_isSimple)
throw new Exception("Cannot load without a LogMessageSaveHelper");
var trace = new LogStackTrace(stream);
m_stackTraceLoadLookup.Add(trace);
return trace;
}
default:
throw new VersionNotFoundException();
}
}
示例14: LoadPublisherTypeDefinition
public PublisherTypeDefinition LoadPublisherTypeDefinition(Stream stream)
{
byte version = stream.ReadNextByte();
switch (version)
{
case 0:
return new PublisherTypeDefinition(stream);
case 1:
{
if (m_isSimple)
throw new Exception("Cannot load without a LogMessageSaveHelper");
int id = stream.ReadInt32();
return m_publisherTypeDefinitionLoadLookup[id];
}
case 2:
{
if (m_isSimple)
throw new Exception("Cannot load without a LogMessageSaveHelper");
int id = stream.ReadInt32();
var details = new PublisherTypeDefinition(stream);
m_publisherTypeDefinitionLoadLookup.Add(details);
return details;
}
case 3:
{
if (m_isSimple)
throw new Exception("Cannot load without a LogMessageSaveHelper");
var details = new PublisherTypeDefinition(stream);
m_publisherTypeDefinitionLoadLookup.Add(details);
return details;
}
default:
throw new VersionNotFoundException();
}
}
示例15: Authenticate
private bool Authenticate(Stream stream, byte[] additionalChallenge)
{
HashMethod passwordHashMethod = (HashMethod)stream.ReadNextByte();
byte[] salt = stream.ReadBytes(stream.ReadNextByte());
int iterations = stream.ReadInt32();
SetHashMethod((HashMethod)stream.ReadNextByte());
SetSrpStrength((SrpStrength)stream.ReadInt32());
m_credentials.TryUpdate(passwordHashMethod, salt, iterations);
BigInteger pubA = m_client.GenerateClientCredentials(m_hash, salt, m_credentials.UsernameBytes, m_credentials.SaltedPassword);
byte[] pubABytes = pubA.ToPaddedArray(m_srpByteLength);
stream.Write(pubABytes);
stream.Flush();
//Read from Server: B
byte[] pubBBytes = stream.ReadBytes(m_srpByteLength);
BigInteger pubB = new BigInteger(1, pubBBytes);
//Calculate Session Key
BigInteger S = m_client.CalculateSecret(m_hash, pubB);
byte[] SBytes = S.ToPaddedArray(m_srpByteLength);
byte[] clientProof = m_hash.ComputeHash(pubABytes, pubBBytes, SBytes, additionalChallenge);
stream.Write(clientProof);
stream.Flush();
byte[] serverProof = m_hash.ComputeHash(pubBBytes, pubABytes, SBytes, additionalChallenge);
if (stream.ReadBoolean())
{
byte[] serverProofCheck = stream.ReadBytes(m_hash.GetDigestSize());
int ticketLength = stream.ReadInt16();
if (ticketLength < 0 || ticketLength > 10000)
return false;
if (serverProofCheck.SecureEquals(serverProof))
{
m_resumeTicket = stream.ReadBytes(ticketLength);
m_sessionSecret = m_hash.ComputeHash(pubABytes, SBytes, pubBBytes).Combine(m_hash.ComputeHash(pubBBytes, SBytes, pubABytes));
return true;
}
return false;
}
return false;
}