protected virtual int VerifyCash(string signature) { var tempCertificate = this.Certificate; this.Certificate = null; var tempCash = this.Cash; this.Cash = null; try { using (var stream = this.Export(BufferManager.Instance)) { stream.Seek(0, SeekOrigin.End); ItemUtilities.Write(stream, byte.MaxValue, signature); stream.Seek(0, SeekOrigin.Begin); return(Miner.Verify(tempCash, stream)); } } finally { this.Certificate = tempCertificate; this.Cash = tempCash; } }
protected override Stream Export(BufferManager bufferManager, int count) { BufferStream bufferStream = new BufferStream(bufferManager); // CreationTime if (this.CreationTime != DateTime.MinValue) { ItemUtilities.Write(bufferStream, (byte)SerializeId.CreationTime, this.CreationTime.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ", System.Globalization.DateTimeFormatInfo.InvariantInfo)); } // Key if (this.Key != null) { using (var stream = this.Key.Export(bufferManager)) { ItemUtilities.Write(bufferStream, (byte)SerializeId.Key, stream); } } // Certificate if (this.Certificate != null) { using (var stream = this.Certificate.Export(bufferManager)) { ItemUtilities.Write(bufferStream, (byte)SerializeId.Certificate, stream); } } bufferStream.Seek(0, SeekOrigin.Begin); return(bufferStream); }
protected override Stream Export(BufferManager bufferManager, int count) { BufferStream bufferStream = new BufferStream(bufferManager); // Path if (this.Path != null) { ItemUtilities.Write(bufferStream, (byte)SerializeId.Path, this.Path); } // CreationTime if (this.CreationTime != DateTime.MinValue) { ItemUtilities.Write(bufferStream, (byte)SerializeId.CreationTime, this.CreationTime.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ", System.Globalization.DateTimeFormatInfo.InvariantInfo)); } // FormatType if (this.FormatType != 0) { ItemUtilities.Write(bufferStream, (byte)SerializeId.FormatType, this.FormatType.ToString()); } // Hypertext if (this.Hypertext != null) { ItemUtilities.Write(bufferStream, (byte)SerializeId.Hypertext, this.Hypertext); } bufferStream.Seek(0, SeekOrigin.Begin); return(bufferStream); }
protected override void ProtectedImport(Stream stream, BufferManager bufferManager, int count) { for (; ;) { byte id; { byte[] idBuffer = new byte[1]; if (stream.Read(idBuffer, 0, idBuffer.Length) != idBuffer.Length) { return; } id = idBuffer[0]; } int length; { byte[] lengthBuffer = new byte[4]; if (stream.Read(lengthBuffer, 0, lengthBuffer.Length) != lengthBuffer.Length) { return; } length = NetworkConverter.ToInt32(lengthBuffer); } using (RangeStream rangeStream = new RangeStream(stream, stream.Position, length, true)) { if (id == (byte)SerializeId.Tag) { this.Tag = Chat.Import(rangeStream, bufferManager); } else if (id == (byte)SerializeId.CreationTime) { this.CreationTime = DateTime.ParseExact(ItemUtilities.GetString(rangeStream), "yyyy-MM-ddTHH:mm:ssZ", System.Globalization.DateTimeFormatInfo.InvariantInfo).ToUniversalTime(); } else if (id == (byte)SerializeId.FormatType) { this.FormatType = (HypertextFormatType)Enum.Parse(typeof(HypertextFormatType), ItemUtilities.GetString(rangeStream)); } else if (id == (byte)SerializeId.Hypertext) { this.Hypertext = ItemUtilities.GetString(rangeStream); } else if (id == (byte)SerializeId.Certificate) { this.Certificate = Certificate.Import(rangeStream, bufferManager); } } } }
protected override Stream Export(BufferManager bufferManager, int count) { BufferStream bufferStream = new BufferStream(bufferManager); // Name if (this.Name != null) { ItemUtilities.Write(bufferStream, (byte)SerializeId.Name, this.Name); } // Id if (this.Id != null) { ItemUtilities.Write(bufferStream, (byte)SerializeId.Id, this.Id); } bufferStream.Seek(0, SeekOrigin.Begin); return(bufferStream); }
protected override Stream Export(BufferManager bufferManager, int count) { BufferStream bufferStream = new BufferStream(bufferManager); // Hash if (this.Hash != null) { ItemUtilities.Write(bufferStream, (byte)SerializeId.Hash, this.Hash); } // HashAlgorithm if (this.HashAlgorithm != 0) { ItemUtilities.Write(bufferStream, (byte)SerializeId.HashAlgorithm, this.HashAlgorithm.ToString()); } bufferStream.Seek(0, SeekOrigin.Begin); return(bufferStream); }
protected override Stream Export(BufferManager bufferManager, int count) { BufferStream bufferStream = new BufferStream(bufferManager); // Id if (this.Id != null) { ItemUtilities.Write(bufferStream, (byte)SerializeId.Id, this.Id); } // Uris foreach (var value in this.Uris) { ItemUtilities.Write(bufferStream, (byte)SerializeId.Uri, value); } bufferStream.Seek(0, SeekOrigin.Begin); return(bufferStream); }
protected override void ProtectedImport(Stream stream, BufferManager bufferManager, int count) { for (; ;) { byte id; { byte[] idBuffer = new byte[1]; if (stream.Read(idBuffer, 0, idBuffer.Length) != idBuffer.Length) { return; } id = idBuffer[0]; } int length; { byte[] lengthBuffer = new byte[4]; if (stream.Read(lengthBuffer, 0, lengthBuffer.Length) != lengthBuffer.Length) { return; } length = NetworkConverter.ToInt32(lengthBuffer); } using (RangeStream rangeStream = new RangeStream(stream, stream.Position, length, true)) { if (id == (byte)SerializeId.Hash) { this.Hash = ItemUtilities.GetByteArray(rangeStream); } else if (id == (byte)SerializeId.HashAlgorithm) { this.HashAlgorithm = (HashAlgorithm)Enum.Parse(typeof(HashAlgorithm), ItemUtilities.GetString(rangeStream)); } } } }
protected override void ProtectedImport(Stream stream, BufferManager bufferManager, int count) { for (; ;) { byte id; { byte[] idBuffer = new byte[1]; if (stream.Read(idBuffer, 0, idBuffer.Length) != idBuffer.Length) { return; } id = idBuffer[0]; } int length; { byte[] lengthBuffer = new byte[4]; if (stream.Read(lengthBuffer, 0, lengthBuffer.Length) != lengthBuffer.Length) { return; } length = NetworkConverter.ToInt32(lengthBuffer); } using (RangeStream rangeStream = new RangeStream(stream, stream.Position, length, true)) { if (id == (byte)SerializeId.CreationTime) { this.CreationTime = DateTime.ParseExact(ItemUtilities.GetString(rangeStream), "yyyy-MM-ddTHH:mm:ssZ", System.Globalization.DateTimeFormatInfo.InvariantInfo).ToUniversalTime(); } else if (id == (byte)SerializeId.Cost) { this.Cost = ItemUtilities.GetInt(rangeStream); } else if (id == (byte)SerializeId.ExchangePublicKey) { this.ExchangePublicKey = ExchangePublicKey.Import(rangeStream, bufferManager); } else if (id == (byte)SerializeId.TrustSignature) { this.ProtectedTrustSignatures.Add(ItemUtilities.GetString(rangeStream)); } else if (id == (byte)SerializeId.DeleteSignature) { this.ProtectedDeleteSignatures.Add(ItemUtilities.GetString(rangeStream)); } else if (id == (byte)SerializeId.Wiki) { this.ProtectedWikis.Add(Wiki.Import(rangeStream, bufferManager)); } else if (id == (byte)SerializeId.Chat) { this.ProtectedChats.Add(Chat.Import(rangeStream, bufferManager)); } else if (id == (byte)SerializeId.Certificate) { this.Certificate = Certificate.Import(rangeStream, bufferManager); } } } }
protected override Stream Export(BufferManager bufferManager, int count) { BufferStream bufferStream = new BufferStream(bufferManager); // CreationTime if (this.CreationTime != DateTime.MinValue) { ItemUtilities.Write(bufferStream, (byte)SerializeId.CreationTime, this.CreationTime.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ", System.Globalization.DateTimeFormatInfo.InvariantInfo)); } // Cost if (this.Cost != 0) { ItemUtilities.Write(bufferStream, (byte)SerializeId.Cost, this.Cost); } // ExchangePublicKey if (this.ExchangePublicKey != null) { using (var stream = this.ExchangePublicKey.Export(bufferManager)) { ItemUtilities.Write(bufferStream, (byte)SerializeId.ExchangePublicKey, stream); } } // TrustSignatures foreach (var value in this.TrustSignatures) { ItemUtilities.Write(bufferStream, (byte)SerializeId.TrustSignature, value); } // DeleteSignatures foreach (var value in this.DeleteSignatures) { ItemUtilities.Write(bufferStream, (byte)SerializeId.DeleteSignature, value); } // Wikis foreach (var value in this.Wikis) { using (var stream = value.Export(bufferManager)) { ItemUtilities.Write(bufferStream, (byte)SerializeId.Wiki, stream); } } // Chats foreach (var value in this.Chats) { using (var stream = value.Export(bufferManager)) { ItemUtilities.Write(bufferStream, (byte)SerializeId.Chat, stream); } } // Certificate if (this.Certificate != null) { using (var stream = this.Certificate.Export(bufferManager)) { ItemUtilities.Write(bufferStream, (byte)SerializeId.Certificate, stream); } } bufferStream.Seek(0, SeekOrigin.Begin); return(bufferStream); }
public int GetHashCode(byte[] value) { return(ItemUtilities.GetHashCode(value)); }